Mercurial > public > fructose_gen
view tests/g2.h @ 4:9d536614c4c0 tip
Added tag fructose1.1.0 for changeset d8aeeb7f6785
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 21 May 2011 21:11:44 -0500 |
parents | d098192f01d9 |
children |
line wrap: on
line source
#ifndef FRUCTOSE_MAIN_TEST_X2_H #define FRUCTOSE_MAIN_TEST_X2_H #include <stdexcept> #include <cmath> #include "fructose/fructose.h" // These tests are rigged so that some of them fail. // The tests include exercising floating point comparisons // and exception handling. namespace { void throw_a_runtime_error() { throw std::runtime_error("this is a runtime error"); } } FRUCTOSE_STRUCT(misc_tests) { FRUCTOSE_TEST(exceptions) { fructose_assert_exception(throw_a_runtime_error(), std::logic_error); fructose_assert_no_exception(throw_a_runtime_error()); } FRUCTOSE_TEST(loopdata) { static const struct { int line_number; int a; int b; int expected_result; } data[] = { {__LINE__, 3, 4, 12} , {__LINE__, 1, 50, 50} , {__LINE__, 5, 12, 60} , {__LINE__, 6, 6, 37} , {__LINE__, 7, 10, 70} }; for (std::size_t i = 0; i < sizeof(data)/sizeof(data[0]); ++i) { if (verbose()) { std::cout << "Testing to see if " << data[i].a << " * " << data[i].b << " = " << data[i].expected_result << std::endl; } int result = data[i].a * data[i].b; fructose_loop1_assert(data[i].line_number, i, result == data[i].expected_result); } } FRUCTOSE_TEST(floatingpoint) { double my_pi = 3.141592654; double calc_pi = 4.0 * atan(1.0); fructose_assert_double_eq_rel_abs(my_pi, calc_pi, 0.01, 0.01); fructose_assert_double_eq(my_pi, calc_pi); fructose_assert_double_ne(my_pi, calc_pi); fructose_assert_double_ne_rel_abs(my_pi, calc_pi, 0.01, 0.01); } }; #endif