openMSX
DivMod_test.cc
Go to the documentation of this file.
1#include "catch.hpp"
2#include "DivModByConst.hh"
3#include "DivModBySame.hh"
4
5using namespace openmsx;
6
7template<uint32_t DIVISOR>
8static void test(const DivModByConst<DIVISOR>& c, const DivModBySame& s,
9 uint64_t dividend)
10{
11 uint64_t rd = dividend / DIVISOR;
12 if (uint32_t(rd) == rd) {
13 CHECK(c.div(dividend) == (dividend / DIVISOR));
14 CHECK(s.div(dividend) == (dividend / DIVISOR));
15 CHECK(c.mod(dividend) == (dividend % DIVISOR));
16 CHECK(s.mod(dividend) == (dividend % DIVISOR));
17 }
18}
19
20template<uint32_t DIVISOR>
21static void test()
22{
24 DivModBySame s; s.setDivisor(DIVISOR);
25
26 for (uint64_t dividend : {0ULL, 1ULL, 2ULL, 3ULL, 4ULL, 5ULL, 7ULL,
27 100ULL, 10015ULL, 12410015ULL, 0x1234567890ULL,
28 0x7FFFFFFFFFFFFFFFULL, 0x8000000000000000ULL,
29 0xFFFFFFFF00000000ULL, 0xFFFFFFFFFFFFFFFFULL}) {
30 test(c, s, dividend);
31 }
32}
33
34TEST_CASE("DivModByConst, DivModBySame")
35{
36 test<1>();
37 test<2>();
38 test<3>();
39 test<4>();
40 test<5>();
41 test<7>();
42 test<10>();
43 test<128>();
44 test<1000>();
45 test<90000>();
46 test<90017>();
47}
TEST_CASE("DivModByConst, DivModBySame")
Helper class to divide multiple times by the same number.
uint32_t div(uint64_t dividend) const
uint32_t mod(uint64_t dividend) const
void setDivisor(uint32_t divisor)
CHECK(m3==m3)
This file implemented 3 utility functions:
Definition Autofire.cc:11
constexpr uint32_t div(uint64_t dividend) const
constexpr uint32_t mod(uint64_t dividend) const