add a test to see that frac_make can handle large integers.

This commit is contained in:
Enno Rehling 2017-03-06 21:43:31 +01:00
parent 05bb109a09
commit e3a969ce9b
1 changed files with 10 additions and 0 deletions

View File

@ -30,6 +30,16 @@ static void test_fractions(CuTest *tc) {
CuAssertIntEquals(tc, -1, frac_sign(frac_make(-1, 1))); CuAssertIntEquals(tc, -1, frac_sign(frac_make(-1, 1)));
CuAssertIntEquals(tc, -1, frac_sign(frac_make(1, -1))); CuAssertIntEquals(tc, -1, frac_sign(frac_make(1, -1)));
CuAssertIntEquals(tc, 0, frac_sign(frac_make(0, 1))); CuAssertIntEquals(tc, 0, frac_sign(frac_make(0, 1)));
/* we reduce large integers by calculating the gcd */
a = frac_make(480000, 3000);
CuAssertIntEquals(tc, 160, a.sa[0]);
CuAssertIntEquals(tc, 1, a.sa[1]);
/* if num is too big for a short, and the gcd is 1, we cheat: */
a = frac_make(480001, 3000);
CuAssertIntEquals(tc, 32000, a.sa[0]);
CuAssertIntEquals(tc, 200, a.sa[1]);
} }
CuSuite *get_variant_suite(void) CuSuite *get_variant_suite(void)