blob: 40636e8a91d9c96ce7e1ca9d4ad8e460c592d1c7 (
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
|
#include <cxxtest/TestSuite.h>
#include "common/stdafx.h"
#include "common/hashmap.h"
class HashMapTestSuite : public CxxTest::TestSuite
{
public:
void test_empty_clear( void )
{
Common::HashMap<int, int> container;
TS_ASSERT( container.empty() );
container[0] = 17;
container[1] = 33;
TS_ASSERT( !container.empty() );
container.clear();
TS_ASSERT( container.empty() );
}
void test_contains( void )
{
Common::HashMap<int, int> container;
container[0] = 17;
container[1] = 33;
TS_ASSERT( container.contains(0) );
TS_ASSERT( container.contains(1) );
TS_ASSERT( !container.contains(17) );
TS_ASSERT( !container.contains(-1) );
}
void test_add_remove( void )
{
Common::HashMap<int, int> container;
container[0] = 17;
container[1] = 33;
TS_ASSERT( container.contains(1) );
container.erase(1);
TS_ASSERT( !container.contains(1) );
container[1] = 42;
TS_ASSERT( container.contains(1) );
}
void test_lookup( void )
{
Common::HashMap<int, int> container;
container[0] = 17;
container[1] = -1;
container[2] = 45;
container[3] = 12;
container[4] = 96;
TS_ASSERT_EQUALS( container[0], 17 );
TS_ASSERT_EQUALS( container[1], -1 );
TS_ASSERT_EQUALS( container[2], 45 );
TS_ASSERT_EQUALS( container[3], 12 );
TS_ASSERT_EQUALS( container[4], 96 );
}
void test_iterator_begin_end( void )
{
Common::HashMap<int, int> container;
// The container is initially empty ...
TS_ASSERT( container.begin() == container.end() );
// ... then non-empty ...
container[324] = 33;
TS_ASSERT( container.begin() != container.end() );
// ... and again empty.
container.clear();
TS_ASSERT( container.begin() == container.end() );
}
// TODO: Add test cases for iterators, find, ...
};
|