annotate tests/x2.h @ 1:62a54c46da31

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