Skip to content

Commit ac40f31

Browse files
committed
Wrote a failing test case for leading zero error in cast from float
I think this was not being picked up in CI due to differences in random number generator state between CTest and running the executable directly
1 parent a1a0f61 commit ac40f31

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

tests/casting.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ TEST_CASE("arby::Nat::from_float() with non-finite value throws std::domain_erro
5656
}
5757
}
5858

59+
TEST_CASE("arby::Nat::from_float() with value between 0 and 1") {
60+
// NOTE: top range is the last float value > 1
61+
long double zero_ish = GENERATE(0.0L, std::nextafter(1.0L, 0.0L));
62+
CAPTURE(zero_ish);
63+
64+
arby::Nat object = arby::Nat::from_float(zero_ish);
65+
66+
// value should be correct
67+
CHECK((long double)object == Approx(std::trunc(zero_ish)));
68+
}
69+
5970
TEST_CASE("arby::Nat::from_float() with positive value") {
6071
auto power = GENERATE(0.125, 0.25, 0.5, 1, 2, 4, 8);
6172
auto value = GENERATE_COPY(

0 commit comments

Comments
 (0)