Mercurial > public > fructose_gen
comparison tests/x2.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 class misc_tests : public fructose::test_base<misc_tests> | |
21 { | |
22 public: | |
23 void testexceptions(const std::string& test_name) | |
24 { | |
25 fructose_assert_exception(throw_a_runtime_error(), std::logic_error); | |
26 fructose_assert_no_exception(throw_a_runtime_error()); | |
27 } | |
28 | |
29 void testloopdata(const std::string& test_name) | |
30 { | |
31 static const struct { | |
32 int line_number; | |
33 int a; | |
34 int b; | |
35 int expected_result; | |
36 } data[] = { | |
37 {__LINE__, 3, 4, 12} | |
38 , {__LINE__, 1, 50, 50} | |
39 , {__LINE__, 5, 12, 60} | |
40 , {__LINE__, 6, 6, 37} | |
41 , {__LINE__, 7, 10, 70} | |
42 }; | |
43 | |
44 for (std::size_t i = 0; i < sizeof(data)/sizeof(data[0]); ++i) | |
45 { | |
46 if (verbose()) | |
47 { | |
48 std::cout << "Testing to see if " | |
49 << data[i].a << " * " << data[i].b | |
50 << " = " << data[i].expected_result | |
51 << std::endl; | |
52 } | |
53 int result = data[i].a * data[i].b; | |
54 fructose_loop1_assert(data[i].line_number, i, | |
55 result == data[i].expected_result); | |
56 } | |
57 } | |
58 | |
59 void testfloatingpoint(const std::string& test_name) | |
60 { | |
61 double my_pi = 3.141592654; | |
62 double calc_pi = 4.0 * atan(1.0); | |
63 fructose_assert_double_eq_rel_abs(my_pi, calc_pi, 0.01, 0.01); | |
64 fructose_assert_double_eq(my_pi, calc_pi); | |
65 fructose_assert_double_ne(my_pi, calc_pi); | |
66 fructose_assert_double_ne_rel_abs(my_pi, calc_pi, 0.01, 0.01); | |
67 } | |
68 }; | |
69 #endif |