xmscore  1.0
math.cpp
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
6 //------------------------------------------------------------------------------
7 
8 //----- Included files ---------------------------------------------------------
9 
10 #include <xmscore/math/math.h>
11 
12 //----- Function definitions ---------------------------------------------------
13 
14 #if CXX_TEST
15 // TESTS
18 
19 #include <xmscore/math/math.t.h>
20 #include <cmath> // sqrt
21 #include <xmscore/points/pt.h>
23 
28 //------------------------------------------------------------------------------
30 //------------------------------------------------------------------------------
32 {
33  // TS_FAIL("MathUnitTests::TestIt");
34 
35  // TS_ASSERT_EQUALS(0,1);
36  TS_ASSERT_DELTA(xms::MagSquared(1, 2, 3, 4), 30.0, 0.001);
37  TS_ASSERT_DELTA(xms::MagSquared(1, 2, 3), 14.0, 0.001);
38  TS_ASSERT_DELTA(xms::MagSquared(1, 2), 5.0, 0.001);
39 
40  TS_ASSERT_DELTA(xms::Mag(1, 2, 3, 4), 5.4772, 0.001);
41  TS_ASSERT_DELTA(xms::Mag(1, 2, 3), 3.7416, 0.001);
42  TS_ASSERT_DELTA(xms::Mag(1, 2), 2.2360, 0.001);
43 
44  TS_ASSERT_EQUALS(xms::Clamp(5, 1, 8), 5);
45  TS_ASSERT_EQUALS(xms::Clamp(5, 5, 8), 5);
46  TS_ASSERT_EQUALS(xms::Clamp(5, 1, 5), 5);
47  TS_ASSERT_EQUALS(xms::Clamp(5, 6, 8), 6);
48  TS_ASSERT_EQUALS(xms::Clamp(5, 1, 2), 2);
49  // TS_ASSERT_EQUALS(0,1);
50 
51  // EPS
52  const double D = 1e-5;
53  TS_ASSERT_EQUALS(xms::EQ_EPS(1.0, 1.0, D), true);
54  TS_ASSERT_EQUALS(xms::EQ_EPS(1.12345, 1.12345, D), true);
55  TS_ASSERT_EQUALS(xms::EQ_EPS(1.12345, 1.12346, D), true);
56  TS_ASSERT_EQUALS(xms::EQ_EPS(1.12345, 1.12347, D), true);
57  TS_ASSERT_EQUALS(xms::EQ_EPS(1.0, 2.0, D), false); // using integers
58  TS_ASSERT_EQUALS(xms::EQ_EPS(1.0, 1.0, D), true); // using integers
59  TS_ASSERT_EQUALS(xms::EQ_EPS(2.0, 1.0, D), false); // using integers
60 
61  TS_ASSERT_EQUALS(xms::LT_EPS(1.0, 1.0, D), false);
62  TS_ASSERT_EQUALS(xms::LT_EPS(1.12345, 1.12345, D), false);
63  TS_ASSERT_EQUALS(xms::LT_EPS(1.12345, 1.12346, D), false);
64  TS_ASSERT_EQUALS(xms::LT_EPS(1.12345, 1.12347, D), false);
65  TS_ASSERT_EQUALS(xms::LT_EPS(1.0, 2.0, D), true); // using integers
66  TS_ASSERT_EQUALS(xms::LT_EPS(1.0, 1.0, D), false); // using integers
67  TS_ASSERT_EQUALS(xms::LT_EPS(2.0, 1.0, D), false); // using integers
68 
69  TS_ASSERT_EQUALS(xms::GT_EPS(1.0, 1.0, D), false);
70  TS_ASSERT_EQUALS(xms::GT_EPS(1.12345, 1.12345, D), false);
71  TS_ASSERT_EQUALS(xms::GT_EPS(1.12345, 1.12346, D), false);
72  TS_ASSERT_EQUALS(xms::GT_EPS(1.12345, 1.12347, D), false);
73  TS_ASSERT_EQUALS(xms::GT_EPS(1.12347, 1.12345, D), false);
74  TS_ASSERT_EQUALS(xms::GT_EPS(1.0, 2.0, D), false); // using integers
75  TS_ASSERT_EQUALS(xms::GT_EPS(1.0, 1.0, D), false); // using integers
76  TS_ASSERT_EQUALS(xms::GT_EPS(2.0, 1.0, D), true); // using integers
77 
78  // TOL
79  TS_ASSERT_EQUALS(xms::EQ_TOL(1.0, 1.0, D), true);
80  TS_ASSERT_EQUALS(xms::EQ_TOL(1.12345, 1.12345, D), true);
81  TS_ASSERT_EQUALS(xms::EQ_TOL(1.12345, 1.12346, D), true);
82  TS_ASSERT_EQUALS(xms::EQ_TOL(1.12345, 1.12347, D), false);
83  TS_ASSERT_EQUALS(xms::EQ_TOL(1.0, 2.0, D), false); // using integers
84  TS_ASSERT_EQUALS(xms::EQ_TOL(1.0, 1.0, D), true); // using integers
85  TS_ASSERT_EQUALS(xms::EQ_TOL(2.0, 1.0, D), false); // using integers
86 
87  TS_ASSERT_EQUALS(xms::LT_TOL(1.0, 1.0, D), false);
88  TS_ASSERT_EQUALS(xms::LT_TOL(1.12345, 1.12345, D), false);
89  TS_ASSERT_EQUALS(xms::LT_TOL(1.12345, 1.12346, D), false);
90  TS_ASSERT_EQUALS(xms::LT_TOL(1.12345, 1.12347, D), true);
91  TS_ASSERT_EQUALS(xms::LT_TOL(1.0, 2.0, D), true); // using integers
92  TS_ASSERT_EQUALS(xms::LT_TOL(1.0, 1.0, D), false); // using integers
93  TS_ASSERT_EQUALS(xms::LT_TOL(2.0, 1.0, D), false); // using integers
94 
95  TS_ASSERT_EQUALS(xms::GT_TOL(1.0, 1.0, D), false);
96  TS_ASSERT_EQUALS(xms::GT_TOL(1.12345, 1.12345, D), false);
97  TS_ASSERT_EQUALS(xms::GT_TOL(1.12345, 1.12346, D), false);
98  TS_ASSERT_EQUALS(xms::GT_TOL(1.12345, 1.12347, D), false);
99  TS_ASSERT_EQUALS(xms::GT_TOL(1.12347, 1.12345, D), true);
100  TS_ASSERT_EQUALS(xms::GT_TOL(1.0, 2.0, D), false); // using integers
101  TS_ASSERT_EQUALS(xms::GT_TOL(1.0, 1.0, D), false); // using integers
102  TS_ASSERT_EQUALS(xms::GT_TOL(2.0, 1.0, D), true); // using integers
103 
104 } // MptTester::TestIt
105 #endif
void TestIt()
Test xmscore math functions.
Definition: math.cpp:31