Skip to content

Commit d1bbbf1

Browse files
committed
test: reorganize tests
1 parent 9835049 commit d1bbbf1

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

math/ncr_modulo_p.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,18 +137,25 @@ class NCRModuloP {
137137
* @returns void
138138
*/
139139
static void tests() {
140-
// (52323 C 26161) % (1e9 + 7) = 224944353
141-
assert(
142-
math::ncr_modulo_p::NCRModuloP(60000, 1000000007).ncr(52323, 26161) ==
143-
224944353);
144-
// 6 C 2 = 30, 30%5 = 0
145-
assert(math::ncr_modulo_p::NCRModuloP(20, 5).ncr(6, 2) == 0);
146-
// 7C3 = 35, 35 % 29 = 8
147-
assert(math::ncr_modulo_p::NCRModuloP(100, 29).ncr(7, 3) == 6);
148-
}
140+
struct TestCase {
141+
const uint64_t size;
142+
const uint64_t p;
143+
const uint64_t n;
144+
const uint64_t r;
145+
const int64_t expected;
149146

150-
void other_tests() {
151-
assert(math::ncr_modulo_p::NCRModuloP(1000, 13).ncr(10, 3) == 120 % 13);
147+
TestCase(const uint64_t size, const uint64_t p, const uint64_t n,
148+
const uint64_t r, const int64_t expected)
149+
: size(size), p(p), n(n), r(r), expected(expected) {}
150+
};
151+
const std::vector<TestCase> test_cases = {
152+
TestCase(60000, 1000000007, 52323, 26161, 224944353),
153+
TestCase(20, 5, 6, 2, 30 % 5), TestCase(100, 29, 7, 3, 35 % 29),
154+
TestCase(1000, 13, 10, 3, 120 % 13)};
155+
for (const auto& tc : test_cases) {
156+
assert(math::ncr_modulo_p::NCRModuloP(tc.size, tc.p).ncr(tc.n, tc.r) ==
157+
tc.expected);
158+
}
152159
}
153160

154161
/**
@@ -166,7 +173,6 @@ int main() {
166173
std::cout << 6 << "C" << i << " = " << ncrObj.ncr(6, i) << "\n";
167174
}
168175
tests(); // execute the tests
169-
other_tests();
170176
std::cout << "Assertions passed\n";
171177
return 0;
172178
}

0 commit comments

Comments
 (0)