From e3a969ce9b6d078fe0731f2982e04faac005190d Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 6 Mar 2017 21:43:31 +0100 Subject: [PATCH] add a test to see that frac_make can handle large integers. --- src/util/variant.test.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/util/variant.test.c b/src/util/variant.test.c index 12299720b..37aa3f77e 100644 --- a/src/util/variant.test.c +++ b/src/util/variant.test.c @@ -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, 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)