11import sys
22import unittest
33
4- from chess .piece import Bishop , King , Knight , Pawn , Piece , Queen , Rook
4+ from chess import piece
5+ from chess import symbols
56
67
78class TestPieceModel (unittest .TestCase ):
89 """Abstract chess model test case"""
910
1011 def setUp (self ) -> None :
11- self .instance = Piece ()
12+ self .instance = piece . Piece ()
1213
1314 def test_default_initializer (self ):
1415 self .assertIs (True , self .instance .is_white )
1516 self .assertTupleEqual ((0 , 0 ), self .instance .position )
1617
1718 def test_initializer (self ):
18- instance = Piece (False , (7 , 6 ))
19+ instance = piece . Piece (False , (7 , 6 ))
1920 self .assertIs (False , instance .is_white )
2021 self .assertTupleEqual ((7 , 6 ), instance .position )
2122
@@ -59,11 +60,15 @@ def test_get_delta(self):
5960
6061class TestKingPiece (unittest .TestCase ):
6162 def setUp (self ) -> None :
62- self .instance = King (True )
63- self .instance .set_position ((5 , 5 ))
63+ self .instance = piece .King (position = (5 , 5 ))
6464
65- def test_str (self ):
66- self .assertEqual ("white king at (5, 5)" , str (self .instance ))
65+ def test_str_white (self ):
66+ self .instance .is_white = True
67+ self .assertEqual (symbols .WHITE_KING , str (self .instance ))
68+
69+ def test_str_black (self ):
70+ self .instance .is_white = False
71+ self .assertEqual (symbols .BLACK_KING , str (self .instance ))
6772
6873 def test_can_move (self ):
6974 positions = ((5 , 6 ), (6 , 6 ), (6 , 5 ), (6 , 4 ),
@@ -82,11 +87,15 @@ def test_cannot_move(self):
8287
8388class TestQueenPiece (unittest .TestCase ):
8489 def setUp (self ) -> None :
85- self .instance = Queen (False )
86- self .instance .set_position ((2 , 3 ))
90+ self .instance = piece .Queen (position = (2 , 3 ))
8791
88- def test_str (self ):
89- self .assertEqual ("black queen at (2, 3)" , str (self .instance ))
92+ def test_str_white (self ):
93+ self .instance .is_white = True
94+ self .assertEqual (symbols .WHITE_QUEEN , str (self .instance ))
95+
96+ def test_str_black (self ):
97+ self .instance .is_white = False
98+ self .assertEqual (symbols .BLACK_QUEEN , str (self .instance ))
9099
91100 def test_can_move (self ):
92101 positions = ((2 , 5 ), (4 , 5 ), (7 , 3 ), (3 , 2 ),
@@ -104,11 +113,15 @@ def test_cannot_move(self):
104113
105114class TestBishopPiece (unittest .TestCase ):
106115 def setUp (self ) -> None :
107- self .instance = Bishop (True )
108- self .instance .set_position ((5 , 5 ))
116+ self .instance = piece .Bishop (position = (5 , 5 ))
117+
118+ def test_str_white (self ):
119+ self .instance .is_white = True
120+ self .assertEqual (symbols .WHITE_BISHOP , str (self .instance ))
109121
110- def test_str (self ):
111- self .assertEqual ("white bishop at (5, 5)" , str (self .instance ))
122+ def test_str_black (self ):
123+ self .instance .is_white = False
124+ self .assertEqual (symbols .BLACK_BISHOP , str (self .instance ))
112125
113126 def test_can_move (self ):
114127 positions = ((6 , 6 ), (7 , 3 ), (2 , 2 ), (3 , 7 ))
@@ -125,11 +138,15 @@ def test_cannot_move(self):
125138
126139class TestKnightPiece (unittest .TestCase ):
127140 def setUp (self ) -> None :
128- self .instance = Knight (False )
129- self .instance .set_position ((3 , 4 ))
141+ self .instance = piece .Knight (position = (3 , 4 ))
130142
131- def test_str (self ):
132- self .assertEqual ("black knight at (3, 4)" , str (self .instance ))
143+ def test_str_white (self ):
144+ self .instance .is_white = True
145+ self .assertEqual (symbols .WHITE_KNIGHT , str (self .instance ))
146+
147+ def test_str_black (self ):
148+ self .instance .is_white = False
149+ self .assertEqual (symbols .BLACK_KNIGHT , str (self .instance ))
133150
134151 def test_can_move (self ):
135152 positions = ((4 , 6 ), (5 , 5 ), (5 , 3 ), (4 , 2 ),
@@ -148,11 +165,15 @@ def test_cannot_move(self):
148165
149166class TestRookPiece (unittest .TestCase ):
150167 def setUp (self ) -> None :
151- self .instance = Rook (True )
152- self .instance .set_position ((5 , 2 ))
168+ self .instance = piece .Rook (position = (5 , 2 ))
153169
154- def test_str (self ):
155- self .assertEqual ("white rook at (5, 2)" , str (self .instance ))
170+ def test_str_white (self ):
171+ self .instance .is_white = True
172+ self .assertEqual (symbols .WHITE_ROOK , str (self .instance ))
173+
174+ def test_str_black (self ):
175+ self .instance .is_white = False
176+ self .assertEqual (symbols .BLACK_ROOK , str (self .instance ))
156177
157178 def test_can_move (self ):
158179 positions = ((5 , 4 ), (7 , 2 ), (5 , 1 ), (2 , 2 ))
@@ -169,11 +190,15 @@ def test_cannot_move(self):
169190
170191class TestPawnPiece (unittest .TestCase ):
171192 def setUp (self ) -> None :
172- self .instance = Pawn (False )
173- self .instance .set_position ((6 , 5 ))
193+ self .instance = piece .Pawn (position = (6 , 5 ))
194+
195+ def test_str_white (self ):
196+ self .instance .is_white = True
197+ self .assertEqual (symbols .WHITE_PAWN , str (self .instance ))
174198
175- def test_str (self ):
176- self .assertEqual ("black pawn at (6, 5)" , str (self .instance ))
199+ def test_str_black (self ):
200+ self .instance .is_white = False
201+ self .assertEqual (symbols .BLACK_PAWN , str (self .instance ))
177202
178203 def test_can_move (self ):
179204 self .instance .is_white = False
0 commit comments