11#include < attwoodn/expression_tree.hpp>
2+ #include < limits>
3+ #include < iomanip>
24#include < cassert>
35
46using namespace attwoodn ::expression_tree;
57
6- int main (int argc, char ** argv) {
7- std::string hello = " hello world" ;
8+ void test_equals ();
89
9- // assert(op::equals(hello, hello));
10+ int main (int argc, char ** argv) {
11+ test_equals ();
1012
1113 return EXIT_SUCCESS;
14+ }
15+
16+ void test_equals () {
17+ // test string equality/inequality
18+ {
19+ std::string hello = " hello world" ;
20+
21+ assert (op::equals (hello, hello));
22+ assert (op::equals (hello, " hello world" ));
23+ assert (op::equals (" hello world" , " hello world" ));
24+ assert (op::equals (" " , " " ));
25+
26+ assert (!op::equals (" " , " " ));
27+ assert (!op::equals (" hello world" , " hey, world" ));
28+ assert (!op::equals (" test" , " test " ));
29+ }
30+
31+ // test integer equality/inequality
32+ {
33+ assert (op::equals (5 , 5 ));
34+ assert (op::equals (0 , 0 ));
35+ assert (op::equals (-5 , -5 ));
36+ assert (op::equals (123456789 , 123456789 ));
37+ assert (op::equals (123456789 , 123456789L ));
38+ assert (op::equals (255 , 0xff ));
39+ assert (op::equals (0xbeef , 0xbeef ));
40+ assert (op::equals (std::numeric_limits<uint32_t >::max (), std::numeric_limits<uint32_t >::max ()));
41+ assert (op::equals (std::numeric_limits<uint16_t >::max (), std::numeric_limits<uint16_t >::max ()));
42+ assert (op::equals (std::numeric_limits<int16_t >::max (), std::numeric_limits<uint16_t >::max () / 2 ));
43+
44+ assert (!op::equals (-5 , 5 ));
45+ assert (!op::equals (0 , 1 ));
46+ assert (!op::equals (254 , 0xff ));
47+ assert (!op::equals (123456789 , 123456789000L ));
48+ assert (!op::equals (std::numeric_limits<int16_t >::max (), std::numeric_limits<uint16_t >::max () / 2.0 ));
49+ }
50+
51+ // test float equality/inequality
52+ {
53+ assert (op::equals (5.0 , 5.0 ));
54+ assert (op::equals (0.000 , 0.000 ));
55+ assert (op::equals (-5.0 , -5.0 ));
56+ assert (op::equals (3 .400f , 3 .4f ));
57+ assert (op::equals ((float ) 99999.0 , (double ) 99999.0 ));
58+ assert (op::equals (12345 .999f , 12345 .999f ));
59+
60+ assert (!op::equals (5.0 , -5.0 ));
61+ assert (!op::equals (0.000 , 0.000001 ));
62+ assert (!op::equals (-5.0 , -4.999999 ));
63+
64+ // there are some understandable difficulties with comparing floats directly. These should be equal
65+ assert (!op::equals ((float ) 99999.999 , (double ) 99999.999 ));
66+ }
1267}
0 commit comments