Debian Codegraph @

tests/src/utility/test_FastMod.cpp

raw
1 #include <pbcopper/utility/FastMod.h>
2 #include <pbcopper/utility/Random.h>
3
4 #include <vector>
5
6 #include <gtest/gtest.h>
7
8 using namespace PacBio;
9 template <typename T>
10 void TestFM()
11 {
12 uint64_t seed = 0;
13 for (int i = 0; i < 1000000; ++i) {
14 const T modV = Utility::WyHash64Step(seed);
15 Utility::FastMod<T> fm(modV);
16 for (int j = 0; j < 100; ++j) {
17 const T rV = Utility::WyHash64Step(seed);
18 EXPECT_EQ(rV % modV, fm.Modulus(rV));
19 const auto [div, mod] = fm.DivMod(rV);
20 EXPECT_EQ(fm.Modulus(rV), mod);
21 EXPECT_EQ(div * modV + mod, rV);
22 }
23 }
24 }
25
26 TEST(Utility_FastMod, fm)
27 {
28 TestFM<uint32_t>();
29 TestFM<uint64_t>();
30 }