Skip to content

Commit

Permalink
ut
Browse files Browse the repository at this point in the history
  • Loading branch information
Artur Bać committed Jul 24, 2024
1 parent 0e81bf6 commit d125a13
Show file tree
Hide file tree
Showing 16 changed files with 450 additions and 478 deletions.
4 changes: 2 additions & 2 deletions unit_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,6 @@ add_fixedmath_ut( multiplication_ut )
add_fixedmath_ut( division_ut )
add_fixedmath_ut( misc_functions_ut )
add_fixedmath_ut( sin_cos_ut )
# add_compile_test( tan )
# add_compile_test( atan )
add_fixedmath_ut( tan_ut )
add_fixedmath_ut( atan_ut )

2 changes: 1 addition & 1 deletion unit_tests/addition_ut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int main()
expect( test_resulting_type<double>( 1_fix + 1. ) );
return {};
};
result |= run_constexpr_test(fn_tmpl);
result |= run_runtime_test(fn_tmpl);
result |= run_consteval_test(fn_tmpl);
};
}
Expand Down
390 changes: 390 additions & 0 deletions unit_tests/atan_ut.cc

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion unit_tests/division_ut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ int main()
expect(test_resulting_type<double>(1_fix / 1.));
return {};
};
result |= run_constexpr_test(fn_tmpl);
result |= run_runtime_test(fn_tmpl);
result |= run_consteval_test(fn_tmpl);
};
}
2 changes: 1 addition & 1 deletion unit_tests/fixed_construction_ut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ int main()
expect_eq(fixed_t{4096llu}, 4096_fix);
return {};
};
result |= run_constexpr_test(fn_tmpl);
result |= run_runtime_test(fn_tmpl);
result |= run_consteval_test(fn_tmpl);
};
}
75 changes: 0 additions & 75 deletions unit_tests/include/addition.h

This file was deleted.

354 changes: 2 additions & 352 deletions unit_tests/include/atan.h

Large diffs are not rendered by default.

30 changes: 0 additions & 30 deletions unit_tests/include/tan.h

This file was deleted.

6 changes: 3 additions & 3 deletions unit_tests/include/unit_test_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ test_result require_throw(test_type const & test) noexcept
template<typename unit_test>
[[maybe_unused]]
constexpr test_result
run_constexpr_test(unit_test const & test, source_location const location = source_location::current())
run_runtime_test(unit_test const & test, source_location const location = source_location::current())
{
return expect(test(), location);
}
Expand Down Expand Up @@ -266,7 +266,7 @@ namespace detail
template<typename templ_list, typename unit_test>
[[maybe_unused]]
constexpr test_result
run_constexpr_test(unit_test const & test, source_location const location = source_location::current())
run_runtime_test(unit_test const & test, source_location const location = source_location::current())
{
return expect(detail::test_invoke<templ_list>::constexpr_run(test), location);
}
Expand Down Expand Up @@ -295,7 +295,7 @@ consteval test_result test()
return test_result{};
};

auto res = run_constexpr_test<traits_test_list>(test_fn);
auto res = run_runtime_test<traits_test_list>(test_fn);
return res | test_result{counter == 4};
}

Expand Down
6 changes: 3 additions & 3 deletions unit_tests/misc_functions_ut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ int main()
expect_eq(ceil(5.25_fix), 6_fix);
return {};
};
result |= run_constexpr_test(fn_tmpl);
result |= run_runtime_test(fn_tmpl);
result |= run_consteval_test(fn_tmpl);
};

Expand All @@ -43,7 +43,7 @@ int main()

return {};
};
result |= run_constexpr_test(fn_tmpl);
result |= run_runtime_test(fn_tmpl);
result |= run_consteval_test(fn_tmpl);
};

Expand All @@ -58,7 +58,7 @@ int main()
expect_eq(angle_to_radians(45), phi / 4);
return {};
};
result |= run_constexpr_test(fn_tmpl);
result |= run_runtime_test(fn_tmpl);
result |= run_consteval_test(fn_tmpl);
};
}
2 changes: 1 addition & 1 deletion unit_tests/multiplication_ut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int main()
expect(test_resulting_type<double>(1_fix * 1.));
return {};
};
result |= run_constexpr_test(fn_tmpl);
result |= run_runtime_test(fn_tmpl);
result |= run_consteval_test(fn_tmpl);
};
}
4 changes: 2 additions & 2 deletions unit_tests/sin_cos_ut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int main()
test_sin(-85 * phi / 180, -0.99610_fix, 0.0001_fix);
return {};
};
result |= run_constexpr_test(fn_tmpl);
result |= run_runtime_test(fn_tmpl);
result |= run_consteval_test(fn_tmpl);
};

