2015-02-06 16:35:40 +11:00
|
|
|
#include "fixed.hpp"
|
2015-11-16 11:42:20 +11:00
|
|
|
#include "types/string.hpp"
|
2015-02-06 16:35:40 +11:00
|
|
|
|
2015-04-13 16:45:56 +10:00
|
|
|
#include "tap.hpp"
|
2015-02-06 16:35:40 +11:00
|
|
|
|
2018-01-09 16:28:25 +11:00
|
|
|
#include <sstream>
|
|
|
|
|
2017-01-04 22:38:41 +11:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2015-02-06 20:01:26 +11:00
|
|
|
template <typename T, unsigned I, unsigned E>
|
2015-02-06 16:35:40 +11:00
|
|
|
void
|
2018-08-05 14:42:02 +10:00
|
|
|
test_simple (cruft::TAP::logger &tap)
|
2015-02-06 16:35:40 +11:00
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
using fixed = cruft::fixed<T,I,E>;
|
2017-01-04 22:38:41 +11:00
|
|
|
using integer = typename fixed::integer_type;
|
2015-02-06 16:35:40 +11:00
|
|
|
|
2017-01-04 22:38:41 +11:00
|
|
|
const auto lo = fixed::from_integer (integer {0});
|
|
|
|
const auto hi = fixed::from_integer (integer {1});
|
2015-02-06 16:35:40 +11:00
|
|
|
|
2015-04-13 16:45:56 +10:00
|
|
|
std::ostringstream os;
|
|
|
|
os << "fixed<" << type_to_string<T> () << ',' << I << ',' << E << '>';
|
2015-02-06 16:35:40 +11:00
|
|
|
|
2016-07-28 13:36:23 +10:00
|
|
|
tap.expect_eq (lo, lo, "%s self equality", os.str ());
|
|
|
|
tap.expect_eq (hi, hi, "%s self equality", os.str ());
|
2015-02-06 16:35:40 +11:00
|
|
|
|
2016-07-28 13:36:23 +10:00
|
|
|
tap.expect_neq (hi, lo, "%s inequality", os.str ());
|
|
|
|
tap.expect_neq (lo, hi, "%s inequality", os.str ());
|
2015-02-06 16:35:40 +11:00
|
|
|
|
2016-07-28 13:36:23 +10:00
|
|
|
tap.expect_lt (lo, hi, "%s less than", os.str ());
|
|
|
|
tap.expect_le (lo, hi, "%s less than equal", os.str ());
|
|
|
|
tap.expect_le (lo, lo, "%s less than equal", os.str ());
|
2015-04-13 16:45:56 +10:00
|
|
|
|
2016-07-28 13:36:23 +10:00
|
|
|
tap.expect_gt (hi, lo, "%s greater than", os.str ());
|
|
|
|
tap.expect_ge (lo, lo, "%s greater than equal", os.str ());
|
|
|
|
tap.expect_ge (hi, lo, "%s greater than equal", os.str ());
|
2015-02-06 16:35:40 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-04 22:38:41 +11:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2015-02-06 16:35:40 +11:00
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2015-04-13 16:45:56 +10:00
|
|
|
|
|
|
|
test_simple<signed,16,16> (tap);
|
|
|
|
test_simple<signed,26, 6> (tap);
|
|
|
|
test_simple<signed,32,32> (tap);
|
2015-02-06 20:01:26 +11:00
|
|
|
|
2015-04-13 16:45:56 +10:00
|
|
|
test_simple<unsigned,16,16> (tap);
|
|
|
|
test_simple<unsigned,26, 6> (tap);
|
|
|
|
test_simple<unsigned,32,32> (tap);
|
2017-05-22 13:55:21 +10:00
|
|
|
|
|
|
|
return tap.status ();
|
2015-02-06 16:35:40 +11:00
|
|
|
}
|