10 #define TEST_CASES 100
13 void TestShifting(unsigned cases)
15 for (unsigned c = 0; c < cases; ++c)
17 Arbint aa(1u, rand());
19 for (unsigned i = 0; i < 100*sizeof(Arbint::digit_t); ++i)
22 //Debug("i is %u bb is %c%s, a was %c%s", i, bb.SignChar(), bb.DigitStr().c_str(), aa.SignChar(), aa.DigitStr().c_str());
26 Fatal("i is %u bb is %c%s, a was %c%s", i, bb.SignChar(), bb.DigitStr().c_str(), aa.SignChar(), aa.DigitStr().c_str());
32 void TestMaths(unsigned cases)
34 for (unsigned i = 0; i < cases; ++i)
42 //Debug("Test %u: a = %li, b = %li", i, a, b);
44 //Debug("a < b = %d", a < b);
45 //Debug("Arb a<b = %d", arb_a < arb_b);
46 assert((arb_a < arb_b) == (a < b));
48 //Debug("a > b = %d", a > b);
49 //Debug("Arb a>b = %d", arb_a > arb_b);
50 assert((arb_a > arb_b) == (a > b));
52 //Debug("a + b = %.16lx", a+b);
53 //Debug("Arb a+b = %s", (arb_a+arb_b).DigitStr().c_str());
54 assert((arb_a+arb_b).AsDigit() == a + b);
56 //Debug("a - b = %li %.16lx", (a-b), (a-b));
57 //Debug("Arb a-b = %s %.16lx", (arb_a-arb_b).DigitStr().c_str(), (arb_a-arb_b).AsDigit());
58 assert((arb_a-arb_b).AsDigit() == a - b);
60 //Debug("a * b = %.16lx", a*b);
61 //Debug("Arb a*b = %s", (arb_a*arb_b).DigitStr().c_str());
62 assert((arb_a*arb_b).AsDigit() == a * b);
64 //Debug("a / b = %.16lx", a/b);
65 //Debug("Arb a/b = %s", (arb_a/arb_b).DigitStr().c_str());
66 assert((arb_a/arb_b).AsDigit() == a / b);
67 assert((arb_a%arb_b).AsDigit() == a % b);
71 void TestConstructFromDouble(unsigned cases)
73 for (unsigned c = 0; c < cases; ++c)
75 int64_t test = (int64_t)(rand()*1e6);
76 double d = (double)(test);
81 Fatal("test is %li, d is %f, a is %s, b is %s", test, d, a.DigitStr().c_str(), b.DigitStr().c_str());
88 int main(int argc, char ** argv)
90 Debug("Shift testing...");
91 TestShifting(TEST_CASES);
92 Debug("Left/Right shift testing succeeded");
94 Debug("Testing +-*/%");
95 TestMaths(TEST_CASES);
96 Debug("All (single digit) maths operator tests successful!");
99 Debug("Testing construct from double");
100 TestConstructFromDouble(TEST_CASES);
101 Debug("Construct from double successful");