libcruft-util/test/rational.cpp
Danny Robson f6056153e3 rename root namespace from util to cruft
This places, at long last, the core library code into the same namespace
as the extended library code.
2018-08-05 14:42:02 +10:00

36 lines
681 B
C++

#include "rational.hpp"
#include "tap.hpp"
using cruft::rational;
int
main (void)
{
cruft::TAP::logger tap;
{
rational<int> val { -3, -2 };
tap.expect (val.n == 3 && val.d == 2, "reduce double negatives at construction");
}
{
rational<int> val { 5 };
tap.expect (val.n == 5 && val.d == 1, "scalar construction");
}
{
rational<int> a { 2, 3 };
rational<int> b { 3, 2 };
tap.expect_eq (a.inverse (), b, "inversion and equality");
}
{
rational<int> val { 8, 12 };
tap.expect_eq (val.reduced (), rational<int> { 2, 3 }, "factorisation");
}
return tap.status ();
}