RunSetTest.cpp 4.75 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
#include "RunSetTest.hpp"
#include "CppUnitAdditionalMacros.hpp"

CPPUNIT_TEST_SUITE_REGISTRATION( RunSetTest );

using namespace hepnos;

void RunSetTest::setUp() {}

void RunSetTest::tearDown() {}

void RunSetTest::testFillDataStore() {

    auto mds = datastore->createDataSet("matthieu");
    CPPUNIT_ASSERT(mds.valid());
    // erroneous run creation
    CPPUNIT_ASSERT_THROW(
            mds.createRun(InvalidRunNumber),
            hepnos::Exception);
    // default-constructed run has InvalidRunNumber number
    Run r0;
    CPPUNIT_ASSERT(!r0.valid());
23
    CPPUNIT_ASSERT_THROW(r0.number(), hepnos::Exception);
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    // correct run creation
    Run r1 = mds.createRun(42);
    // assert the characteristics of the created dataset
    CPPUNIT_ASSERT(r1.valid());
    CPPUNIT_ASSERT(42 == r1.number());
    CPPUNIT_ASSERT_EQUAL_STR("matthieu", r1.container());
    // assert comparison with a default-constructed run
    CPPUNIT_ASSERT(r0 != r1);
    CPPUNIT_ASSERT(!(r0 == r1));
    // assert that r1.next() is not valid
    Run r2 = r1.next();
    CPPUNIT_ASSERT(!r2.valid());
    // create more runs
    Run r3 = mds.createRun(47);
    r2 = mds.createRun(45);
    // assert that these are valid
    CPPUNIT_ASSERT(r2.valid());
    CPPUNIT_ASSERT(r3.valid());
    // assert that r1.next() == r2 and r2.next() == r3
    CPPUNIT_ASSERT(r2 == r1.next());
    CPPUNIT_ASSERT(r3 == r2.next());
    // create more datasets for future tests
    Run r4 = mds.createRun(53);
    Run r5 = mds.createRun(59);
    CPPUNIT_ASSERT(r4.valid());
    CPPUNIT_ASSERT(r5.valid());
}

52
void RunSetTest::testBraketOperator() {
53 54 55 56
    DataSet mds = (*datastore)["matthieu"];
    CPPUNIT_ASSERT(mds.valid());
    // check that accessing a Run that does not exist
    // yields a non-valid Run instance
57
    CPPUNIT_ASSERT_THROW(mds[43], hepnos::Exception);
58 59 60

    // check that accessing a run that exists yields
    // a valid Run instance with correct information
61
    Run r2 = mds[45];
62 63 64 65 66 67
    CPPUNIT_ASSERT(r2.valid());
    CPPUNIT_ASSERT(45 == r2.number());
    CPPUNIT_ASSERT_EQUAL_STR("matthieu", r2.container());

    // check that we access the same Run using the runs() function
    // to go through the RunSet
68
    Run r22 = mds.runs()[45];
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 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 144 145 146 147 148 149 150 151 152 153 154
    CPPUNIT_ASSERT(r2 == r22);
}

void RunSetTest::testFind() {
    DataSet mds = (*datastore)["matthieu"];
    CPPUNIT_ASSERT(mds.valid());
    // test calling find for a Run that does not exist
    {
        auto it = mds.runs().find(43);
        CPPUNIT_ASSERT(it == mds.runs().end());
        CPPUNIT_ASSERT(!(it->valid()));
    }
    // test calling find for a Run that exists
    {
        auto it = mds.runs().find(45);
        CPPUNIT_ASSERT(it != mds.runs().end());
        CPPUNIT_ASSERT(it->valid());
        CPPUNIT_ASSERT(45 == it->number());
        // test iteration
        ++it;
        CPPUNIT_ASSERT(it->valid());
        CPPUNIT_ASSERT(47 == it->number());
    }
}

void RunSetTest::testBeginEnd() {
    DataSet mds = (*datastore)["matthieu"];
    CPPUNIT_ASSERT(mds.valid());

    std::vector<RunNumber> numbers = {42, 45, 47, 53, 59};
    auto it = mds.runs().begin();
    for(int i=0; i < numbers.size(); i++, it++) {
        CPPUNIT_ASSERT_EQUAL(numbers[i], it->number());
    }
    CPPUNIT_ASSERT(it == mds.runs().end());
}

void RunSetTest::testLowerUpperBounds() {
    DataSet mds = (*datastore)["matthieu"];
    CPPUNIT_ASSERT(mds.valid());

    {
        auto it = mds.runs().lower_bound(47);
        CPPUNIT_ASSERT(it->valid());
        CPPUNIT_ASSERT(it->number() == 47);
    }
    {
        auto it = mds.runs().lower_bound(48);
        CPPUNIT_ASSERT(it->valid());
        CPPUNIT_ASSERT(it->number() == 53);
    }
    {
        auto it = mds.runs().lower_bound(46);
        CPPUNIT_ASSERT(it->valid());
        CPPUNIT_ASSERT(it->number() == 47);
    }
    {
        auto it = mds.runs().lower_bound(60);
        CPPUNIT_ASSERT(!(it->valid()));
        CPPUNIT_ASSERT(it == mds.runs().end());
    }
    {
        auto it = mds.runs().upper_bound(47);
        CPPUNIT_ASSERT(it->valid());
        CPPUNIT_ASSERT(it->number() == 53);
    }
    {
        auto it = mds.runs().upper_bound(48);
        CPPUNIT_ASSERT(it->valid());
        CPPUNIT_ASSERT(it->number() == 53);
    }
    {
        auto it = mds.runs().upper_bound(46);
        CPPUNIT_ASSERT(it->valid());
        CPPUNIT_ASSERT(it->number() == 47);
    }
    {
        auto it = mds.runs().upper_bound(59);
        CPPUNIT_ASSERT(!(it->valid()));
        CPPUNIT_ASSERT(it == mds.runs().end());
    }
}

void RunSetTest::testCreateSubRuns() {
    DataSet mds = (*datastore)["matthieu"];
    CPPUNIT_ASSERT(mds.valid());
155
    Run r2 = mds[45];
156 157

    {
158
        CPPUNIT_ASSERT_THROW(r2[73], hepnos::Exception);
159 160 161 162 163 164 165 166
    }

    {
        SubRun sr = r2.createSubRun(73);
        CPPUNIT_ASSERT(sr.valid());
        CPPUNIT_ASSERT(73 == sr.number());
    }
}