1 //===-- tests/test_power2funcs.cpp ------------------------------*- C++ -*-===//
2 // Test of certain compile-time/run-time functions relating to powers of 2.
4 // Copyright (C) 2013-2014 Dirk Steinke.
5 // See copyright and license notice in COPYRIGHT or include/jitcs.h
6 //===----------------------------------------------------------------------===//
8 #include "jitcs_int_power2funcs.h"
11 using namespace jitcs
;
13 static void test(UnitTest
& t
) {
14 t
.check("IsPowerOf2OrZeroCT/0", IsPowerOf2OrZeroCT
<0>::Val
== true);
15 t
.check("IsPowerOf2OrZeroCT/3", IsPowerOf2OrZeroCT
<3>::Val
== false);
16 t
.check("IsPowerOf2OrZeroCT/4", IsPowerOf2OrZeroCT
<4>::Val
== true);
17 t
.check("IsPowerOf2CT/0", IsPowerOf2CT
<0>::Val
== false);
18 t
.check("IsPowerOf2CT/3", IsPowerOf2CT
<3>::Val
== false);
19 t
.check("IsPowerOf2CT/4", IsPowerOf2CT
<4>::Val
== true);
20 t
.check("Log2CT/1", Log2CT
<1>::Val
== 0);
21 t
.check("Log2CT/4", Log2CT
<4>::Val
== 2);
22 t
.check("Log2CT/5", Log2CT
<5>::Val
== 2);
23 t
.check("RoundUpToPowerOf2CT/16,16", RoundUpToPowerOf2CT
<16,16>::Val
== 16);
24 t
.check("RoundUpToPowerOf2CT/20,16", RoundUpToPowerOf2CT
<20,16>::Val
== 32);
26 t
.check("IsPowerOf2OrZero/0", IsPowerOf2OrZero(0) == true);
27 t
.check("IsPowerOf2OrZero/3", IsPowerOf2OrZero(3) == false);
28 t
.check("IsPowerOf2OrZero/4", IsPowerOf2OrZero(4) == true);
29 t
.check("IsPowerOf2/0", IsPowerOf2(0) == false);
30 t
.check("IsPowerOf2/3", IsPowerOf2(3) == false);
31 t
.check("IsPowerOf2/4", IsPowerOf2(4) == true);
32 t
.check("RoundUpToPowerOf2/16,T16", RoundUpToPowerOf2
<16>(16) == 16);
33 t
.check("RoundUpToPowerOf2/20,T16", RoundUpToPowerOf2
<16>(20) == 32);
34 t
.check("RoundUpToPowerOf2/16,16", RoundUpToPowerOf2(16,16) == 16);
35 t
.check("RoundUpToPowerOf2/20,16", RoundUpToPowerOf2(20,16) == 32);
36 t
.check("DivRoundedUpByPowerOf2/16,T16", DivRoundedUpByPowerOf2
<16>(16) == 1);
37 t
.check("DivRoundedUpByPowerOf2/20,T16", DivRoundedUpByPowerOf2
<16>(20) == 2);
40 static UnitTestRun
_1("ADT/PowerOf2Funcs", test
);