aboutsummaryrefslogtreecommitdiff
path: root/test/common/queue.h
blob: e3c0cb0a19bfcb19c675cb253a6bc81908f80223 (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
#include <cxxtest/TestSuite.h>

#include "common/queue.h"

class QueueTestSuite : public CxxTest::TestSuite {
public:
	void test_empty_clear() {
		Common::Queue<int> queue;
		TS_ASSERT(queue.empty());

		queue.push(1);
		queue.push(2);
		TS_ASSERT(!queue.empty());

		queue.clear();

		TS_ASSERT(queue.empty());
	}

	void test_size() {
		Common::Queue<int> queue;
		TS_ASSERT_EQUALS(queue.size(), 0);

		queue.push(5);
		TS_ASSERT_EQUALS(queue.size(), 1);

		queue.push(9);
		queue.push(0);
		TS_ASSERT_EQUALS(queue.size(), 3);

		queue.pop();
		TS_ASSERT_EQUALS(queue.size(), 2);
	}

	void test_front_back_pop() {
		Common::Queue<int> queue;

		queue.push( 42);
		queue.push(-23);

		TS_ASSERT_EQUALS(queue.front(), 42);
		TS_ASSERT_EQUALS(queue.back(), -23);

		queue.front() = -23;
		queue.back() = 42;
		TS_ASSERT_EQUALS(queue.front(), -23);
		TS_ASSERT_EQUALS(queue.back(),   42);

		queue.pop();
		TS_ASSERT_EQUALS(queue.front(), 42);
	}

	void test_assign() {
		Common::Queue<int> q1, q2;

		for (int i = 0; i < 5; ++i) {
			q1.push(i);
			q2.push(4-i);
		}

		Common::Queue<int> q3(q1);

		for (int i = 0; i < 5; ++i) {
			TS_ASSERT_EQUALS(q3.front(), i);
			q3.pop();
		}

		TS_ASSERT(q3.empty());

		q3 = q2;

		for (int i = 4; i >= 0; --i) {
			TS_ASSERT_EQUALS(q3.front(), i);
			q3.pop();
		}

		TS_ASSERT(q3.empty());
	}
};