Ignore:
Timestamp:
Sep 7, 2011, 7:17:07 PM (9 years ago)
Author:
sam
Message:

test: replace CppUnit with our LolUnit test suite.

CppUnit is really too large for our needs, would require to be precompiled
for many platforms, in all combinations of debug and release modes, with
additional variants for libstdc++ versions. We replace it with our own
lightweight implementation, LolUnit. Good riddance.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/half.cpp

    r911 r912  
    1313#endif
    1414
    15 #include <cppunit/extensions/HelperMacros.h>
    16 #include <cppunit/TestCaller.h>
    17 #include <cppunit/TestCase.h>
    18 #include <cppunit/TestSuite.h>
    19 
    2015#include <cmath>
    2116
    2217#include "core.h"
     18#include "lol/unit.h"
    2319
    2420/* Ensure isnan() is present even on systems that don't define it, or
     
    3834{
    3935
    40 class HalfTest : public CppUnit::TestCase
     36LOLUNIT_FIXTURE(HalfTest)
    4137{
    42     CPPUNIT_TEST_SUITE(HalfTest);
    43     CPPUNIT_TEST(test_half_from_float);
    44     CPPUNIT_TEST(test_half_makeaccurate);
    45     CPPUNIT_TEST(test_half_makebits);
    46     CPPUNIT_TEST(test_half_is_nan);
    47     CPPUNIT_TEST(test_half_is_inf);
    48     CPPUNIT_TEST(test_half_is_finite);
    49     CPPUNIT_TEST(test_half_is_normal);
    50     CPPUNIT_TEST(test_half_classify);
    51     CPPUNIT_TEST(test_half_to_float);
    52     CPPUNIT_TEST(test_half_to_int);
    53     CPPUNIT_TEST(test_float_op_half);
    54     CPPUNIT_TEST(test_half_op_float);
    55     CPPUNIT_TEST_SUITE_END();
    56 
    5738public:
    58     HalfTest() : CppUnit::TestCase("Matrix Test") {}
    59 
    60     void setUp()
    61     {
    62     }
    63 
     39    void setUp() {}
    6440    void tearDown() {}
    6541
    66     void test_half_from_float()
     42    LOLUNIT_TEST(test_half_from_float)
    6743    {
    6844        for (size_t i = 0; i < sizeof(pairs) / sizeof(*pairs); i++)
     
    7046            half a = (half)pairs[i].f;
    7147            uint16_t b = pairs[i].x;
    72             CPPUNIT_ASSERT_EQUAL(a.bits, b);
    73         }
    74     }
    75 
    76     void test_half_makeaccurate()
     48            LOLUNIT_ASSERT_EQUAL(a.bits, b);
     49        }
     50    }
     51
     52    LOLUNIT_TEST(test_half_makeaccurate)
    7753    {
    7854        for (size_t i = 0; i < sizeof(pairs) / sizeof(*pairs); i++)
     
    8056            half a = half::makeaccurate(pairs[i].f);
    8157            uint16_t b = pairs[i].x;
    82             CPPUNIT_ASSERT_EQUAL(a.bits, b);
    83         }
    84     }
    85 
    86     void test_half_makebits()
     58            LOLUNIT_ASSERT_EQUAL(a.bits, b);
     59        }
     60    }
     61
     62    LOLUNIT_TEST(test_half_makebits)
    8763    {
    8864        for (unsigned int i = 0; i < 0x10000; i++)
     
    9066            half a = half::makebits(i);
    9167            uint16_t b = i;
    92             CPPUNIT_ASSERT_EQUAL(a.bits, b);
    93         }
    94     }
    95 
    96     void test_half_is_nan()
    97     {
    98         CPPUNIT_ASSERT(half::makebits(0x7c01).is_nan());
    99         CPPUNIT_ASSERT(half::makebits(0xfc01).is_nan());
    100         CPPUNIT_ASSERT(half::makebits(0x7e00).is_nan());
    101         CPPUNIT_ASSERT(half::makebits(0xfe00).is_nan());
    102 
    103         CPPUNIT_ASSERT(!half::makebits(0x7c00).is_nan());
    104         CPPUNIT_ASSERT(!half::makebits(0xfc00).is_nan());
    105 
    106         CPPUNIT_ASSERT(!half(0.0f).is_nan());
    107         CPPUNIT_ASSERT(!half(-0.0f).is_nan());
    108         CPPUNIT_ASSERT(!half(2.0f).is_nan());
    109         CPPUNIT_ASSERT(!half(-2.0f).is_nan());
    110     }
    111 
    112     void test_half_is_inf()
    113     {
    114         CPPUNIT_ASSERT(half(65536.0f).is_inf());
    115         CPPUNIT_ASSERT(half(-65536.0f).is_inf());
    116 
    117         CPPUNIT_ASSERT(!half(0.0f).is_inf());
    118         CPPUNIT_ASSERT(!half(-0.0f).is_inf());
    119         CPPUNIT_ASSERT(!half(65535.0f).is_inf());
    120         CPPUNIT_ASSERT(!half(-65535.0f).is_inf());
    121 
    122         CPPUNIT_ASSERT(half::makebits(0x7c00).is_inf());
    123         CPPUNIT_ASSERT(half::makebits(0xfc00).is_inf());
    124 
    125         CPPUNIT_ASSERT(!half::makebits(0x7e00).is_inf());
    126         CPPUNIT_ASSERT(!half::makebits(0xfe00).is_inf());
    127     }
    128 
    129     void test_half_is_finite()
    130     {
    131         CPPUNIT_ASSERT(half(0.0f).is_finite());
    132         CPPUNIT_ASSERT(half(-0.0f).is_finite());
    133         CPPUNIT_ASSERT(half(65535.0f).is_finite());
    134         CPPUNIT_ASSERT(half(-65535.0f).is_finite());
    135 
    136         CPPUNIT_ASSERT(!half(65536.0f).is_finite());
    137         CPPUNIT_ASSERT(!half(-65536.0f).is_finite());
    138 
    139         CPPUNIT_ASSERT(!half::makebits(0x7c00).is_finite());
    140         CPPUNIT_ASSERT(!half::makebits(0xfc00).is_finite());
    141 
    142         CPPUNIT_ASSERT(!half::makebits(0x7e00).is_finite());
    143         CPPUNIT_ASSERT(!half::makebits(0xfe00).is_finite());
    144     }
    145 
    146     void test_half_is_normal()
    147     {
    148         CPPUNIT_ASSERT(half(0.0f).is_normal());
    149         CPPUNIT_ASSERT(half(-0.0f).is_normal());
    150         CPPUNIT_ASSERT(half(65535.0f).is_normal());
    151         CPPUNIT_ASSERT(half(-65535.0f).is_normal());
    152 
    153         CPPUNIT_ASSERT(!half(65536.0f).is_normal());
    154         CPPUNIT_ASSERT(!half(-65536.0f).is_normal());
    155 
    156         CPPUNIT_ASSERT(!half::makebits(0x7c00).is_normal());
    157         CPPUNIT_ASSERT(!half::makebits(0xfc00).is_normal());
    158 
    159         CPPUNIT_ASSERT(!half::makebits(0x7e00).is_normal());
    160         CPPUNIT_ASSERT(!half::makebits(0xfe00).is_normal());
    161     }
    162 
    163     void test_half_classify()
     68            LOLUNIT_ASSERT_EQUAL(a.bits, b);
     69        }
     70    }
     71
     72    LOLUNIT_TEST(test_half_is_nan)
     73    {
     74        LOLUNIT_ASSERT(half::makebits(0x7c01).is_nan());
     75        LOLUNIT_ASSERT(half::makebits(0xfc01).is_nan());
     76        LOLUNIT_ASSERT(half::makebits(0x7e00).is_nan());
     77        LOLUNIT_ASSERT(half::makebits(0xfe00).is_nan());
     78
     79        LOLUNIT_ASSERT(!half::makebits(0x7c00).is_nan());
     80        LOLUNIT_ASSERT(!half::makebits(0xfc00).is_nan());
     81
     82        LOLUNIT_ASSERT(!half(0.0f).is_nan());
     83        LOLUNIT_ASSERT(!half(-0.0f).is_nan());
     84        LOLUNIT_ASSERT(!half(2.0f).is_nan());
     85        LOLUNIT_ASSERT(!half(-2.0f).is_nan());
     86    }
     87
     88    LOLUNIT_TEST(test_half_is_inf)
     89    {
     90        LOLUNIT_ASSERT(half(65536.0f).is_inf());
     91        LOLUNIT_ASSERT(half(-65536.0f).is_inf());
     92
     93        LOLUNIT_ASSERT(!half(0.0f).is_inf());
     94        LOLUNIT_ASSERT(!half(-0.0f).is_inf());
     95        LOLUNIT_ASSERT(!half(65535.0f).is_inf());
     96        LOLUNIT_ASSERT(!half(-65535.0f).is_inf());
     97
     98        LOLUNIT_ASSERT(half::makebits(0x7c00).is_inf());
     99        LOLUNIT_ASSERT(half::makebits(0xfc00).is_inf());
     100
     101        LOLUNIT_ASSERT(!half::makebits(0x7e00).is_inf());
     102        LOLUNIT_ASSERT(!half::makebits(0xfe00).is_inf());
     103    }
     104
     105    LOLUNIT_TEST(test_half_is_finite)
     106    {
     107        LOLUNIT_ASSERT(half(0.0f).is_finite());
     108        LOLUNIT_ASSERT(half(-0.0f).is_finite());
     109        LOLUNIT_ASSERT(half(65535.0f).is_finite());
     110        LOLUNIT_ASSERT(half(-65535.0f).is_finite());
     111
     112        LOLUNIT_ASSERT(!half(65536.0f).is_finite());
     113        LOLUNIT_ASSERT(!half(-65536.0f).is_finite());
     114
     115        LOLUNIT_ASSERT(!half::makebits(0x7c00).is_finite());
     116        LOLUNIT_ASSERT(!half::makebits(0xfc00).is_finite());
     117
     118        LOLUNIT_ASSERT(!half::makebits(0x7e00).is_finite());
     119        LOLUNIT_ASSERT(!half::makebits(0xfe00).is_finite());
     120    }
     121
     122    LOLUNIT_TEST(test_half_is_normal)
     123    {
     124        LOLUNIT_ASSERT(half(0.0f).is_normal());
     125        LOLUNIT_ASSERT(half(-0.0f).is_normal());
     126        LOLUNIT_ASSERT(half(65535.0f).is_normal());
     127        LOLUNIT_ASSERT(half(-65535.0f).is_normal());
     128
     129        LOLUNIT_ASSERT(!half(65536.0f).is_normal());
     130        LOLUNIT_ASSERT(!half(-65536.0f).is_normal());
     131
     132        LOLUNIT_ASSERT(!half::makebits(0x7c00).is_normal());
     133        LOLUNIT_ASSERT(!half::makebits(0xfc00).is_normal());
     134
     135        LOLUNIT_ASSERT(!half::makebits(0x7e00).is_normal());
     136        LOLUNIT_ASSERT(!half::makebits(0xfe00).is_normal());
     137    }
     138
     139    LOLUNIT_TEST(test_half_classify)
    164140    {
    165141        for (uint32_t i = 0; i < 0x10000; i++)
     
    168144            if (h.is_nan())
    169145            {
    170                 CPPUNIT_ASSERT(!h.is_inf());
    171                 CPPUNIT_ASSERT(!h.is_normal());
    172                 CPPUNIT_ASSERT(!h.is_finite());
     146                LOLUNIT_ASSERT(!h.is_inf());
     147                LOLUNIT_ASSERT(!h.is_normal());
     148                LOLUNIT_ASSERT(!h.is_finite());
    173149            }
    174150            else if (h.is_inf())
    175151            {
    176                 CPPUNIT_ASSERT(!h.is_normal());
    177                 CPPUNIT_ASSERT(!h.is_finite());
     152                LOLUNIT_ASSERT(!h.is_normal());
     153                LOLUNIT_ASSERT(!h.is_finite());
    178154            }
    179155            else
    180156            {
    181                 CPPUNIT_ASSERT(h.is_finite());
    182             }
    183         }
    184     }
    185 
    186     void test_half_to_float()
     157                LOLUNIT_ASSERT(h.is_finite());
     158            }
     159        }
     160    }
     161
     162    LOLUNIT_TEST(test_half_to_float)
    187163    {
    188164        for (size_t i = 0; i < sizeof(pairs) / sizeof(*pairs); i++)
     
    190166            float a = (float)half::makebits(pairs[i].x);
    191167            float b = pairs[i].f;
    192             CPPUNIT_ASSERT_EQUAL(a, b);
     168            LOLUNIT_ASSERT_EQUAL(a, b);
    193169        }
    194170
     
    200176            if (h.is_nan())
    201177            {
    202                 CPPUNIT_ASSERT(isnan(f));
    203                 CPPUNIT_ASSERT(g.is_nan());
     178                LOLUNIT_ASSERT(isnan(f));
     179                LOLUNIT_ASSERT(g.is_nan());
    204180            }
    205181            else
    206182            {
    207                 CPPUNIT_ASSERT(!isnan(f));
    208                 CPPUNIT_ASSERT_EQUAL(g.bits, h.bits);
    209             }
    210         }
    211     }
    212 
    213     void test_half_to_int()
    214     {
    215         CPPUNIT_ASSERT_EQUAL((int)(half)(0.0f), 0);
    216         CPPUNIT_ASSERT_EQUAL((int)(half)(-0.0f), 0);
    217         CPPUNIT_ASSERT_EQUAL((int)(half)(0.9f), 0);
    218         CPPUNIT_ASSERT_EQUAL((int)(half)(-0.9f), 0);
    219         CPPUNIT_ASSERT_EQUAL((int)(half)(1.0f), 1);
    220         CPPUNIT_ASSERT_EQUAL((int)(half)(-1.0f), -1);
    221         CPPUNIT_ASSERT_EQUAL((int)(half)(1.9f), 1);
    222         CPPUNIT_ASSERT_EQUAL((int)(half)(-1.9f), -1);
    223         CPPUNIT_ASSERT_EQUAL((int)(half)(65504.0f), 65504);
    224         CPPUNIT_ASSERT_EQUAL((int)(half)(-65504.0f), -65504);
    225     }
    226 
    227     void test_float_op_half()
     183                LOLUNIT_ASSERT(!isnan(f));
     184                LOLUNIT_ASSERT_EQUAL(g.bits, h.bits);
     185            }
     186        }
     187    }
     188
     189    LOLUNIT_TEST(test_half_to_int)
     190    {
     191        LOLUNIT_ASSERT_EQUAL((int)(half)(0.0f), 0);
     192        LOLUNIT_ASSERT_EQUAL((int)(half)(-0.0f), 0);
     193        LOLUNIT_ASSERT_EQUAL((int)(half)(0.9f), 0);
     194        LOLUNIT_ASSERT_EQUAL((int)(half)(-0.9f), 0);
     195        LOLUNIT_ASSERT_EQUAL((int)(half)(1.0f), 1);
     196        LOLUNIT_ASSERT_EQUAL((int)(half)(-1.0f), -1);
     197        LOLUNIT_ASSERT_EQUAL((int)(half)(1.9f), 1);
     198        LOLUNIT_ASSERT_EQUAL((int)(half)(-1.9f), -1);
     199        LOLUNIT_ASSERT_EQUAL((int)(half)(65504.0f), 65504);
     200        LOLUNIT_ASSERT_EQUAL((int)(half)(-65504.0f), -65504);
     201    }
     202
     203    LOLUNIT_TEST(test_float_op_half)
    228204    {
    229205        half zero = 0;
     
    232208
    233209        float a = zero + one;
    234         CPPUNIT_ASSERT_EQUAL(1.0f, a);
     210        LOLUNIT_ASSERT_EQUAL(1.0f, a);
    235211        a += zero;
    236         CPPUNIT_ASSERT_EQUAL(1.0f, a);
     212        LOLUNIT_ASSERT_EQUAL(1.0f, a);
    237213        a -= zero;
    238         CPPUNIT_ASSERT_EQUAL(1.0f, a);
     214        LOLUNIT_ASSERT_EQUAL(1.0f, a);
    239215        a *= one;
    240         CPPUNIT_ASSERT_EQUAL(1.0f, a);
     216        LOLUNIT_ASSERT_EQUAL(1.0f, a);
    241217        a /= one;
    242         CPPUNIT_ASSERT_EQUAL(1.0f, a);
     218        LOLUNIT_ASSERT_EQUAL(1.0f, a);
    243219
    244220        float b = one + zero;
    245         CPPUNIT_ASSERT_EQUAL(1.0f, b);
     221        LOLUNIT_ASSERT_EQUAL(1.0f, b);
    246222        b += one;
    247         CPPUNIT_ASSERT_EQUAL(2.0f, b);
     223        LOLUNIT_ASSERT_EQUAL(2.0f, b);
    248224        b *= two;
    249         CPPUNIT_ASSERT_EQUAL(4.0f, b);
     225        LOLUNIT_ASSERT_EQUAL(4.0f, b);
    250226        b -= two;
    251         CPPUNIT_ASSERT_EQUAL(2.0f, b);
     227        LOLUNIT_ASSERT_EQUAL(2.0f, b);
    252228        b /= two;
    253         CPPUNIT_ASSERT_EQUAL(1.0f, b);
     229        LOLUNIT_ASSERT_EQUAL(1.0f, b);
    254230
    255231        float c = one - zero;
    256         CPPUNIT_ASSERT_EQUAL(1.0f, c);
     232        LOLUNIT_ASSERT_EQUAL(1.0f, c);
    257233
    258234        float d = two - one;
    259         CPPUNIT_ASSERT_EQUAL(1.0f, d);
     235        LOLUNIT_ASSERT_EQUAL(1.0f, d);
    260236
    261237        float e = two + (-one);
    262         CPPUNIT_ASSERT_EQUAL(1.0f, e);
     238        LOLUNIT_ASSERT_EQUAL(1.0f, e);
    263239
    264240        float f = (two * two) / (one + one);
    265         CPPUNIT_ASSERT_EQUAL(2.0f, f);
    266     }
    267 
    268     void test_half_op_float()
     241        LOLUNIT_ASSERT_EQUAL(2.0f, f);
     242    }
     243
     244    LOLUNIT_TEST(test_half_op_float)
    269245    {
    270246        half zero = 0;
     
    274250
    275251        half a = one + 0.0f;
    276         CPPUNIT_ASSERT_EQUAL(one.bits, a.bits);
     252        LOLUNIT_ASSERT_EQUAL(one.bits, a.bits);
    277253        a += 0.0f;
    278         CPPUNIT_ASSERT_EQUAL(one.bits, a.bits);
     254        LOLUNIT_ASSERT_EQUAL(one.bits, a.bits);
    279255        a -= 0.0f;
    280         CPPUNIT_ASSERT_EQUAL(one.bits, a.bits);
     256        LOLUNIT_ASSERT_EQUAL(one.bits, a.bits);
    281257        a *= 1.0f;
    282         CPPUNIT_ASSERT_EQUAL(one.bits, a.bits);
     258        LOLUNIT_ASSERT_EQUAL(one.bits, a.bits);
    283259        a /= 1.0f;
    284         CPPUNIT_ASSERT_EQUAL(one.bits, a.bits);
     260        LOLUNIT_ASSERT_EQUAL(one.bits, a.bits);
    285261
    286262        half b = one + 0.0f;
    287         CPPUNIT_ASSERT_EQUAL(one.bits, b.bits);
     263        LOLUNIT_ASSERT_EQUAL(one.bits, b.bits);
    288264        b += 1.0f;
    289         CPPUNIT_ASSERT_EQUAL(two.bits, b.bits);
     265        LOLUNIT_ASSERT_EQUAL(two.bits, b.bits);
    290266        b *= 2.0f;
    291         CPPUNIT_ASSERT_EQUAL(four.bits, b.bits);
     267        LOLUNIT_ASSERT_EQUAL(four.bits, b.bits);
    292268        b -= 2.0f;
    293         CPPUNIT_ASSERT_EQUAL(two.bits, b.bits);
     269        LOLUNIT_ASSERT_EQUAL(two.bits, b.bits);
    294270        b /= 2.0f;
    295         CPPUNIT_ASSERT_EQUAL(one.bits, b.bits);
     271        LOLUNIT_ASSERT_EQUAL(one.bits, b.bits);
    296272
    297273        half c = 1.0f - zero;
    298         CPPUNIT_ASSERT_EQUAL(one.bits, c.bits);
     274        LOLUNIT_ASSERT_EQUAL(one.bits, c.bits);
    299275
    300276        half d = 2.0f - one;
    301         CPPUNIT_ASSERT_EQUAL(one.bits, d.bits);
     277        LOLUNIT_ASSERT_EQUAL(one.bits, d.bits);
    302278
    303279        half e = 2.0f + (-one);
    304         CPPUNIT_ASSERT_EQUAL(one.bits, e.bits);
     280        LOLUNIT_ASSERT_EQUAL(one.bits, e.bits);
    305281
    306282        half f = (2.0f * two) / (1.0f + one);
    307         CPPUNIT_ASSERT_EQUAL(two.bits, f.bits);
     283        LOLUNIT_ASSERT_EQUAL(two.bits, f.bits);
    308284    }
    309285
     
    330306};
    331307
    332 CPPUNIT_TEST_SUITE_REGISTRATION(HalfTest);
     308LOLUNIT_SETUP_FIXTURE(HalfTest);
    333309
    334310} /* namespace lol */
Note: See TracChangeset for help on using the changeset viewer.