From ea84abf5880f0af2642dd3de08a6d9c6f7f88426 Mon Sep 17 00:00:00 2001 From: Matthew Hoops Date: Mon, 17 May 2010 20:57:36 +0000 Subject: Add tests for Common::Rational from patch #2963496 (VideoDecoder Rewrite), also courtesy of DrMcCoy who wrote the main Common::Rational class too svn-id: r49062 --- test/common/rational.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 test/common/rational.h (limited to 'test/common') diff --git a/test/common/rational.h b/test/common/rational.h new file mode 100644 index 0000000000..f1a4ea6ab2 --- /dev/null +++ b/test/common/rational.h @@ -0,0 +1,38 @@ +#include + +#include "common/rational.h" + +class RationalTestSuite : public CxxTest::TestSuite { +public: + void test_operators() { + Common::Rational r0(6, 3); + Common::Rational r1(1, 2); + + Common::Rational r2(62, 2); + Common::Rational r3(34, 4); + + Common::Rational r4 = (r0 + r1) * 3; + Common::Rational r5 = (r2 - r3) / 3; + + Common::Rational r6 = r5 - 1; + + TS_ASSERT(r4 == r5); + + TS_ASSERT(-r4 == -r5); + + TS_ASSERT( r4 > r6); + TS_ASSERT( r4 >= r6); + TS_ASSERT(!(r4 < r6)); + TS_ASSERT(!(r4 <= r6)); + + TS_ASSERT( r4 > 7); + TS_ASSERT( r4 >= 7); + TS_ASSERT(!(r4 < 7)); + TS_ASSERT(!(r4 <= 7)); + + TS_ASSERT( 7 < r4); + TS_ASSERT( 7 <= r4); + TS_ASSERT(!(7 > r4)); + TS_ASSERT(!(7 >= r4)); + } +}; -- cgit v1.2.3