def test__apply_a_dxdy_translation(self): """ TestBoard.test__apply_a_dxdy_translation """ # (1) .................................................................. h1 = Board() h1.apply_a_dxdy_translation(10,10) h2 = Board() self.assertEqual( h1.compare_after_normalization(h2), True ) self.assertEqual( h2.compare_after_normalization(h1), True ) # (2) .................................................................. h1 = Board(['A',]) h1.set_a_tile( (0,0), player_id='A', height=3) h1.apply_a_dxdy_translation(1,1) h2 = Board(['A',]) h2.set_a_tile( (1,0), player_id='A', height=3) self.assertEqual( h1.compare_after_normalization(h2), True ) self.assertEqual( h2.compare_after_normalization(h1), True ) # (3) .................................................................. h1 = Board(['A', 'B']) h1.set_a_tile( (0,0), player_id='A', height=3) h1.set_a_tile( (1,0), player_id='B', height=2) h1.apply_a_dxdy_translation(1,1) h2 = Board(['A', 'B']) h2.set_a_tile( (1,1), player_id='A', height=3) h2.set_a_tile( (2,2), player_id='B', height=2) self.assertEqual( h1.compare_after_normalization(h2), True ) self.assertEqual( h2.compare_after_normalization(h1), True ) # (4) .................................................................. h1 = Board(['A',]) h1.set_a_tile( (1,0), player_id='A', height=3) h1.apply_a_dxdy_translation(-1,0) h2 = Board(['A',]) h2.set_a_tile( (0,0), player_id='A', height=3) self.assertEqual( h1.compare_after_normalization(h2), True ) self.assertEqual( h2.compare_after_normalization(h1), True ) # (5) .................................................................. h1 = Board(['A',]) h1.set_a_tile( (1,0), player_id='A', height=3) h1.apply_a_dxdy_translation(-1,-1) h2 = Board(['A',]) h2.set_a_tile( (0,-1), player_id='A', height=3) self.assertEqual( h1.compare_after_normalization(h2), True ) self.assertEqual( h2.compare_after_normalization(h1), True ) # (6) .................................................................. h1 = Board(['A', 'B']) h1.set_a_tile( (0,0), player_id='A', height=1) h1.set_a_tile( (1,0), player_id='B', height=2) h1.apply_a_dxdy_translation(0,0) h2 = Board(['A', 'B']) h2.set_a_tile( (0,0), player_id='A', height=1) h2.set_a_tile( (1,0), player_id='B', height=2) self.assertEqual( h1.compare_after_normalization(h2), True ) self.assertEqual( h2.compare_after_normalization(h1), True )
def test__compare_after_normalization(self): """ TestBoard.test__compare_after_normalization test of Board.compare_after_normalization """ # (1) .................................................................. # # empty tiles are equal. # h1 = Board() h2 = Board() self.assertEqual( h1.compare_after_normalization(h2), True ) self.assertEqual( h2.compare_after_normalization(h1), True ) # (2) .................................................................. # # trivial comparison. # h1 = Board(['A',]) h1.set_a_tile( (0,5), player_id='A', height=3 ) h2 = Board() self.assertEqual( h1.compare_after_normalization(h2), False ) self.assertEqual( h2.compare_after_normalization(h1), False ) # (3) .................................................................. # # trivial comparison. # h1 = Board(['A',]) h1.set_a_tile( (0,0), player_id='A', height=9 ) h2 = Board(['A',]) h2.set_a_tile( (0,0), player_id='A', height=9 ) self.assertEqual( h1.compare_after_normalization(h2), True ) self.assertEqual( h2.compare_after_normalization(h1), True ) # (4) .................................................................. # # identity through translation. # h1 = Board(['A',]) h1.set_a_tile( (0,0), player_id='A', height=9 ) h2 = Board(['ABC',]) h2.set_a_tile( (8,5), player_id='ABC', height=9 ) self.assertEqual( h1.compare_after_normalization(h2), True ) self.assertEqual( h2.compare_after_normalization(h1), True ) # (5) .................................................................. # # player's name has no influence on the comparison. # h1 = Board(['A','B']) h1.set_a_tile( (0,0), player_id='A', height=9 ) h1.set_a_tile( (0,1), player_id='B', height=4 ) h2 = Board(['ABC', 'DEF']) h2.set_a_tile( (0,0), player_id='ABC', height=9 ) h2.set_a_tile( (0,1), player_id='DEF', height=4 ) self.assertEqual( h1.compare_after_normalization(h2), True ) self.assertEqual( h2.compare_after_normalization(h1), True ) # (6) .................................................................. # # order in players' id matters. # h1 = Board(['A','B']) h1.set_a_tile( (0,0), player_id='A', height=9 ) h1.set_a_tile( (0,1), player_id='B', height=4 ) h2 = Board(['DEF', 'ABC']) h2.set_a_tile( (0,0), player_id='ABC', height=9 ) h2.set_a_tile( (0,1), player_id='DEF', height=4 ) self.assertEqual( h1.compare_after_normalization(h2), False ) self.assertEqual( h2.compare_after_normalization(h1), False ) # (7) .................................................................. # # identity through rotation. # h1 = Board(['A','B', 'C']) h1.set_a_tile( (0,0), player_id='A', height=1 ) h1.set_a_tile( (1,0), player_id='B', height=2 ) h1.set_a_tile( (2,0), player_id='C', height=3 ) h2 = Board(['A', 'B', 'C']) h2.set_a_tile( (0,2), player_id='C', height=3 ) h2.set_a_tile( (1,1), player_id='B', height=2 ) h2.set_a_tile( (2,2), player_id='A', height=1 ) self.assertEqual( h1.compare_after_normalization(h2), True ) self.assertEqual( h2.compare_after_normalization(h1), True ) # (8) .................................................................. # # heights matter. # h1 = Board(['A',]) h1.set_a_tile( (0,0), player_id='A', height=4 ) h2 = Board(['A',]) h2.set_a_tile( (0,0), player_id='A', height=9 ) self.assertEqual( h1.compare_after_normalization(h2), True ) self.assertEqual( h2.compare_after_normalization(h1), True )