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