1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
|
#include "dgunit.h"
#include "../src/events_ds.h"
class EventsDSTest
: public DGUnit
{
public:
EventsDSTest()
{
DGUNIT_TEST(EventsDSTest::test_all);
}
public:
void test_all()
{
EventsDS events_ds;
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();
const auto& event_ids = events_ds.getEventIDsOf(group_id);
DGUNIT_ASSERT(event_ids.size() == 3);
events_ds.startAddingNewGroup(42);
events_ds.emplace<SampleEvent>(13, 13, 1.0, nullptr, "d", 42);
DGUNIT_ASSERT(events_ds.getSampleEventGroupIDsOf(42).size() == 2);
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);
std::string group_concat = "";
for (const auto& sample_event: events_ds.iterateOver<SampleEvent>(13))
{
group_concat.append(sample_event.group);
}
DGUNIT_ASSERT(group_concat == "abcd");
for (const auto& sample_event: events_ds.iterateOver<SampleEvent>(13))
{
DGUNIT_ASSERT(events_ds.get<SampleEvent>(sample_event.id).channel == 13);
DGUNIT_ASSERT(events_ds.getType(sample_event.id) == Event::Type::SampleEvent);
}
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());
}
};
static EventsDSTest test;
|