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

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

class MapTestSuite : public CxxTest::TestSuite 
{
	public:
	void test_isEmpty_clear( void )
	{
		Common::Map<int, int> map;
		TS_ASSERT( map.isEmpty() );
		map[0] = 17;
		map[1] = 33;
		TS_ASSERT( !map.isEmpty() );
		map.clear();
		TS_ASSERT( map.isEmpty() );
	}
	void test_contains( void )
	{
		Common::Map<int, int> map;
		map[0] = 17;
		map[1] = 33;
		TS_ASSERT( map.contains(0) );
		TS_ASSERT( map.contains(1) );
		TS_ASSERT( !map.contains(17) );
		TS_ASSERT( !map.contains(-1) );
	}

	void test_add_remove( void )
	{
		Common::Map<int, int> map;
		map[0] = 17;
		map[1] = 33;
		TS_ASSERT( map.contains(1) );
		map.remove(1);
		TS_ASSERT( !map.contains(1) );
		map.addKey(1);
		TS_ASSERT( map.contains(1) );
	}

	void test_merge( void )
	{
		Common::Map<int, int> mapA, mapB;
		mapA[0] = 17;
		mapA[1] = 33;
		mapA[2] = 45;
		mapA[3] = 12;

		mapB[1] = -1;
		mapB[4] = 96;
		
		mapA.merge(mapB);

		TS_ASSERT( mapA.contains(1) );
		TS_ASSERT( mapA.contains(4) );

		TS_ASSERT_EQUALS( mapA[0], 17 );
		TS_ASSERT_EQUALS( mapA[1], -1 );
		TS_ASSERT_EQUALS( mapA[2], 45 );
		TS_ASSERT_EQUALS( mapA[3], 12 );
		TS_ASSERT_EQUALS( mapA[4], 96 );
	}
};