| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <gtest/gtest.h> | ||
| 2 | #include "na64calib/indices/range-override.hh" | ||
| 3 | |||
| 4 | namespace na64dp { | ||
| 5 | namespace calib { | ||
| 6 | |||
| 7 | // Tests validity ranges lookup | ||
| 8 | 8 | TEST(FileIndex, RunsValidityRanges) { | |
| 9 | // |---a---|---b--|-----c-----|----d-----|--e--... | ||
| 10 | // ^1 ^10 ^33 ^78 ^99 | ||
| 11 | 2 | na64dp::calib::RangeIndex<int, char> i; | |
| 12 |
1/1✓ Branch 2 taken 1 times.
|
2 | i.insert({ 1, 'a' }); |
| 13 |
1/1✓ Branch 2 taken 1 times.
|
2 | i.insert({10, 'b' }); |
| 14 |
1/1✓ Branch 2 taken 1 times.
|
2 | i.insert({33, 'c' }); |
| 15 |
1/1✓ Branch 2 taken 1 times.
|
2 | i.insert({78, 'd' }); |
| 16 |
1/1✓ Branch 2 taken 1 times.
|
2 | i.insert({99, 'e' }); |
| 17 | // test middle cases | ||
| 18 |
3/4✓ Branch 1 taken 1 times.
✓ Branch 5 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
|
2 | EXPECT_EQ( i.get_valid_entry_for( 5)->second, 'a' ); |
| 19 |
3/4✓ Branch 1 taken 1 times.
✓ Branch 5 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
|
2 | EXPECT_EQ( i.get_valid_entry_for( 20)->second, 'b' ); |
| 20 |
3/4✓ Branch 1 taken 1 times.
✓ Branch 5 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
|
2 | EXPECT_EQ( i.get_valid_entry_for( 40)->second, 'c' ); |
| 21 |
3/4✓ Branch 1 taken 1 times.
✓ Branch 5 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
|
2 | EXPECT_EQ( i.get_valid_entry_for( 80)->second, 'd' ); |
| 22 |
3/4✓ Branch 1 taken 1 times.
✓ Branch 5 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
|
2 | EXPECT_EQ( i.get_valid_entry_for(110)->second, 'e' ); |
| 23 | // test boundary cases | ||
| 24 |
3/4✓ Branch 1 taken 1 times.
✓ Branch 5 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
|
2 | EXPECT_EQ( i.get_valid_entry_for( 1)->second, 'a' ); |
| 25 |
3/4✓ Branch 1 taken 1 times.
✓ Branch 5 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
|
2 | EXPECT_EQ( i.get_valid_entry_for( 10)->second, 'b' ); |
| 26 |
3/4✓ Branch 1 taken 1 times.
✓ Branch 5 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
|
2 | EXPECT_EQ( i.get_valid_entry_for( 33)->second, 'c' ); |
| 27 |
3/4✓ Branch 1 taken 1 times.
✓ Branch 5 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
|
2 | EXPECT_EQ( i.get_valid_entry_for( 78)->second, 'd' ); |
| 28 |
3/4✓ Branch 1 taken 1 times.
✓ Branch 5 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
|
2 | EXPECT_EQ( i.get_valid_entry_for( 99)->second, 'e' ); |
| 29 | // test error (no `valid from' entry) | ||
| 30 |
4/6✓ Branch 2 taken 1 times.
✓ Branch 5 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 1 times.
✓ Branch 23 taken 1 times.
✗ Branch 24 not taken.
|
2 | ASSERT_EQ( i.get_valid_entry_for(0), i.end() ); |
| 31 | 2 | } | |
| 32 | |||
| 33 | // TODO: rewrite | ||
| 34 | #if 0 | ||
| 35 | class TestRangeOverrideRunIndex : public ::testing::Test { | ||
| 36 | public: | ||
| 37 | RangeOverrideRunIndex fi; | ||
| 38 | TestRangeOverrideRunIndex() { | ||
| 39 | fi.add_entry( EventID(5, 0, 12) | ||
| 40 | , "foo-int" | ||
| 41 | , RangeOverrideRunIndex::UpdateRecipe{ "loader1" } ); | ||
| 42 | fi.add_entry( EventID(10, 0, 0) | ||
| 43 | , "foo-int" | ||
| 44 | , iIndex::UpdateRecipe{ "loader2" } ); | ||
| 45 | } | ||
| 46 | }; | ||
| 47 | |||
| 48 | TEST_F(TestRangeOverrideRunIndex, indexReturnsCalibOnCalib) { | ||
| 49 | iIndex::Updates ul; | ||
| 50 | fi.updates( EventID( 5, 0, 11), EventID( 5, 0, 12) | ||
| 51 | , {0,0}, {0,0} | ||
| 52 | , ul ); | ||
| 53 | ASSERT_EQ( 1, ul.size() ); | ||
| 54 | auto update = *ul.begin(); | ||
| 55 | EXPECT_EQ( update.first, "foo-int" ); | ||
| 56 | ASSERT_EQ( 1, update.second.size() ); | ||
| 57 | EXPECT_STREQ( update.second.begin()->loaderName.c_str(), "loader1" ); | ||
| 58 | //const EventID calibEID(5, 0, 12); | ||
| 59 | //EXPECT_EQ( update.second.begin()->eventID, calibEID ); | ||
| 60 | } | ||
| 61 | #endif | ||
| 62 | |||
| 63 | } | ||
| 64 | } | ||
| 65 | |||
| 66 |