def testRedundancyMultipleOccurence(self): tiles = ['s', 'a', 'f', 'e', None, None, 's', 'a', 'f', None] nodes = self.create_horizontal_nodes(tiles) placements = Placement.placements('safe', nodes[0]) placement = placements[0] self.assertFalse(Collision.safe(placement)) placements = Placement.placements('safe', nodes[6]) placement = placements[0] self.assertTrue(Collision.safe(placement))
def testRedundancy(self): # Run the test again, but without any empty space. tiles = ['s', 'a', 'f', 'e', None, None] nodes = self.create_horizontal_nodes(tiles) placements = Placement.placements('safe', nodes[0]) placement = placements[0] self.assertFalse(Collision.safe(placement)) tiles = ['a', 'b', 's', 'a', 'f', 'e', 't', 'b', 'z', 'x', 'h'] nodes = self.create_horizontal_nodes(tiles) placements = Placement.placements('safe', nodes[2]) placement = placements[0] self.assertEqual(placement.node(0), nodes[2]) self.assertEqual(placement.node(0).letter, 's') self.assertFalse(Collision.safe(placement))
def testHorizontalSafe(self): tiles = [None, 's', None, 'f', None] nodes = self.create_horizontal_nodes(tiles) placements = Placement.placements('safe', nodes[1]) self.assertEqual(len(placements), 2) placement = placements[0] # Test that we have the right start node. self.assertEqual(placement.node(0), nodes[1]) # Make sure that there is no collision. self.assertTrue(Collision.safe(placement)) vertical_placement = placements[1] self.assertEqual(vertical_placement.node(0), nodes[1]) self.assertFalse(Collision.safe(vertical_placement))
def testHorizontalCollision(self): tiles = [None, 's', 'a', 'e', None] nodes = self.create_horizontal_nodes(tiles) placements = Placement.placements('safe', nodes[1]) # We expect the vertical and horizontal placements. placement = placements[0] self.assertEqual(placement.node(0), nodes[1]) self.assertFalse(Collision.safe(placement))
def testVerticalSafe(self): tiles = [None, 's', None, 'f', None] nodes = self.create_vertical_nodes(tiles) placements = Placement.placements('safe', nodes[1]) # There should be two placement objects returned from the previous static # method. # One would attempt to place it to the right, and the other downward. Of # course the downward placement would fall right off the board, and should # not pass the collision safety test. self.assertEqual(len(placements), 2) placement = placements[1] # Test that we have the right start node. self.assertEqual(placement.node(0), nodes[1]) # Make sure that there is no collision. self.assertTrue(Collision.safe(placement)) horizontal_placement = placements[0] self.assertEqual(horizontal_placement.node(0), nodes[1]) self.assertFalse(Collision.safe(horizontal_placement))
def testPreexistingLetters(self): tiles = [None, None, None, 'x', 'z', 's', None, 'f', None] nodes = self.create_vertical_nodes(tiles) placements = Placement.placements('safe', nodes[5]) self.assertEqual(len(placements), 2) placement = placements[1] self.assertTrue(placement, Collision.safe(placement)) # The preexisting letters should contain the lettera 's' and 'f' because # when placing the word 'safe' across from the letter 's' the letter 'f' # would be used as well. letters = Collision.preexisting_letters(placement) self.assertEqual(len(letters), 2) self.assertEqual(letters[0], 's') self.assertEqual(letters[1], 'f')