diff options
author | André Nusser <andre.nusser@googlemail.com> | 2020-02-18 00:26:06 +0100 |
---|---|---|
committer | André Nusser <andre.nusser@googlemail.com> | 2020-02-23 13:46:28 +0100 |
commit | 3184ffc5792bf24523a896961e197d8203cbca56 (patch) | |
tree | d61d532ad9258bc2331c9fc7204dfdbc3768c651 /test/eventsdstest.cc | |
parent | 95ca5bc0c29d1cb3e7a16904dfe3790513870bc7 (diff) |
Add unit test for EventsDS.
Diffstat (limited to 'test/eventsdstest.cc')
-rw-r--r-- | test/eventsdstest.cc | 54 |
1 files changed, 50 insertions, 4 deletions
diff --git a/test/eventsdstest.cc b/test/eventsdstest.cc index 2616053..c884e4f 100644 --- a/test/eventsdstest.cc +++ b/test/eventsdstest.cc @@ -34,14 +34,60 @@ class EventsDSTest public: EventsDSTest() { - DGUNIT_TEST(EventsDSTest::todo); + DGUNIT_TEST(EventsDSTest::test_all); } public: - void todo() + void test_all() { - // TODO: Add some tests here - DGUNIT_ASSERT(false); + EventsDS events_ds; + + // group 1 + events_ds.startAddingNewGroup(42); + events_ds.emplace<SampleEvent>(13, 13, 1.0, nullptr, "a", 42); + events_ds.emplace<SampleEvent>(13, 13, 1.0, nullptr, "b", 42); + events_ds.emplace<SampleEvent>(13, 13, 1.0, nullptr, "c", 42); + + DGUNIT_ASSERT(events_ds.getSampleEventGroupIDsOf(13).empty()); + DGUNIT_ASSERT(events_ds.getSampleEventGroupIDsOf(42).size() == 1); + auto group_id = events_ds.getSampleEventGroupIDsOf(42).back(); + + auto const& event_ids = events_ds.getEventIDsOf(group_id); + DGUNIT_ASSERT(event_ids.size() == 3); + + // group 2 + events_ds.startAddingNewGroup(42); + events_ds.emplace<SampleEvent>(13, 13, 1.0, nullptr, "d", 42); + + DGUNIT_ASSERT(events_ds.getSampleEventGroupIDsOf(42).size() == 2); + + // group 3 + events_ds.startAddingNewGroup(23); + events_ds.emplace<SampleEvent>(7, 7, 1.0, nullptr, "foo", 23); + events_ds.emplace<SampleEvent>(7, 7, 1.0, nullptr, "bar", 23); + + DGUNIT_ASSERT(events_ds.getSampleEventGroupIDsOf(42).size() == 2); + DGUNIT_ASSERT(events_ds.numberOfEvents(13) == 4); + DGUNIT_ASSERT(events_ds.numberOfEvents(7) == 2); + + // iterate over + std::string group_concat = ""; + for (auto const& sample_event: events_ds.iterateOver<SampleEvent>(13)) { + group_concat.append(sample_event.group); + } + DGUNIT_ASSERT(group_concat == "abcd"); + + // remove + auto event_id = events_ds.getEventIDsOf(events_ds.getSampleEventGroupIDsOf(42).back()).back(); + events_ds.remove(event_id); + DGUNIT_ASSERT(events_ds.getSampleEventGroupIDsOf(42).size() == 1); + + event_id = events_ds.getEventIDsOf(events_ds.getSampleEventGroupIDsOf(23).back()).back(); + events_ds.remove(event_id); + DGUNIT_ASSERT(!events_ds.getSampleEventGroupIDsOf(23).empty()); + event_id = events_ds.getEventIDsOf(events_ds.getSampleEventGroupIDsOf(23).back()).back(); + events_ds.remove(event_id); + DGUNIT_ASSERT(events_ds.getSampleEventGroupIDsOf(23).empty()); } }; |