aboutsummaryrefslogtreecommitdiff
path: root/test/common/rational.h
diff options
context:
space:
mode:
Diffstat (limited to 'test/common/rational.h')
-rw-r--r--test/common/rational.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/test/common/rational.h b/test/common/rational.h
index f1a4ea6ab2..5425ec4d81 100644
--- a/test/common/rational.h
+++ b/test/common/rational.h
@@ -35,4 +35,60 @@ public:
TS_ASSERT(!(7 > r4));
TS_ASSERT(!(7 >= r4));
}
+
+ void test_assign() {
+ Common::Rational r0(6, 3);
+ Common::Rational r1(1, 2);
+
+ TS_ASSERT(r0 == 2);
+ TS_ASSERT(r1 == Common::Rational(1, 2));
+
+ r0 = r1;
+ TS_ASSERT(r0 == r1);
+ TS_ASSERT(r0 == Common::Rational(1, 2));
+ }
+
+ void test_negative() {
+ Common::Rational r0(6, 3);
+ Common::Rational r1(1, 2);
+
+ r0 = -r0;
+ r1 = -r1;
+ TS_ASSERT(r0 == -2);
+ TS_ASSERT(r1 == Common::Rational(-1, 2));
+ TS_ASSERT(r1 == Common::Rational(1, -2));
+ }
+
+ void test_add_sub() {
+ const Common::Rational r0(6, 3);
+ const Common::Rational r1(1, 2);
+
+ TS_ASSERT(r0 + r1 == Common::Rational(5, 2));
+ TS_ASSERT(r1 + r0 == Common::Rational(5, 2));
+ TS_ASSERT(r0 - r1 == Common::Rational(3, 2));
+ TS_ASSERT(r1 - r0 == Common::Rational(-3, 2));
+ }
+
+ void test_mul() {
+ const Common::Rational r0(6, 3);
+ const Common::Rational r1(1, 2);
+
+ const Common::Rational r2(15, 14);
+ const Common::Rational r3(7,3);
+ const Common::Rational r4(5,2);
+
+ TS_ASSERT_EQUALS(r0 * r1, 1);
+
+ TS_ASSERT_EQUALS(r2 * r3, r4);
+ TS_ASSERT_EQUALS((-r2) * r3, -r4);
+ TS_ASSERT_EQUALS(r2 * (-r3), -r4);
+ TS_ASSERT_EQUALS((-r2) * (-r3), r4);
+ }
+
+ void test_div() {
+ Common::Rational r0(6, 3);
+ Common::Rational r1(1, 2);
+
+ TS_ASSERT(r0 / r1 == 4);
+ }
};