aboutsummaryrefslogtreecommitdiff
path: root/test/common/array.h
blob: f83c3bf0eab0c2a2aad344f1abe1a2662df8f90f (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
#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 );
	}
};