13 int main(
int argc,
char** argv)
16 std::locale::global(std::locale(argv[1]));
18 std::locale::global(std::locale(
""));
19 std::cin.imbue(std::locale());
20 std::cout.imbue(std::locale());
24 TEST(c1.value().value() == 0);
26 TEST(c2.value().value() == 100);
27 currency2 c3(3, 1416);
28 TEST(c3.value().value() == 314);
30 TEST(c4.value().value() == 628);
32 TEST(c5.value().value() == 528);
33 TEST(c3 + c3 == c1 + c4);
34 TEST(c3 + c3 <= c1 + c4);
35 TEST(c3 + c3 >= c1 + c4);
42 TEST(c2 / 2L == currency2(0, 50));
58 TEST(c3 + c5 == --c4 + c2);
59 TEST(c3 + c5 == c4 + c2);
60 TEST(c3 + c5 == c4-- + c2);
61 TEST(c3 + c5 == c4 + c2 + c2);
62 TEST(c3 + c5 == ++c4 + c2);
63 TEST(c3 + c5 == c4 + c2);
64 TEST(c3 + c5 == c4++ + c2);
69 TEST((c4 /= 2L) == c5);
72 TEST(c4.as_string() ==
"3.14");
73 TEST(c4.integer() == 3);
74 c4 += currency2(-1,8);
75 TEST((c4 == currency2(2.06)));
76 TEST(c4.integer() == 2);
77 TEST(c4.round() == 2);
79 TEST(c4.round() == 3);
81 TEST(c3.integer() == 3);
82 TEST((-c3).integer() == -3);
83 TEST(c3.fraction() == 14);
84 TEST((-c3).fraction() == 14);
86 TEST(currency4(7,4999).round() == 7L);
87 TEST(currency4(7,5000).round() == 8L);
88 TEST(currency4(7,5001).round() == 8L);
89 TEST(currency4(7,4999).round() == 7L);
90 TEST(currency4(8,5000).round() == 8L);
91 TEST(currency4(8,5001).round() == 9L);
93 TEST(currency4(123,2345500) == currency4(123,2346));
94 TEST(currency4(123,2345501) == currency4(123,2346));
95 TEST(currency4(123,2345499) == currency4(123,2345));
96 TEST(currency4(123,2346500) == currency4(123,2346));
97 TEST(currency4(123,2346501) == currency4(123,2347));
98 TEST(currency4(123,2346499) == currency4(123,2346));
99 TEST(currency4(123,2346400) == currency4(123,2346));
100 TEST(currency4(123,2346600) == currency4(123,2347));
102 TEST(currency4(-3.14159265).value().value() == -31416L);
103 TEST(currency4(123,456789).value().value() == 1234568L);
104 TEST(currency4(123,4).value().value() == 1230004L);
105 TEST(currency4(-10,1111).value().value() == -101111L);
107 std::ostringstream out;
108 c3 = currency2(3, 14);
109 out << std::showbase << c3 <<
" 3.14 " << currency2(-10,12) <<
" 3.00 421.40 end";
111 std::istringstream in(out.str());
118 TEST(c6.value() == -1012L);
120 TEST(c6.value() == 300L);
122 TEST(c6.value() == 42140L);
123 TEST(not (in >> c6));
125 TEST(currency2(31.59265) == currency2(31, 59));
126 TEST(currency2(31.595) == currency2(31, 60));
129 currency2 big(1234567, 89);
130 TEST(big.as_string() ==
"1,234,567.89");
135 }
catch (std::invalid_argument
const& ex) {
137 }
catch (std::exception
const& ex) {
138 std::cerr <<
"wrong exception: " << ex.what() <<
'\n';
Represent a rational number (fraction) as a numerator and denominator.
int main(int argc, char **argv)