Expand All @@ -96,7 +96,7 @@ int main()
test_cos(2 * -phi, 0.99984_fix, 0.0001_fix);
return {};
};
result |= run_constexpr_test(fn_tmpl);
result |= run_runtime_test(fn_tmpl);
result |= run_consteval_test(fn_tmpl);
};
}
Expand Down
4 changes: 2 additions & 2 deletions unit_tests/sqrt_ut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ int main()
expect_approx(sqrt(3333331.0215148925781250_fix), 1825.7412_fix, 0.001_fix);
return {};
};
result |= run_constexpr_test(fn_tmpl);
result |= run_runtime_test(fn_tmpl);
result |= run_consteval_test(fn_tmpl);
};

Expand Down Expand Up @@ -73,7 +73,7 @@ int main()
test_hypot(0.5_fix, 0.25_fix, 0.559005_fix, 0.0001_fix);
return {};
};
result |= run_constexpr_test(fn_tmpl);
result |= run_runtime_test(fn_tmpl);
result |= run_consteval_test(fn_tmpl);
};
}
2 changes: 1 addition & 1 deletion unit_tests/subtraction_ut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ int main()
expect(test_resulting_type<double>(1_fix - 1.));
return {};
};
result |= run_constexpr_test(fn_tmpl);
result |= run_runtime_test(fn_tmpl);
result |= run_consteval_test(fn_tmpl);
};
}
37 changes: 37 additions & 0 deletions unit_tests/tan_ut.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#include <unit_test_core.h>
#include <unit_test_common.h>

using boost::ut::operator""_test;
using namespace metatests;
using namespace fixedmath;
using namespace fixedmath::func;

constexpr void
test_tan(fixed_t x, fixed_t expected, fixed_t aprox, source_location const location = source_location::current())
{
expect_approx(tan(x), expected, aprox, location);
expect_approx(tan(-x), -expected, aprox, location);
}

int main()
{
test_result result;
"tan"_test = [&result]
{
auto fn_tmpl = [] -> metatests::test_result
{
test_tan(phi / 2 + phi / 32, -10.155854941143394_fix, 0.0001_fix);
test_tan(phi / 3, 1.73204_fix, 0.0001_fix);
test_tan(phi / 4, 0.99997_fix, 0.0001_fix);
test_tan(phi / 5, 0.72653_fix, 0.0001_fix);
test_tan(phi / 8, 0.41419_fix, 0.0001_fix);
test_tan(phi / 16, 0.19889_fix, 0.0001_fix);
test_tan(0_fix, 0_fix, 0.0001_fix);
return {};
};
result |= run_runtime_test(fn_tmpl);
result |= run_consteval_test(fn_tmpl);
};
}

// 0.0001
8 changes: 4 additions & 4 deletions unit_tests/type_convertions_ut.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ int main()
//
return {};
};
result |= run_constexpr_test(fn_tmpl);
result |= run_runtime_test(fn_tmpl);
result |= run_consteval_test(fn_tmpl);
};

Expand Down Expand Up @@ -73,7 +73,7 @@ int main()
expect_neq(arithmetic_to_fixed(dlimits_::min()), limits_::quiet_NaN());
return {};
};
result |= run_constexpr_test(fn_tmpl);
result |= run_runtime_test(fn_tmpl);
result |= run_consteval_test(fn_tmpl);
};

Expand All @@ -88,7 +88,7 @@ int main()
expect_eq(fixed_to_arithmetic<unsigned>(100.55_fix), 100u);
return {};
};
result |= run_constexpr_test(fn_tmpl);
result |= run_runtime_test(fn_tmpl);
result |= run_consteval_test(fn_tmpl);
};
"fixed_to_arithmetic floating point"_test = [&result]
Expand Down Expand Up @@ -122,7 +122,7 @@ int main()
}
return {};
};
result |= run_constexpr_test(fn_tmpl);
result |= run_runtime_test(fn_tmpl);
result |= run_consteval_test(fn_tmpl);
};
}

0 comments on commit d125a13

Please sign in to comment.