File: pooltest.cpp

package info (click to toggle)
tagua 1.0~alpha2-15
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 8,028 kB
  • ctags: 7,178
  • sloc: cpp: 26,149; ansic: 13,039; makefile: 182; ruby: 87; sh: 39
file content (104 lines) | stat: -rw-r--r-- 3,535 bytes parent folder | download | duplicates (6)
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
#include "pooltest.h"

#include "hlvariant/pool.h"
#include "hlvariant/poolcollection.h"
#include "hlvariant/chess/piece.h"

CPPUNIT_TEST_SUITE_REGISTRATION(PoolTest);

void PoolTest::setUp() {
  m_pools = new ChessPoolCollection;
}

void PoolTest::tearDown() {
  delete m_pools;
}

void PoolTest::test_empty_pool() {
  CPPUNIT_ASSERT(m_pools->pool(ChessPiece::WHITE).empty());
  
  CPPUNIT_ASSERT_EQUAL(0, m_pools->pool(ChessPiece::WHITE).count(ChessPiece::KING));
}

void PoolTest::test_add() {
  m_pools->pool(ChessPiece::WHITE).add(ChessPiece::KNIGHT);
  CPPUNIT_ASSERT_EQUAL(1, m_pools->pool(ChessPiece::WHITE).count(ChessPiece::KNIGHT));
  
  m_pools->pool(ChessPiece::WHITE).add(ChessPiece::KNIGHT);
  CPPUNIT_ASSERT_EQUAL(2, m_pools->pool(ChessPiece::WHITE).count(ChessPiece::KNIGHT));
}

void PoolTest::test_remove() {
  m_pools->pool(ChessPiece::WHITE).add(ChessPiece::ROOK);
  m_pools->pool(ChessPiece::WHITE).add(ChessPiece::ROOK);
  
  m_pools->pool(ChessPiece::WHITE).remove(ChessPiece::ROOK);
  CPPUNIT_ASSERT_EQUAL(1, m_pools->pool(ChessPiece::WHITE).count(ChessPiece::ROOK));
}

void PoolTest::test_remove_clear() {
  m_pools->pool(ChessPiece::WHITE).add(ChessPiece::ROOK);
  
  m_pools->pool(ChessPiece::WHITE).remove(ChessPiece::ROOK);
  CPPUNIT_ASSERT_EQUAL(0, m_pools->pool(ChessPiece::WHITE).count(ChessPiece::ROOK));
  CPPUNIT_ASSERT(m_pools->pool(ChessPiece::WHITE).empty());
}

void PoolTest::test_size() {
  CPPUNIT_ASSERT_EQUAL(0, m_pools->pool(ChessPiece::WHITE).size());
  
  m_pools->pool(ChessPiece::WHITE).add(ChessPiece::ROOK);
  m_pools->pool(ChessPiece::WHITE).add(ChessPiece::ROOK);
  m_pools->pool(ChessPiece::WHITE).add(ChessPiece::KNIGHT);
  m_pools->pool(ChessPiece::WHITE).add(ChessPiece::KNIGHT);
  m_pools->pool(ChessPiece::WHITE).add(ChessPiece::KNIGHT);
  m_pools->pool(ChessPiece::WHITE).add(ChessPiece::BISHOP);
  m_pools->pool(ChessPiece::BLACK).add(ChessPiece::BISHOP);
  
  CPPUNIT_ASSERT_EQUAL(6, m_pools->pool(ChessPiece::WHITE).size());
  CPPUNIT_ASSERT_EQUAL(1, m_pools->pool(ChessPiece::BLACK).size());
}

void PoolTest::test_empty_remove() {
  m_pools->pool(ChessPiece::WHITE).remove(ChessPiece::BISHOP);
  CPPUNIT_ASSERT_EQUAL(0, m_pools->pool(ChessPiece::WHITE).count(ChessPiece::ROOK));
  CPPUNIT_ASSERT(m_pools->pool(ChessPiece::WHITE).empty());
}

void PoolTest::test_pool_equality() {
  CPPUNIT_ASSERT(m_pools->pool(ChessPiece::WHITE) != m_pools->pool(ChessPiece::BLACK));
  CPPUNIT_ASSERT(m_pools->pool(ChessPiece::WHITE) == m_pools->pool(ChessPiece::WHITE));
  
  ChessPoolCollection other;
  other.pool(ChessPiece::BLACK).add(ChessPiece::KING);
  
  CPPUNIT_ASSERT(m_pools->pool(ChessPiece::BLACK) != other.pool(ChessPiece::BLACK));
  
  other.pool(ChessPiece::BLACK).remove(ChessPiece::KING);
  
  CPPUNIT_ASSERT(m_pools->pool(ChessPiece::BLACK) == other.pool(ChessPiece::BLACK));
  
  other.pool(ChessPiece::WHITE).add(ChessPiece::ROOK);
  m_pools->pool(ChessPiece::WHITE).add(ChessPiece::ROOK);
  
  CPPUNIT_ASSERT(m_pools->pool(ChessPiece::WHITE) == other.pool(ChessPiece::WHITE));
}

void PoolTest::test_collection_equality() {
  CPPUNIT_ASSERT((*m_pools) == (*m_pools));
  
  ChessPoolCollection other;
  other.pool(ChessPiece::BLACK).add(ChessPiece::KING);
  
  CPPUNIT_ASSERT((*m_pools) != other);
  
  other.pool(ChessPiece::BLACK).remove(ChessPiece::KING);
  
  CPPUNIT_ASSERT((*m_pools) == other);
  
  other.pool(ChessPiece::WHITE).add(ChessPiece::ROOK);
  m_pools->pool(ChessPiece::WHITE).add(ChessPiece::ROOK);
  
  CPPUNIT_ASSERT((*m_pools) == other);
}