Mercurial > public > fructose_gen
comparison tests/g2.h @ 0:d098192f01d9
Initial commit to the repository.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 19 Mar 2011 19:53:12 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:d098192f01d9 |
---|---|
1 #ifndef FRUCTOSE_MAIN_TEST_X2_H | |
2 #define FRUCTOSE_MAIN_TEST_X2_H | |
3 | |
4 #include <stdexcept> | |
5 #include <cmath> | |
6 | |
7 #include "fructose/fructose.h" | |
8 | |
9 // These tests are rigged so that some of them fail. | |
10 // The tests include exercising floating point comparisons | |
11 // and exception handling. | |
12 | |
13 namespace { | |
14 void throw_a_runtime_error() | |
15 { | |
16 throw std::runtime_error("this is a runtime error"); | |
17 } | |
18 } | |
19 | |
20 FRUCTOSE_STRUCT(misc_tests) | |
21 { | |
22 FRUCTOSE_TEST(exceptions) | |
23 { | |
24 fructose_assert_exception(throw_a_runtime_error(), std::logic_error); | |
25 fructose_assert_no_exception(throw_a_runtime_error()); | |
26 } | |
27 | |
28 FRUCTOSE_TEST(loopdata) | |
29 { | |
30 static const struct { | |
31 int line_number; | |
32 int a; | |
33 int b; | |
34 int expected_result; | |
35 } data[] = { | |
36 {__LINE__, 3, 4, 12} | |
37 , {__LINE__, 1, 50, 50} | |
38 , {__LINE__, 5, 12, 60} | |
39 , {__LINE__, 6, 6, 37} | |
40 , {__LINE__, 7, 10, 70} | |
41 }; | |
42 | |
43 for (std::size_t i = 0; i < sizeof(data)/sizeof(data[0]); ++i) | |
44 { | |
45 if (verbose()) | |
46 { | |
47 std::cout << "Testing to see if " | |
48 << data[i].a << " * " << data[i].b | |
49 << " = " << data[i].expected_result | |
50 << std::endl; | |
51 } | |
52 int result = data[i].a * data[i].b; | |
53 fructose_loop1_assert(data[i].line_number, i, | |
54 result == data[i].expected_result); | |
55 } | |
56 } | |
57 | |
58 FRUCTOSE_TEST(floatingpoint) | |
59 { | |
60 double my_pi = 3.141592654; | |
61 double calc_pi = 4.0 * atan(1.0); | |
62 fructose_assert_double_eq_rel_abs(my_pi, calc_pi, 0.01, 0.01); | |
63 fructose_assert_double_eq(my_pi, calc_pi); | |
64 fructose_assert_double_ne(my_pi, calc_pi); | |
65 fructose_assert_double_ne_rel_abs(my_pi, calc_pi, 0.01, 0.01); | |
66 } | |
67 }; | |
68 #endif |