Add a PromotionManager.
[tagua/yd.git] / tests / variants / boardtest.cpp
blob39817266365f2b2238056f7dbc6bfc040f62d727
1 #include "boardtest.h"
3 #include <board.h>
4 #include <piece.h>
5 #include <point.h>
6 #include <color.h>
7 #include <types/chess/knight.h>
8 #include <types/chess/king.h>
10 #include "test_utils.h"
12 using namespace Chess;
14 CPPUNIT_TEST_SUITE_REGISTRATION(BoardTest);
16 void BoardTest::setUp() {
17 m_board = new Board(Point(8,8));
20 void BoardTest::tearDown() {
21 delete m_board;
24 void BoardTest::test_size() {
25 CPPUNIT_ASSERT_EQUAL(8, m_board->size().x);
26 CPPUNIT_ASSERT_EQUAL(8, m_board->size().y);
29 void BoardTest::test_get_null() {
30 Piece x = m_board->get(Point(3, 2));
31 CPPUNIT_ASSERT_EQUAL(Piece(), x);
34 void BoardTest::test_set_get() {
35 Piece piece(White::self(), Knight::self());
36 m_board->set(Point(3, 2), piece);
37 CPPUNIT_ASSERT_EQUAL(piece, m_board->get(Point(3, 2)));
40 void BoardTest::test_valid() {
41 CPPUNIT_ASSERT(!m_board->valid(Point(-1, 3)));
42 CPPUNIT_ASSERT(!m_board->valid(Point(7, -1)));
43 CPPUNIT_ASSERT(!m_board->valid(Point(8, 0)));
44 CPPUNIT_ASSERT(!m_board->valid(Point(8, 7)));
46 CPPUNIT_ASSERT(m_board->valid(Point(1, 3)));
47 CPPUNIT_ASSERT(m_board->valid(Point(4, 7)));
48 CPPUNIT_ASSERT(m_board->valid(Point(0, 0)));
49 CPPUNIT_ASSERT(m_board->valid(Point(7, 7)));
52 void BoardTest::test_set_invalid() {
53 m_board->set(Point(8, 2), Piece(Black::self(), Knight::self()));
54 CPPUNIT_ASSERT_EQUAL(Piece(), m_board->get(Point(8, 2)));
57 void BoardTest::test_compare() {
58 Piece p1(White::self(), King::self());
59 Piece p2(Black::self(), Knight::self());
61 m_board->set(Point(3, 4), p1);
62 m_board->set(Point(5, 1), p2);
64 Board other(m_board->size());
65 other.set(Point(3, 4), p1);
67 CPPUNIT_ASSERT(!other.equals(m_board));
69 other.set(Point(5, 1), p2);
71 CPPUNIT_ASSERT(other.equals(m_board));
74 void BoardTest::test_clone() {
75 Piece p1(White::self(), King::self());
76 Piece p2(Black::self(), Knight::self());
78 m_board->set(Point(3, 4), p1);
80 Board other(*m_board);
82 CPPUNIT_ASSERT_EQUAL(p1, other.get(Point(3, 4)));
84 m_board->set(Point(3, 5), p2);
86 CPPUNIT_ASSERT_EQUAL(Piece(), other.get(Point(3, 5)));
89 void BoardTest::test_pathinfo_h() {
90 PathInfo path = m_board->path(Point(3, 4), Point(6, 4));
91 CPPUNIT_ASSERT(path.direction() == PathInfo::Horizontal);
92 CPPUNIT_ASSERT(path.parallel());
95 void BoardTest::test_pathinfo_v() {
96 PathInfo path = m_board->path(Point(7, 2), Point(7, 4));
97 CPPUNIT_ASSERT(path.direction() == PathInfo::Vertical);
98 CPPUNIT_ASSERT(path.parallel());
101 void BoardTest::test_pathinfo_d() {
102 PathInfo path = m_board->path(Point(3, 3), Point(5, 5));
103 CPPUNIT_ASSERT(path.diagonal());
105 path = m_board->path(Point(2, 7), Point(5, 4));
106 CPPUNIT_ASSERT(path.diagonal());
109 void BoardTest::test_pathinfo_invalid() {
110 PathInfo path = m_board->path(Point(-1, 3), Point(7, 3));
111 CPPUNIT_ASSERT(!path.valid());
113 path = m_board->path(Point(3, 3), Point(5, 4));
114 CPPUNIT_ASSERT(!path.valid());
117 void BoardTest::test_pathinfo_obstacles() {
118 Piece p1(White::self(), King::self());
119 Piece p2(Black::self(), Knight::self());
121 PathInfo path = m_board->path(Point(1, 1), Point(4, 4));
122 CPPUNIT_ASSERT(path.clear());
124 m_board->set(Point(2, 2), p1);
125 path = m_board->path(Point(1, 1), Point(4, 4));
126 CPPUNIT_ASSERT(!path.clear());
127 CPPUNIT_ASSERT_EQUAL(1, path.numObstacles());
129 m_board->set(Point(6, 2), p2);
130 path = m_board->path(Point(0, 2), Point(5, 2));
131 CPPUNIT_ASSERT_EQUAL(1, path.numObstacles());
133 path = m_board->path(Point(0, 2), Point(6, 2));
134 CPPUNIT_ASSERT_EQUAL(1, path.numObstacles());
136 path = m_board->path(Point(0, 2), Point(7, 2));
137 CPPUNIT_ASSERT_EQUAL(2, path.numObstacles());
139 path = m_board->path(Point(2, 2), Point(6, 2));
140 CPPUNIT_ASSERT(path.clear());
143 void BoardTest::test_find() {
144 Piece p1(Black::self(), King::self());
145 Piece p2(Black::self(), Knight::self());
146 Piece p3(White::self(), King::self());
148 m_board->set(Point(3, 4), p1);
149 m_board->set(Point(5, 6), p2);
150 m_board->set(Point(7, 7), p2);
152 CPPUNIT_ASSERT(m_board->find(p3) == Point::invalid());
153 CPPUNIT_ASSERT(m_board->find(p2) == Point(5, 6));
154 CPPUNIT_ASSERT(m_board->find(p1) == Point(3, 4));