2015-02-06 16:35:40 +11:00
|
|
|
#include "fixed.hpp"
|
|
|
|
|
2015-04-13 16:45:56 +10:00
|
|
|
#include "tap.hpp"
|
2015-02-06 16:35:40 +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
|
2015-04-13 16:45:56 +10:00
|
|
|
test_simple (util::TAP::logger &tap)
|
2015-02-06 16:35:40 +11:00
|
|
|
{
|
2015-02-06 20:01:26 +11:00
|
|
|
using fixed_t = util::fixed<T,I,E>;
|
|
|
|
using integer_t = typename fixed_t::integer_t;
|
2015-02-06 16:35:40 +11:00
|
|
|
|
2015-06-04 22:18:43 +10:00
|
|
|
const fixed_t lo {integer_t{0}};
|
|
|
|
const fixed_t hi {integer_t{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
|
|
|
|
2015-04-13 16:45:56 +10:00
|
|
|
tap.expect_eq (lo, lo, os.str () + " self equality");
|
|
|
|
tap.expect_eq (hi, hi, os.str () + " self equality");
|
2015-02-06 16:35:40 +11:00
|
|
|
|
2015-04-13 16:45:56 +10:00
|
|
|
tap.expect_neq (hi, lo, os.str () + " inequality");
|
|
|
|
tap.expect_neq (lo, hi, os.str () + " inequality");
|
2015-02-06 16:35:40 +11:00
|
|
|
|
2015-04-13 16:45:56 +10:00
|
|
|
tap.expect_lt (lo, hi, os.str () + " less than");
|
|
|
|
tap.expect_le (lo, hi, os.str () + " less than equal");
|
|
|
|
tap.expect_le (lo, lo, os.str () + " less than equal");
|
|
|
|
|
|
|
|
tap.expect_gt (hi, lo, os.str () + " greater than");
|
|
|
|
tap.expect_ge (lo, lo, os.str () + " greater than equal");
|
|
|
|
tap.expect_ge (hi, lo, os.str () + " greater than equal");
|
2015-02-06 16:35:40 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
2015-04-13 16:45:56 +10:00
|
|
|
util::TAP::logger tap;
|
|
|
|
|
|
|
|
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);
|
2015-02-06 16:35:40 +11:00
|
|
|
}
|