bgneal@0: #ifndef FRUCTOSE_MAIN_TEST_X2_H bgneal@0: #define FRUCTOSE_MAIN_TEST_X2_H bgneal@0: bgneal@0: #include bgneal@0: #include bgneal@0: bgneal@0: #include "fructose/fructose.h" bgneal@0: bgneal@0: // These tests are rigged so that some of them fail. bgneal@0: // The tests include exercising floating point comparisons bgneal@0: // and exception handling. bgneal@0: bgneal@0: namespace { bgneal@0: void throw_a_runtime_error() bgneal@0: { bgneal@0: throw std::runtime_error("this is a runtime error"); bgneal@0: } bgneal@0: } bgneal@0: bgneal@0: FRUCTOSE_STRUCT(misc_tests) bgneal@0: { bgneal@0: FRUCTOSE_TEST(exceptions) bgneal@0: { bgneal@0: fructose_assert_exception(throw_a_runtime_error(), std::logic_error); bgneal@0: fructose_assert_no_exception(throw_a_runtime_error()); bgneal@0: } bgneal@0: bgneal@0: FRUCTOSE_TEST(loopdata) bgneal@0: { bgneal@0: static const struct { bgneal@0: int line_number; bgneal@0: int a; bgneal@0: int b; bgneal@0: int expected_result; bgneal@0: } data[] = { bgneal@0: {__LINE__, 3, 4, 12} bgneal@0: , {__LINE__, 1, 50, 50} bgneal@0: , {__LINE__, 5, 12, 60} bgneal@0: , {__LINE__, 6, 6, 37} bgneal@0: , {__LINE__, 7, 10, 70} bgneal@0: }; bgneal@0: bgneal@0: for (std::size_t i = 0; i < sizeof(data)/sizeof(data[0]); ++i) bgneal@0: { bgneal@0: if (verbose()) bgneal@0: { bgneal@0: std::cout << "Testing to see if " bgneal@0: << data[i].a << " * " << data[i].b bgneal@0: << " = " << data[i].expected_result bgneal@0: << std::endl; bgneal@0: } bgneal@0: int result = data[i].a * data[i].b; bgneal@0: fructose_loop1_assert(data[i].line_number, i, bgneal@0: result == data[i].expected_result); bgneal@0: } bgneal@0: } bgneal@0: bgneal@0: FRUCTOSE_TEST(floatingpoint) bgneal@0: { bgneal@0: double my_pi = 3.141592654; bgneal@0: double calc_pi = 4.0 * atan(1.0); bgneal@0: fructose_assert_double_eq_rel_abs(my_pi, calc_pi, 0.01, 0.01); bgneal@0: fructose_assert_double_eq(my_pi, calc_pi); bgneal@0: fructose_assert_double_ne(my_pi, calc_pi); bgneal@0: fructose_assert_double_ne_rel_abs(my_pi, calc_pi, 0.01, 0.01); bgneal@0: } bgneal@0: }; bgneal@0: #endif