class PositionTestCase(unittest.TestCase): def setUp(self): self.position = Position(1, 1, Orientation.NORTH) def test_should_be_equal(self): other_position = Position(1, 1, Orientation.NORTH) result = self.position.__eq__(other_position) self.assertTrue(result) def test_should_not_be_equal_when_orientation_is_different(self): other_position = Position(1, 1, Orientation.SOUTH) result = self.position.__eq__(other_position) self.assertFalse(result) def test_should_not_be_equal_when_x_is_different(self): other_position = Position(2, 1, Orientation.NORTH) result = self.position.__eq__(other_position) self.assertFalse(result) def test_should_not_be_equal_when_y_is_different(self): other_position = Position(1, 2, Orientation.NORTH) result = self.position.__eq__(other_position) self.assertFalse(result) def test_should_be_same_when_is_equal(self): other_position = Position(1, 1, Orientation.NORTH) result = self.position.is_same(other_position) self.assertTrue(result) def test_should_be_same_when_orientation_is_different(self): other_position = Position(1, 1, Orientation.EAST) result = self.position.is_same(other_position) self.assertTrue(result) def test_should_not_be_same_when_x_is_different(self): other_position = Position(2, 1, Orientation.NORTH) result = self.position.is_same(other_position) self.assertFalse(result) def test_should_not_be_same_when_y_is_different(self): other_position = Position(1, 2, Orientation.NORTH) result = self.position.is_same(other_position) self.assertFalse(result) def test_should_stringify(self): result = self.position.__str__() self.assertEqual(result, "Position={x=1, y=1, orientation=NORTH}")
class Mower: def __init__(self, x, y, orientation): self.position = Position(x, y, orientation) self.mower_strategy = DefaultMowerStrategy() def __str__(self): return "Mower={" + \ "position=" + self.position.__str__() + \ "}" def should_move(self): return self.mower_strategy.should_move(self.position) def move(self): self.position = self.should_move() return self.position def turn_right(self): self.position = self.mower_strategy.turn_right(self.position) return self.position def turn_left(self): self.position = self.mower_strategy.turn_left(self.position) return self.position