RunTest.cpp 3.59 KB
Newer Older
Matthieu Dorier's avatar
Matthieu Dorier committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include "RunTest.hpp"
#include "CppUnitAdditionalMacros.hpp"

CPPUNIT_TEST_SUITE_REGISTRATION( RunTest );

using namespace hepnos;

void RunTest::setUp() {}

void RunTest::tearDown() {}

void RunTest::testFillDataStore() {

    auto mds = datastore->createDataSet("matthieu");
    CPPUNIT_ASSERT(mds.valid());
    Run r1 = mds.createRun(42);
    CPPUNIT_ASSERT(r1.valid());
}

void RunTest::testCreateSubRuns() {
    DataSet mds = (*datastore)["matthieu"];
    CPPUNIT_ASSERT(mds.valid());
23
    Run r1 = mds[42];
Matthieu Dorier's avatar
Matthieu Dorier committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

    SubRun sr10 = r1.createSubRun(10);
    CPPUNIT_ASSERT(sr10.valid());
    CPPUNIT_ASSERT(10 == sr10.number());

    SubRun sr23 = r1.createSubRun(23);
    CPPUNIT_ASSERT(sr23.valid());
    CPPUNIT_ASSERT(23 == sr23.number());

    SubRun sr13 = r1.createSubRun(13);
    CPPUNIT_ASSERT(sr13.valid());
    CPPUNIT_ASSERT(13 == sr13.number());

    SubRun sr38 = r1.createSubRun(38);
    CPPUNIT_ASSERT(sr38.valid());
    CPPUNIT_ASSERT(38 == sr38.number());
}

42
void RunTest::testBraketOperator() {
Matthieu Dorier's avatar
Matthieu Dorier committed
43 44 45
    DataSet mds = (*datastore)["matthieu"];
    CPPUNIT_ASSERT(mds.valid());

46
    Run r1 = mds[42];
Matthieu Dorier's avatar
Matthieu Dorier committed
47 48 49
    CPPUNIT_ASSERT(r1.valid());

    // check access to non-existing SubRun
50
    CPPUNIT_ASSERT_THROW(r1[12], hepnos::Exception);
Matthieu Dorier's avatar
Matthieu Dorier committed
51 52

    // check access to existing SubRun
53
    SubRun sr13 = r1[13];
Matthieu Dorier's avatar
Matthieu Dorier committed
54 55 56 57 58 59 60
    CPPUNIT_ASSERT(sr13.valid());
    CPPUNIT_ASSERT(13 == sr13.number());
}

void RunTest::testFind() {
    DataSet mds = (*datastore)["matthieu"];
    CPPUNIT_ASSERT(mds.valid());
61
    Run r1 = mds[42];
Matthieu Dorier's avatar
Matthieu Dorier committed
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
    CPPUNIT_ASSERT(r1.valid());
    // test calling find for a SubRun that does not exist
    {
        auto it = r1.find(12);
        CPPUNIT_ASSERT(it == r1.end());
        CPPUNIT_ASSERT(!(it->valid()));
    }
    // test calling find for a SubRun that exists
    {
        auto it = r1.find(13);
        CPPUNIT_ASSERT(it != r1.end());
        CPPUNIT_ASSERT(it->valid());
        CPPUNIT_ASSERT(13 == it->number());
        // test iteration
        ++it;
        CPPUNIT_ASSERT(it->valid());
        CPPUNIT_ASSERT(23 == it->number());
    }
}

void RunTest::testBeginEnd() {
    DataSet mds = (*datastore)["matthieu"];
    CPPUNIT_ASSERT(mds.valid());
85
    Run r1 = mds[42];
Matthieu Dorier's avatar
Matthieu Dorier committed
86 87 88 89 90 91 92 93 94 95 96 97 98
    CPPUNIT_ASSERT(r1.valid());

    std::vector<SubRunNumber> numbers = {10, 13, 23, 38};
    auto it = r1.begin();
    for(int i=0; i < numbers.size(); i++, it++) {
        CPPUNIT_ASSERT_EQUAL(numbers[i], it->number());
    }
    CPPUNIT_ASSERT(it == r1.end());
}

void RunTest::testLowerUpperBounds() {
    DataSet mds = (*datastore)["matthieu"];
    CPPUNIT_ASSERT(mds.valid());
99
    Run r1 = mds[42];
Matthieu Dorier's avatar
Matthieu Dorier committed
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
    CPPUNIT_ASSERT(r1.valid());

    {
        auto it = r1.lower_bound(13);
        CPPUNIT_ASSERT(it->valid());
        CPPUNIT_ASSERT(it->number() == 13);
    }
    {
        auto it = r1.lower_bound(14);
        CPPUNIT_ASSERT(it->valid());
        CPPUNIT_ASSERT(it->number() == 23);
    }
    {
        auto it = r1.lower_bound(12);
        CPPUNIT_ASSERT(it->valid());
        CPPUNIT_ASSERT(it->number() == 13);
    }
    {
        auto it = r1.lower_bound(40);
        CPPUNIT_ASSERT(!(it->valid()));
        CPPUNIT_ASSERT(it == r1.end());
    }
    {
        auto it = r1.upper_bound(13);
        CPPUNIT_ASSERT(it->valid());
        CPPUNIT_ASSERT(it->number() == 23);
    }
    {
        auto it = r1.upper_bound(14);
        CPPUNIT_ASSERT(it->valid());
        CPPUNIT_ASSERT(it->number() == 23);
    }
    {
        auto it = r1.upper_bound(12);
        CPPUNIT_ASSERT(it->valid());
        CPPUNIT_ASSERT(it->number() == 13);
    }
    {
        auto it = r1.upper_bound(38);
        CPPUNIT_ASSERT(!(it->valid()));
        CPPUNIT_ASSERT(it == r1.end());
    }
}