2024-05-29 16:29:08 +10:00
|
|
|
#include <cruft/util/rational.hpp>
|
|
|
|
#include <cruft/util/tap.hpp>
|
2015-07-13 16:27:07 +10:00
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
using cruft::rational;
|
2015-07-13 16:27:07 +10:00
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2015-07-13 16:27:07 +10:00
|
|
|
|
|
|
|
{
|
|
|
|
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 ();
|
|
|
|
}
|