MyraMath


Source: tests/utility/Number.cpp

1 // ========================================================================= //
2 // This file is part of MyraMath, copyright (c) 2014-2019 by Ryan A Chilton //
3 // and distributed by MyraCore, LLC. See LICENSE.txt for license terms. //
4 // ========================================================================= //
5 
12 #include <tests/myratest.h>
13 
14 using namespace myra;
15 
16 namespace {
17 
18 // Little bit of template glue to check that two Number types match.
19 template<class N1, class N2> class Match { public: static const bool match = false; };
20 template<> class Match<NumberS,NumberS> { public: static const bool match = true; };
21 template<> class Match<NumberD,NumberD> { public: static const bool match = true; };
22 template<> class Match<NumberC,NumberC> { public: static const bool match = true; };
23 template<> class Match<NumberZ,NumberZ> { public: static const bool match = true; };
24 
25 } // namespace
26 
27 // Test ReflectPrecision<Number>
28 ADD_TEST("ReflectPrecision","[utility]")
29  {
30  bool s = Match<float ,ReflectPrecision<NumberS>::type>::match;
31  bool d = Match<double,ReflectPrecision<NumberD>::type>::match;
32  bool c = Match<float ,ReflectPrecision<NumberC>::type>::match;
33  bool z = Match<double,ReflectPrecision<NumberZ>::type>::match;
34  REQUIRE(s);
35  REQUIRE(d);
36  REQUIRE(c);
37  REQUIRE(z);
38  }
39 
40 // Test RaisePrecision<Number>
41 ADD_TEST("RaisePrecision","[utility]")
42  {
43  bool s = Match<NumberD,RaisePrecision<NumberS>::type>::match;
44  bool c = Match<NumberZ,RaisePrecision<NumberC>::type>::match;
45  REQUIRE(s);
46  REQUIRE(c);
47  }
48 
49 // Test LowerPrecision<Number>
50 ADD_TEST("LowerPrecision","[utility]")
51  {
52  bool d = Match<NumberS,LowerPrecision<NumberD>::type>::match;
53  bool z = Match<NumberC,LowerPrecision<NumberZ>::type>::match;
54  REQUIRE(d);
55  REQUIRE(z);
56  }
Definition: syntax.dox:1
Various utility functions/classes related to scalar Number types.
float NumberS
Useful typedefs.
Definition: Number.h:21


Results: [PASS]


Go back to Summary of /test programs.