Skip to content

Commit

Permalink
test: add more cases for binary gcd
Browse files Browse the repository at this point in the history
  • Loading branch information
tolis-0 committed Nov 28, 2023
1 parent 28d2f60 commit f7c7f93
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions math/binary_gcd.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,24 @@ static void tests() {
assert(binary_gcd(0, 11) == 11);
assert(binary_gcd(2*3*7*11*29, 3*5*11*29) == 3*11*29);
assert(binary_gcd(3*17*23*29, 2*2*5*17*23*31) == 17*23);
assert(binary_gcd(7*7*7*7*7, 3*7*7*7*13) == 7*7*7);
assert(binary_gcd(1024*3*7, 1024*11*5) == 1024);
assert(binary_gcd(2*3*3*5, 2*2*3*5) == 2*3*5);
assert(binary_gcd(2*5*11*17*23, 3*7*7*13*19) == 1);

// consecutive numbers have gcd 1
for (i = 1; i < 1000; i++)
for (i = 1; i < 1000; i++) {
assert(binary_gcd(i, i + 1) == 1);
}

for (i = 2; i < 1000; i++)
for (i = 2; i < 1000; i++) {
assert(binary_gcd(i, i) == i);
}

for (i = 1; i < 1000; i++)
for (i = 1; i < 1000; i++) {
assert(binary_gcd(1, i) == 1);
assert(binary_gcd(i, 1) == 1);
}

printf("All tests have successfully passed!\n");
}
Expand Down

0 comments on commit f7c7f93

Please sign in to comment.