Ignore:
Timestamp:
Oct 3, 2011, 1:36:16 AM (11 years ago)
Author:
sam
Message:

core: add real constants for 0, 1, 2 and 10, and reorder static constants
so that their initialisation order ensures they have the proper values. Add
unit tests for these constants.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/real.cpp

    r997 r998  
    2323LOLUNIT_FIXTURE(RealTest)
    2424{
     25    LOLUNIT_TEST(Constants)
     26    {
     27        double a0 = real::R_0;
     28        double a1 = real::R_1;
     29        double a2 = real::R_2;
     30        double a10 = real::R_10;
     31
     32        LOLUNIT_ASSERT_EQUAL(a0, 0.0);
     33        LOLUNIT_ASSERT_EQUAL(a1, 1.0);
     34        LOLUNIT_ASSERT_EQUAL(a2, 2.0);
     35        LOLUNIT_ASSERT_EQUAL(a10, 10.0);
     36
     37        double b0 = log(real::R_E);
     38        LOLUNIT_ASSERT_EQUAL(b0, 1.0);
     39
     40        double b1 = exp(re(real::R_LOG2E));
     41        LOLUNIT_ASSERT_EQUAL(b1, 2.0);
     42
     43        double b2 = exp(re(real::R_LOG10E));
     44        LOLUNIT_ASSERT_EQUAL(b2, 10.0);
     45
     46        double b3 = exp(real::R_LN2);
     47        LOLUNIT_ASSERT_EQUAL(b3, 2.0);
     48
     49        double b4 = exp(real::R_LN10);
     50        LOLUNIT_ASSERT_EQUAL(b4, 10.0);
     51
     52        double b5 = sin(real::R_PI);
     53        double b6 = cos(real::R_PI);
     54        LOLUNIT_ASSERT_DOUBLES_EQUAL(b5, 0.0, 1e-100);
     55        LOLUNIT_ASSERT_EQUAL(b6, -1.0);
     56
     57        double b7 = sin(real::R_PI_2);
     58        double b8 = cos(real::R_PI_2);
     59        LOLUNIT_ASSERT_EQUAL(b7, 1.0);
     60        LOLUNIT_ASSERT_DOUBLES_EQUAL(b8, 0.0, 1e-100);
     61
     62        double b9 = sin(real::R_PI_4) * sin(real::R_PI_4);
     63        double b10 = cos(real::R_PI_4) * cos(real::R_PI_4);
     64        LOLUNIT_ASSERT_EQUAL(b9, 0.5);
     65        LOLUNIT_ASSERT_EQUAL(b10, 0.5);
     66    }
     67
    2568    LOLUNIT_TEST(FloatToReal)
    2669    {
Note: See TracChangeset for help on using the changeset viewer.