summaryrefslogtreecommitdiff
path: root/test/test-counters.cpp
blob: 3f9740ff9c61a9e88811f3faaedae5aa4a2aaedc (plain)
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
#define BOOST_TEST_MODULE Counters
#include <boost/test/unit_test.hpp>

#include "helpers.h"

BOOST_FIXTURE_TEST_SUITE(ec, EventCounterTarget)

BOOST_AUTO_TEST_CASE(zero)
{
	std::array<unsigned long, ENUM_END_EVENT> z {};
	BOOST_CHECK_EQUAL_COLLECTIONS(counters.begin(), counters.end(), z.begin(), z.end());
}

BOOST_AUTO_TEST_CASE(tick_getAll)
{
	BOOST_CHECK_EQUAL(&counters, &getAll());
}

BOOST_AUTO_TEST_CASE(tick_one)
{
	tick(ROTATE_EVENT);
	BOOST_CHECK_EQUAL(get(ROTATE_EVENT), 1);
}

BOOST_AUTO_TEST_CASE(tick_three)
{
	add(ROTATE_EVENT, 3);
	BOOST_CHECK_EQUAL(get(ROTATE_EVENT), 3);
}

BOOST_AUTO_TEST_CASE(tick_different)
{
	add(ROTATE_EVENT, 2).add(UPDATE_ROWS_EVENT_V1, 1);
	BOOST_CHECK_EQUAL(get(ROTATE_EVENT), 2);
	BOOST_CHECK_EQUAL(get(UPDATE_ROWS_EVENT_V1), 1);
}

BOOST_AUTO_TEST_CASE(compare_zero)
{
	EventCounter other;
	BOOST_CHECK(other >= *this);
}

BOOST_AUTO_TEST_CASE(compare_one)
{
	EventCounter other;
	tick(ROTATE_EVENT);

	BOOST_CHECK(!(other >= *this));

	other.tick(ROTATE_EVENT);
	BOOST_CHECK(other >= *this);

	other.tick(ROTATE_EVENT);
	BOOST_CHECK(other >= *this);
}

BOOST_AUTO_TEST_CASE(compare_many)
{
	EventCounter other;
	add(ROTATE_EVENT, 2).add(UPDATE_ROWS_EVENT_V1, 1);

	BOOST_CHECK(!(other >= *this));

	other.tick(UPDATE_ROWS_EVENT_V1);
	BOOST_CHECK(!(other >= *this));

	other.tick(UPDATE_ROWS_EVENT_V1);
	BOOST_CHECK(!(other >= *this));

	other.tick(ROTATE_EVENT);
	BOOST_CHECK(!(other >= *this));

	other.tick(ROTATE_EVENT);
	BOOST_CHECK(other >= *this);

	other.tick(ROTATE_EVENT);
	BOOST_CHECK(other >= *this);

	other.tick(UPDATE_ROWS_EVENT_V1);
	BOOST_CHECK(other >= *this);
}

BOOST_AUTO_TEST_SUITE_END()