aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMax Horn2011-02-09 00:12:02 +0000
committerMax Horn2011-02-09 00:12:02 +0000
commit97bfd60e61991be9ed6686d6eb70370a901d4371 (patch)
tree3347de6a4c6cf6132060153c84b1d8ed0bbf4058 /test
parent2184326dbc428d7b6ef1eda510ae299838d5a2d2 (diff)
downloadscummvm-rg350-97bfd60e61991be9ed6686d6eb70370a901d4371.tar.gz
scummvm-rg350-97bfd60e61991be9ed6686d6eb70370a901d4371.tar.bz2
scummvm-rg350-97bfd60e61991be9ed6686d6eb70370a901d4371.zip
COMMON: Reduce overflow risk in Common::Rational += and -= operators
svn-id: r55839
Diffstat (limited to 'test')
-rw-r--r--test/common/rational.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/test/common/rational.h b/test/common/rational.h
index 21b84a8a41..46dfc278c7 100644
--- a/test/common/rational.h
+++ b/test/common/rational.h
@@ -86,6 +86,22 @@ public:
TS_ASSERT_EQUALS(r1 - 1, Common::Rational(-1, 2));
}
+ void test_add_sub2() {
+ // Make sure cancelation works correctly
+ const Common::Rational r0(4, 15); // = 8 / 30
+ const Common::Rational r1(1, 6); // = 5 / 30
+
+ TS_ASSERT_EQUALS(r0 + r1, Common::Rational(13, 30));
+ TS_ASSERT_EQUALS(r1 + r0, Common::Rational(13, 30));
+ TS_ASSERT_EQUALS(r0 - r1, Common::Rational(1, 10));
+ TS_ASSERT_EQUALS(r1 - r0, Common::Rational(-1, 10));
+
+ TS_ASSERT_EQUALS(1 + r1, Common::Rational(7, 6));
+ TS_ASSERT_EQUALS(r1 + 1, Common::Rational(7, 6));
+ TS_ASSERT_EQUALS(1 - r1, Common::Rational(5, 6));
+ TS_ASSERT_EQUALS(r1 - 1, Common::Rational(-5, 6));
+ }
+
void test_mul() {
const Common::Rational r0(6, 3);
const Common::Rational r1(1, 2);