#include <iostream>
#include <istream>
#include <ostream>
#include <sstream>
#include <string>
#include <boost/test/auto_unit_test.hpp>
#include "calc_error.hpp"
#include "number.hpp"
Go to the source code of this file.
Functions | |
BOOST_AUTO_TEST_CASE (test_basics) | |
BOOST_AUTO_TEST_CASE (test_library) | |
BOOST_AUTO_TEST_CASE (test_compare) | |
BOOST_AUTO_TEST_CASE (test_add) | |
BOOST_AUTO_TEST_CASE (test_subtract) | |
BOOST_AUTO_TEST_CASE (test_multiply) | |
BOOST_AUTO_TEST_CASE (test_divide) | |
BOOST_AUTO_TEST_CASE (test_rational) |
BOOST_AUTO_TEST_CASE | ( | test_rational | ) |
Definition at line 99 of file test_number.cpp.
00100 { 00101 number half(rational<long>(1, 2)); 00102 number a(half); 00103 a = a * number(2); 00104 BOOST_CHECK_EQUAL(number(1), a); 00105 a = a / number(3); 00106 a = a * number(3); 00107 BOOST_CHECK_EQUAL(number(1), a); 00108 a = a - half; 00109 BOOST_CHECK_EQUAL(half, a); 00110 a = half + a; 00111 BOOST_CHECK_EQUAL(number(1), a); 00112 }
BOOST_AUTO_TEST_CASE | ( | test_divide | ) |
Definition at line 88 of file test_number.cpp.
00089 { 00090 number a(5), b(2), c; 00091 c = a / b; 00092 BOOST_CHECK_EQUAL(number(rational<long>(5, 2)), c); 00093 a = number(5.0); 00094 c = a / b; 00095 BOOST_CHECK_EQUAL(number(2.5), c); 00096 BOOST_CHECK_THROW(a / number(0), calc_error); 00097 }
BOOST_AUTO_TEST_CASE | ( | test_multiply | ) |
Definition at line 81 of file test_number.cpp.
00082 { 00083 number a(2.0), b(3), c; 00084 c = a * b; 00085 BOOST_CHECK_EQUAL(number(6), c); 00086 }
BOOST_AUTO_TEST_CASE | ( | test_subtract | ) |
Definition at line 74 of file test_number.cpp.
00075 { 00076 number a(2.0), b(1), c; 00077 c = a - b; 00078 BOOST_CHECK_EQUAL(number(1), c); 00079 }
BOOST_AUTO_TEST_CASE | ( | test_add | ) |
Definition at line 67 of file test_number.cpp.
00068 { 00069 number a(1.0), b(2), c; 00070 c = a + b; 00071 BOOST_CHECK_EQUAL(number(3), c); 00072 }
BOOST_AUTO_TEST_CASE | ( | test_compare | ) |
Definition at line 41 of file test_number.cpp.
00042 { 00043 BOOST_CHECK(number(1) < number(2)); 00044 BOOST_CHECK(number(1) <= number(2)); 00045 BOOST_CHECK(number(1) != number(2)); 00046 BOOST_CHECK(number(2) > number(1)); 00047 BOOST_CHECK(number(2) >= number(1)); 00048 BOOST_CHECK(number(2) != number(1)); 00049 BOOST_CHECK(number(1) == number(1)); 00050 BOOST_CHECK(not (number(1) != number(1))); 00051 BOOST_CHECK(not (number(1) > number(2))); 00052 BOOST_CHECK(not (number(1) >= number(2))); 00053 BOOST_CHECK(not (number(1) == number(2))); 00054 BOOST_CHECK(not (number(2) < number(1))); 00055 BOOST_CHECK(not (number(2) <= number(1))); 00056 BOOST_CHECK(not (number(2) == number(1))); 00057 00058 BOOST_CHECK(number(1) < number(1.5)); 00059 BOOST_CHECK(number(1) <= number(1.5)); 00060 BOOST_CHECK(number(1) != number(1.5)); 00061 BOOST_CHECK(number(1.5) > number(1)); 00062 BOOST_CHECK(number(1.5) >= number(1)); 00063 BOOST_CHECK(number(1.5) != number(1)); 00064 BOOST_CHECK(number(1.0) == number(1)); 00065 }
BOOST_AUTO_TEST_CASE | ( | test_library | ) |
Definition at line 24 of file test_number.cpp.
References number::save(), and number::to_string().
00025 { 00026 number i(1), f(2.0), v; 00027 std::stringstream stream; 00028 i.save(stream); 00029 f.save(stream); 00030 v.save(stream); 00031 00032 number n1(stream); 00033 number n2(stream); 00034 number n3(stream); 00035 00036 BOOST_CHECK_EQUAL(number(1), n1); 00037 BOOST_CHECK_EQUAL(number(2), n2); 00038 BOOST_CHECK_EQUAL("", n3.to_string()); 00039 }
BOOST_AUTO_TEST_CASE | ( | test_basics | ) |
Definition at line 12 of file test_number.cpp.
References number::to_string().
00013 { 00014 number n(1L); 00015 BOOST_CHECK_EQUAL("1", n.to_string()); 00016 number m(2.0); 00017 BOOST_CHECK_EQUAL("2", m.to_string()); 00018 m = n; 00019 BOOST_CHECK_EQUAL("1", m.to_string()); 00020 number x((number(n))); 00021 BOOST_CHECK_EQUAL("1", x.to_string()); 00022 }