SubRunTest.cpp 3.96 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 23
#include "SubRunTest.hpp"
#include "CppUnitAdditionalMacros.hpp"

CPPUNIT_TEST_SUITE_REGISTRATION( SubRunTest );

using namespace hepnos;

void SubRunTest::setUp() {}

void SubRunTest::tearDown() {}

void SubRunTest::testFillDataStore() {

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

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

    Event e10 = sr1.createEvent(10);
    CPPUNIT_ASSERT(e10.valid());
    CPPUNIT_ASSERT(10 == e10.number());

    Event e23 = sr1.createEvent(23);
    CPPUNIT_ASSERT(e23.valid());
    CPPUNIT_ASSERT(23 == e23.number());

    Event e13 = sr1.createEvent(13);
    CPPUNIT_ASSERT(e13.valid());
    CPPUNIT_ASSERT(13 == e13.number());

    Event e38 = sr1.createEvent(38);
    CPPUNIT_ASSERT(e38.valid());
    CPPUNIT_ASSERT(38 == e38.number());
}

46
void SubRunTest::testBraketOperator() {
Matthieu Dorier's avatar
Matthieu Dorier committed
47 48
    DataSet mds = (*datastore)["matthieu"];
    CPPUNIT_ASSERT(mds.valid());
49
    Run r1 = mds[42];
Matthieu Dorier's avatar
Matthieu Dorier committed
50
    CPPUNIT_ASSERT(r1.valid());
51
    SubRun sr1 = r1[3];
Matthieu Dorier's avatar
Matthieu Dorier committed
52 53 54
    CPPUNIT_ASSERT(sr1.valid());

    // check access to non-existing SubRun
55
    CPPUNIT_ASSERT_THROW(sr1[12], hepnos::Exception);
Matthieu Dorier's avatar
Matthieu Dorier committed
56 57

    // check access to existing SubRun
58
    Event e13 = sr1[13];
Matthieu Dorier's avatar
Matthieu Dorier committed
59 60 61 62 63 64 65
    CPPUNIT_ASSERT(e13.valid());
    CPPUNIT_ASSERT(13 == e13.number());
}

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

void SubRunTest::testBeginEnd() {
    DataSet mds = (*datastore)["matthieu"];
    CPPUNIT_ASSERT(mds.valid());
92
    Run r1 = mds[42];
Matthieu Dorier's avatar
Matthieu Dorier committed
93
    CPPUNIT_ASSERT(r1.valid());
94
    SubRun sr1 = r1[3];
Matthieu Dorier's avatar
Matthieu Dorier committed
95 96 97 98 99 100 101 102 103 104 105 106 107
    CPPUNIT_ASSERT(sr1.valid());

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

void SubRunTest::testLowerUpperBounds() {
    DataSet mds = (*datastore)["matthieu"];
    CPPUNIT_ASSERT(mds.valid());
108
    Run r1 = mds[42];
Matthieu Dorier's avatar
Matthieu Dorier committed
109
    CPPUNIT_ASSERT(r1.valid());
110
    SubRun sr1 = r1[3];
Matthieu Dorier's avatar
Matthieu Dorier committed
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 144 145 146 147 148 149 150 151 152 153 154
    CPPUNIT_ASSERT(sr1.valid());

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