From 7d0625db683e06cc55b8ffa2f56a8b26e6bb7427 Mon Sep 17 00:00:00 2001 From: Tim King Date: Fri, 14 Dec 2012 21:04:41 -0500 Subject: [PATCH] Adding unit test for different versions of division. --- test/unit/util/integer_black.h | 75 ++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/test/unit/util/integer_black.h b/test/unit/util/integer_black.h index d2f697637..2f9998066 100644 --- a/test/unit/util/integer_black.h +++ b/test/unit/util/integer_black.h @@ -387,4 +387,79 @@ public: TS_ASSERT_EQUALS(Integer(i).length(), internalLength(i)); } } + + void testEuclideanDivision() { + Integer q, r; + + Integer::euclidianQR(q, r, 1, 4); + TS_ASSERT_EQUALS( q, Integer(0)); + TS_ASSERT_EQUALS( r, Integer(1)); + + + Integer::euclidianQR(q, r, 1, -4); + TS_ASSERT_EQUALS( q, Integer(0)); + TS_ASSERT_EQUALS( r, Integer(1)); + + Integer::euclidianQR(q, r, -1, 4); + TS_ASSERT_EQUALS( q, Integer(-1)); + TS_ASSERT_EQUALS( r, Integer(3)); + + Integer::euclidianQR(q,r, -1, -4); + TS_ASSERT_EQUALS( q, Integer(1)); + TS_ASSERT_EQUALS( r, Integer(3)); + + Integer::euclidianQR(q,r, 5, 4); + TS_ASSERT_EQUALS( q, Integer(1)); + TS_ASSERT_EQUALS( r, Integer(1)); + + Integer::euclidianQR(q,r, 5, -4); + TS_ASSERT_EQUALS( q, Integer(-1)); + TS_ASSERT_EQUALS( r, Integer(1)); + + Integer::euclidianQR(q,r, -5, 4); + TS_ASSERT_EQUALS( q, Integer(-2)); + TS_ASSERT_EQUALS( r, Integer(3)); + + Integer::euclidianQR(q,r, -5, -4); + TS_ASSERT_EQUALS( q, Integer(2)); + TS_ASSERT_EQUALS( r, Integer(3)); + + } + void testFloorDivision() { + Integer q, r; + + Integer::floorQR(q, r, 1, 4); + TS_ASSERT_EQUALS( q, Integer(0)); + TS_ASSERT_EQUALS( r, Integer(1)); + + + Integer::floorQR(q, r, 1, -4); + TS_ASSERT_EQUALS( q, Integer(-1)); + TS_ASSERT_EQUALS( r, Integer(-3)); + + Integer::floorQR(q, r, -1, 4); + TS_ASSERT_EQUALS( q, Integer(-1)); + TS_ASSERT_EQUALS( r, Integer(3)); + + Integer::floorQR(q,r, -1, -4); + TS_ASSERT_EQUALS( q, Integer(0)); + TS_ASSERT_EQUALS( r, Integer(-1)); + + Integer::floorQR(q,r, 5, 4); + TS_ASSERT_EQUALS( q, Integer(1)); + TS_ASSERT_EQUALS( r, Integer(1)); + + Integer::floorQR(q,r, 5, -4); + TS_ASSERT_EQUALS( q, Integer(-2)); + TS_ASSERT_EQUALS( r, Integer(-3)); + + Integer::floorQR(q,r, -5, 4); + TS_ASSERT_EQUALS( q, Integer(-2)); + TS_ASSERT_EQUALS( r, Integer(3)); + + Integer::floorQR(q,r, -5, -4); + TS_ASSERT_EQUALS( q, Integer(1)); + TS_ASSERT_EQUALS( r, Integer(-1)); + + } }; -- 2.30.2