aboutsummaryrefslogtreecommitdiff
path: root/test/common/array.h
blob: 8e1c53b430c624d03cefda0bba58b68e5a30dd10 (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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
#include <cxxtest/TestSuite.h>

#include "common/stdafx.h"
#include "common/array.h"

class ArrayTestSuite : public CxxTest::TestSuite
{
	public:
	void test_empty_clear( void )
	{
		Common::Array<int> array;
		TS_ASSERT( array.empty() );
		array.push_back(17);
		array.push_back(33);
		TS_ASSERT( !array.empty() );
		array.clear();
		TS_ASSERT( array.empty() );
	}

	void test_iterator( void )
	{
		Common::Array<int> array;
		Common::Array<int>::iterator iter;

		// Fill the array with some random data
		array.push_back(17);
		array.push_back(33);
		array.push_back(-11);

		// Iterate over the array and verify that we encounter the elements in
		// the order we expect them to be.

		iter = array.begin();

		TS_ASSERT( *iter == 17 );
		++iter;
		TS_ASSERT( iter != array.end() );

		TS_ASSERT( *iter == 33 );
		++iter;
		TS_ASSERT( iter != array.end() );

		// Also test the postinc
		TS_ASSERT( *iter == -11 );
		iter++;
		TS_ASSERT( iter == array.end() );
	}

	void test_direct_access( void )
	{
		Common::Array<int> array;

		// Fill the array with some random data
		array.push_back(17);
		array.push_back(33);
		array.push_back(-11);

		TS_ASSERT( array[0] == 17 );
		TS_ASSERT( array[1] == 33 );
		TS_ASSERT( array[2] == -11 );
	}

	void test_insert_at( void )
	{
		Common::Array<int> array;

		// First of all some data
		array.push_back(-12);
		array.push_back(17);
		array.push_back(25);
		array.push_back(-11);

		// Insert some data
		array.insert_at(2, 33);

		TS_ASSERT( array[0] == -12 );
		TS_ASSERT( array[1] == 17 );
		TS_ASSERT( array[2] == 33 );
		TS_ASSERT( array[3] == 25 );
		TS_ASSERT( array[4] == -11 );
	}

	void test_remove_at( void )
	{
		Common::Array<int> array;

		// First of all some data
		array.push_back(-12);
		array.push_back(17);
		array.push_back(33);
		array.push_back(25);
		array.push_back(-11);

		// Remove some data
		array.remove_at(1);

		TS_ASSERT( array[0] == -12 );
		TS_ASSERT( array[1] == 33 );
		TS_ASSERT( array[2] == 25 );
		TS_ASSERT( array[3] == -11 );
	}

	void test_push_back( void )
	{
		Common::Array<int> array1, array2;

		// Some data for both
		array1.push_back(-3);
		array1.push_back(5);
		array1.push_back(9);

		array2.push_back(3);
		array2.push_back(-2);
		array2.push_back(-131);

		array1.push_back(array2);

		TS_ASSERT( array1[0] == -3 );
		TS_ASSERT( array1[1] == 5 );
		TS_ASSERT( array1[2] == 9 );
		TS_ASSERT( array1[3] == 3 );
		TS_ASSERT( array1[4] == -2 );
		TS_ASSERT( array1[5] == -131 );
	}

	void test_copy_constructor( void )
	{
		Common::Array<int> array1;

		// Some data for both
		array1.push_back(-3);
		array1.push_back(5);
		array1.push_back(9);

		Common::Array<int> array2(array1);

		TS_ASSERT( array2[0] == -3 );
		TS_ASSERT( array2[1] == 5 );
		TS_ASSERT( array2[2] == 9 );
	}
};