3 CPPUNIT_TEST_SUITE_REGISTRATION(test_math::FixedTest);
5 typedef math::Fixed<16> Fixed;
6 typedef math::Fixed<8> LowerFixed;
7 typedef math::Fixed<24> HigherFixed;
12 void FixedTest::setUp() {
16 void FixedTest::tearDown() {
21 void FixedTest::testConversion() {
22 CPPUNIT_ASSERT_EQUAL(1, Fixed(3, 2).Int());
23 CPPUNIT_ASSERT_DOUBLES_EQUAL(0.75, Fixed(3, 4).Double(), std::numeric_limits<double>::epsilon());
25 CPPUNIT_ASSERT_EQUAL(-1, Fixed(-3, 2).Int());
26 CPPUNIT_ASSERT_DOUBLES_EQUAL(-1.25, Fixed(-5, 4).Double(), std::numeric_limits<double>::epsilon());
28 CPPUNIT_ASSERT_EQUAL(Fixed(3, 2), Fixed(1.5));
29 CPPUNIT_ASSERT_EQUAL(Fixed(-4, 10), Fixed(-0.4));
31 CPPUNIT_ASSERT_EQUAL(Fixed(3, 2), Fixed(HigherFixed(3, 2)));
32 CPPUNIT_ASSERT_EQUAL(Fixed(3, 2), Fixed(LowerFixed(3, 2)));
35 void FixedTest::testComparison() {
36 CPPUNIT_ASSERT_EQUAL(Fixed(), Fixed());
37 CPPUNIT_ASSERT_EQUAL(Fixed(1), Fixed(1));
38 CPPUNIT_ASSERT_EQUAL(Fixed(-1), Fixed(-1));
40 CPPUNIT_ASSERT_EQUAL(Fixed(1, 2), Fixed(2, 4));
42 CPPUNIT_ASSERT(Fixed(0) != Fixed(1));
43 CPPUNIT_ASSERT(Fixed(0) != Fixed(-1));
44 CPPUNIT_ASSERT(Fixed(1, 2) != Fixed(-1, 2));
46 CPPUNIT_ASSERT(Fixed(0) < Fixed(1));
47 CPPUNIT_ASSERT(Fixed(1, 2) <= Fixed(1));
48 CPPUNIT_ASSERT(Fixed(0) > Fixed(-1));
49 CPPUNIT_ASSERT(Fixed(1) >= Fixed(-1, 2));
51 CPPUNIT_ASSERT(Fixed() == LowerFixed());
52 CPPUNIT_ASSERT(Fixed() == HigherFixed());
53 CPPUNIT_ASSERT(Fixed(1) == LowerFixed(1));
54 CPPUNIT_ASSERT(Fixed(1) == HigherFixed(1));
55 CPPUNIT_ASSERT(Fixed(-1) == LowerFixed(-1));
56 CPPUNIT_ASSERT(Fixed(-1) == HigherFixed(-1));
58 CPPUNIT_ASSERT(Fixed(1, 2) == LowerFixed(2, 4));
59 CPPUNIT_ASSERT(Fixed(1, 2) == HigherFixed(2, 4));
61 CPPUNIT_ASSERT(Fixed(0) != LowerFixed(1));
62 CPPUNIT_ASSERT(Fixed(0) != HigherFixed(1));
63 CPPUNIT_ASSERT(Fixed(0) != LowerFixed(-1));
64 CPPUNIT_ASSERT(Fixed(0) != HigherFixed(-1));
65 CPPUNIT_ASSERT(Fixed(1, 2) != LowerFixed(-1, 2));
66 CPPUNIT_ASSERT(Fixed(1, 2) != HigherFixed(-1, 2));
68 CPPUNIT_ASSERT(Fixed(0) < LowerFixed(1));
69 CPPUNIT_ASSERT(Fixed(0) < HigherFixed(1));
70 CPPUNIT_ASSERT(Fixed(1, 2) <= LowerFixed(1));
71 CPPUNIT_ASSERT(Fixed(1, 2) <= HigherFixed(1));
72 CPPUNIT_ASSERT(Fixed(0) > LowerFixed(-1));
73 CPPUNIT_ASSERT(Fixed(0) > HigherFixed(-1));
74 CPPUNIT_ASSERT(Fixed(1) >= LowerFixed(-1, 2));
75 CPPUNIT_ASSERT(Fixed(1) >= HigherFixed(-1, 2));
78 void FixedTest::testSum() {
81 Fixed(1, 4) + Fixed(1, 2));
84 Fixed(2) - Fixed(0.5));
87 void FixedTest::testProduct() {
90 Fixed(2) * Fixed(2.5));
96 Fixed(3, 4) * Fixed(-7, 3));
99 Fixed(3, 4) * Fixed(-2.33333333));
100 CPPUNIT_ASSERT_EQUAL(
102 Fixed(2) / Fixed(0.5));
103 CPPUNIT_ASSERT_EQUAL(
106 CPPUNIT_ASSERT_EQUAL(
108 Fixed(15) / Fixed(5));
109 CPPUNIT_ASSERT_EQUAL(
114 void FixedTest::testModulo() {
115 CPPUNIT_ASSERT_EQUAL(
118 CPPUNIT_ASSERT_EQUAL(
120 Fixed(11) % Fixed(6));
121 CPPUNIT_ASSERT_EQUAL(
124 CPPUNIT_ASSERT_EQUAL(
126 Fixed(8) % Fixed(7.5));