3 #include "hlvariant/pool.h"
4 #include "hlvariant/poolcollection.h"
5 #include "hlvariant/chess/piece.h"
7 CPPUNIT_TEST_SUITE_REGISTRATION(PoolTest
);
9 void PoolTest::setUp() {
10 m_pools
= new ChessPoolCollection
;
13 void PoolTest::tearDown() {
17 void PoolTest::test_empty_pool() {
18 CPPUNIT_ASSERT(m_pools
->pool(ChessPiece::WHITE
).empty());
20 CPPUNIT_ASSERT_EQUAL(0, m_pools
->pool(ChessPiece::WHITE
).count(ChessPiece::KING
));
23 void PoolTest::test_add() {
24 m_pools
->pool(ChessPiece::WHITE
).add(ChessPiece::KNIGHT
);
25 CPPUNIT_ASSERT_EQUAL(1, m_pools
->pool(ChessPiece::WHITE
).count(ChessPiece::KNIGHT
));
27 m_pools
->pool(ChessPiece::WHITE
).add(ChessPiece::KNIGHT
);
28 CPPUNIT_ASSERT_EQUAL(2, m_pools
->pool(ChessPiece::WHITE
).count(ChessPiece::KNIGHT
));
31 void PoolTest::test_remove() {
32 m_pools
->pool(ChessPiece::WHITE
).add(ChessPiece::ROOK
);
33 m_pools
->pool(ChessPiece::WHITE
).add(ChessPiece::ROOK
);
35 m_pools
->pool(ChessPiece::WHITE
).remove(ChessPiece::ROOK
);
36 CPPUNIT_ASSERT_EQUAL(1, m_pools
->pool(ChessPiece::WHITE
).count(ChessPiece::ROOK
));
39 void PoolTest::test_remove_clear() {
40 m_pools
->pool(ChessPiece::WHITE
).add(ChessPiece::ROOK
);
42 m_pools
->pool(ChessPiece::WHITE
).remove(ChessPiece::ROOK
);
43 CPPUNIT_ASSERT_EQUAL(0, m_pools
->pool(ChessPiece::WHITE
).count(ChessPiece::ROOK
));
44 CPPUNIT_ASSERT(m_pools
->pool(ChessPiece::WHITE
).empty());
47 void PoolTest::test_size() {
48 CPPUNIT_ASSERT_EQUAL(0, m_pools
->pool(ChessPiece::WHITE
).size());
50 m_pools
->pool(ChessPiece::WHITE
).add(ChessPiece::ROOK
);
51 m_pools
->pool(ChessPiece::WHITE
).add(ChessPiece::ROOK
);
52 m_pools
->pool(ChessPiece::WHITE
).add(ChessPiece::KNIGHT
);
53 m_pools
->pool(ChessPiece::WHITE
).add(ChessPiece::KNIGHT
);
54 m_pools
->pool(ChessPiece::WHITE
).add(ChessPiece::KNIGHT
);
55 m_pools
->pool(ChessPiece::WHITE
).add(ChessPiece::BISHOP
);
56 m_pools
->pool(ChessPiece::BLACK
).add(ChessPiece::BISHOP
);
58 CPPUNIT_ASSERT_EQUAL(6, m_pools
->pool(ChessPiece::WHITE
).size());
59 CPPUNIT_ASSERT_EQUAL(1, m_pools
->pool(ChessPiece::BLACK
).size());
62 void PoolTest::test_empty_remove() {
63 m_pools
->pool(ChessPiece::WHITE
).remove(ChessPiece::BISHOP
);
64 CPPUNIT_ASSERT_EQUAL(0, m_pools
->pool(ChessPiece::WHITE
).count(ChessPiece::ROOK
));
65 CPPUNIT_ASSERT(m_pools
->pool(ChessPiece::WHITE
).empty());
68 void PoolTest::test_pool_equality() {
69 CPPUNIT_ASSERT(m_pools
->pool(ChessPiece::WHITE
) != m_pools
->pool(ChessPiece::BLACK
));
70 CPPUNIT_ASSERT(m_pools
->pool(ChessPiece::WHITE
) == m_pools
->pool(ChessPiece::WHITE
));
72 ChessPoolCollection other
;
73 other
.pool(ChessPiece::BLACK
).add(ChessPiece::KING
);
75 CPPUNIT_ASSERT(m_pools
->pool(ChessPiece::BLACK
) != other
.pool(ChessPiece::BLACK
));
77 other
.pool(ChessPiece::BLACK
).remove(ChessPiece::KING
);
79 CPPUNIT_ASSERT(m_pools
->pool(ChessPiece::BLACK
) == other
.pool(ChessPiece::BLACK
));
81 other
.pool(ChessPiece::WHITE
).add(ChessPiece::ROOK
);
82 m_pools
->pool(ChessPiece::WHITE
).add(ChessPiece::ROOK
);
84 CPPUNIT_ASSERT(m_pools
->pool(ChessPiece::WHITE
) == other
.pool(ChessPiece::WHITE
));
87 void PoolTest::test_collection_equality() {
88 CPPUNIT_ASSERT((*m_pools
) == (*m_pools
));
90 ChessPoolCollection other
;
91 other
.pool(ChessPiece::BLACK
).add(ChessPiece::KING
);
93 CPPUNIT_ASSERT((*m_pools
) != other
);
95 other
.pool(ChessPiece::BLACK
).remove(ChessPiece::KING
);
97 CPPUNIT_ASSERT((*m_pools
) == other
);
99 other
.pool(ChessPiece::WHITE
).add(ChessPiece::ROOK
);
100 m_pools
->pool(ChessPiece::WHITE
).add(ChessPiece::ROOK
);
102 CPPUNIT_ASSERT((*m_pools
) == other
);