-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Artur Bać
committed
Jul 22, 2024
1 parent
3c29a8f
commit 80440ce
Showing
10 changed files
with
169 additions
and
142 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#include <unit_test_core.h> | ||
#include <unit_test_common.h> | ||
|
||
using boost::ut::operator""_test; | ||
using namespace metatests; | ||
using namespace fixedmath; | ||
|
||
int main() | ||
{ | ||
test_result result; | ||
using F = fixedmath::fixed_internal; | ||
"addition"_test = [&result] | ||
{ | ||
auto fn_tmpl = [] -> metatests::test_result | ||
{ | ||
expect_eq(add(0_fix, 1_fix), 1_fix); | ||
expect_eq(add(1_fix, 1_fix), 2_fix); | ||
expect_eq(add(10_fix, 1_fix), 11_fix); | ||
expect_eq(add(-10_fix, 1_fix), -9_fix); | ||
|
||
expect_eq(0_fix + 1_fix, 1_fix); | ||
expect_eq(1_fix + 1_fix, 2_fix); | ||
expect_eq(10.4_fix + 1_fix, 11.4_fix); | ||
expect_eq(-10_fix + 1_fix, -9_fix); | ||
|
||
expect_eq(0_fix + 1, 1_fix); | ||
expect_eq(1 + 1_fix, 2_fix); | ||
expect_eq(10.4 + 1_fix, 11.4); | ||
expect_eq(10.5_fix + 10.2, 20.7); | ||
expect_eq(-10.5_fix + uint8_t(10), -0.5_fix); | ||
expect_eq(-10.5_fix + uint16_t(10), -0.5_fix); | ||
expect_eq(-10.5_fix + uint32_t(10), -0.5_fix); | ||
expect_eq(-10.5_fix + uint64_t(10), -0.5_fix); | ||
expect_eq(uint8_t(10) + -10.5_fix, -.5_fix); | ||
expect_eq(uint16_t(10) + -10.5_fix, -.5_fix); | ||
expect_eq(uint32_t(10) + -10.5_fix, -.5_fix); | ||
expect_eq(uint64_t(10) + -10.5_fix, -.5_fix); | ||
expect_eq(-10_fix + 1, -9_fix); | ||
expect_eq(10.5_fix + -10., .5); | ||
expect_eq(10.5_fix + -10.f, .5_fix); | ||
expect_lt(limits_::max(), limits_::quiet_NaN()); | ||
expect_neq(limits_::lowest() + 1, limits_::quiet_NaN()); | ||
|
||
expect_neq(as_fixed(limits_::max().v - 65536) + 1_fix, limits_::quiet_NaN()); | ||
return {}; | ||
}; | ||
result |= run_constexpr_test(fn_tmpl); | ||
result |= run_consteval_test(fn_tmpl); | ||
}; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <unit_test_core.h> | ||
#include <unit_test_common.h> | ||
|
||
using boost::ut::operator""_test; | ||
using namespace metatests; | ||
using F = fixedmath::fixed_internal; | ||
using namespace fixedmath; | ||
|
||
int main() | ||
{ | ||
test_result result; | ||
"fixed construction"_test = [&result] | ||
{ | ||
auto fn_tmpl = [] -> metatests::test_result | ||
{ | ||
expect_eq(fixed_t{1}, 1_fix); | ||
expect_eq(fixed_t{1u}, 1_fix); | ||
expect_eq(fixed_t{1lu}, 1_fix); | ||
expect_eq(fixed_t{1llu}, 1_fix); | ||
expect_eq(fixed_t{-1}, -1_fix); | ||
expect_eq(fixed_t{1.f}, 1_fix); | ||
expect_eq(fixed_t{-1.f}, -1_fix); | ||
expect_eq(fixed_t{2}, 2_fix); | ||
expect_eq(fixed_t{-2}, -2_fix); | ||
expect_eq(fixed_t{2.f}, 2_fix); | ||
expect_eq(fixed_t{-2.f}, -2_fix); | ||
expect_eq(fixed_t{4.f}, 4_fix); | ||
expect_eq(fixed_t{-4.f}, -4_fix); | ||
|
||
expect_eq(fixed_t{4096ll}, 4096_fix); | ||
expect_eq(fixed_t{-4096ll}, -4096_fix); | ||
expect_eq(fixed_t{4096llu}, 4096_fix); | ||
return {}; | ||
}; | ||
result |= run_constexpr_test(fn_tmpl); | ||
result |= run_consteval_test(fn_tmpl); | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.