Skip to content

Commit 4b0f5ff

Browse files
committed
Test negative values
1 parent b11ea5b commit 4b0f5ff

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/test_gcd_lcm.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,26 @@ void test_gcd_lcm_properties()
130130
BOOST_TEST_EQ(gcd(x, gcd(y, z)), gcd(gcd(x, y), z));
131131
}
132132

133+
void test_negative_value()
134+
{
135+
// These should always return positive values
136+
// Also exercises our constexpr-ness
137+
138+
constexpr int128_t p {2 * 2 * 3};
139+
constexpr int128_t q {2 * 3 * 3};
140+
static_assert(2 * 3 == gcd(p, q));
141+
142+
static_assert(gcd(int128_t{6}, int128_t{10}) == 2);
143+
static_assert(gcd(int128_t{6}, int128_t{-10}) == 2);
144+
static_assert(gcd(int128_t{-6}, int128_t{-10}) == 2);
145+
146+
static_assert(gcd(int128_t{24}, int128_t{0}) == 24);
147+
static_assert(gcd(int128_t{-24}, int128_t{0}) == 24);
148+
149+
static_assert(gcd(int128_t{0}, int128_t{24}) == 24);
150+
static_assert(gcd(int128_t{0}, int128_t{-24}) == 24);
151+
}
152+
133153
int main()
134154
{
135155
test_gcd<uint128_t>();
@@ -139,6 +159,7 @@ int main()
139159
test_gcd<int128_t>();
140160
test_lcm<int128_t>();
141161
test_gcd_lcm_properties<int128_t>();
162+
test_negative_value();
142163

143164
return boost::report_errors();
144165
}

0 commit comments

Comments
 (0)