示例#1
0
class TestOngoingGame(unittest.TestCase):
  def setUp(self):
    self.game = Game()

  def test_is_over(self):
    self.assertFalse(self.game.is_over())

  def test_is_tie(self):
    self.assertFalse(self.game.is_tie())

  def test_is_won(self):
    self.assertFalse(self.game.is_won())

  def test_get_winner(self):
    self.assertIsNone(self.game.get_winner())

  def test_get_available_directions(self):
    expected_directions = [
      DIRECTIONS.west,
      DIRECTIONS.south,
      DIRECTIONS.east
    ]

    self.assertEqual(
      set(self.game.get_available_directions()),
      set(expected_directions)
    )
class TestAdvancingValidMoveToEmptySpace(unittest.TestCase):
  def setUp(self):
    self.game                = Game()
    self.space               = self.game.arena.space
    self.player              = self.game.player1
    self.player2             = self.game.player2
    self.game.current_player = self.player
    self.player.position     = (1, 1)
    self.move                = Move(self.player, DIRECTIONS.south)
    self.new_position        = translated_position(
      self.player.position, DIRECTIONS.south
    )

    self.space[self.new_position] = None

    GameAdvancement(self.game, self.move).do()

  def test_player_position(self):
    self.assertEqual(
      self.player.position, (1, 2)
    )

  def test_player_direction(self):
    self.assertEqual(
      self.player.direction, DIRECTIONS.south
    )

  def test_player_vital_status(self):
    self.assertTrue(self.player.is_alive())

  def test_player2_vital_status(self):
    self.assertTrue(self.player2.is_alive())

  def test_arena_space_ownership(self):
    self.assertEqual(
      self.space.get((1, 1), None), self.player
    )

  def test_game_is_over(self):
    self.assertFalse(self.game.is_over())

  def test_game_is_tie(self):
    self.assertFalse(self.game.is_tie())

  def test_game_is_won(self):
    self.assertFalse(self.game.is_won())

  def test_game_get_winner(self):
    self.assertIsNone(self.game.get_winner())

  def test_current_player(self):
    self.assertTrue(
      self.game.current_player is self.player2
    )

  def test_last_player(self):
    self.assertTrue(
      self.game.last_player is self.player
    )
class TestAdvancingInvalidMove(unittest.TestCase):
  def setUp(self):
    self.game                = Game()
    self.space               = self.game.arena.space
    self.player              = self.game.player1
    self.player2             = self.game.player2
    self.game.current_player = self.player
    self.player.position     = (1, 1)
    self.move                = Move(self.player, DIRECTIONS.south)
    self.new_position        = translated_position(
      self.player.position, DIRECTIONS.south
    )

    # Assume the move reports as invalid
    self.move.is_valid = MagicMock(return_value=False)

    GameAdvancement(self.game, self.move).do()

  def test_player_position(self):
    self.assertEqual(
      self.player.position, (1, 1)
    )

  def test_player_direction(self):
    self.assertEqual(
      self.player.direction, DIRECTIONS.south
    )

  def test_player_vital_status(self):
    self.assertTrue(self.player.is_alive())

  def test_player2_vital_status(self):
    self.assertTrue(self.player2.is_alive())

  def test_arena_space_ownership(self):
    self.assertIsNone(
      self.space.get((1, 1), None)
    )

  def test_game_is_over(self):
    self.assertFalse(self.game.is_over())

  def test_game_is_tie(self):
    self.assertFalse(self.game.is_tie())

  def test_game_is_won(self):
    self.assertFalse(self.game.is_won())

  def test_game_get_winner(self):
    self.assertIsNone(self.game.get_winner())

  def test_current_player(self):
    self.assertTrue(
      self.game.current_player is self.player
    )

  def test_last_player(self):
    self.assertIsNone(self.game.last_player)
示例#4
0
class TestTiedGame(unittest.TestCase):
  def setUp(self):
    self.game = Game()
    self.game.player1.alive = False
    self.game.player2.alive = False

  def test_is_over(self):
    self.assertTrue(self.game.is_over())

  def test_is_tie(self):
    self.assertTrue(self.game.is_tie())

  def test_is_won(self):
    self.assertFalse(self.game.is_won())

  def test_get_winner(self):
    self.assertIsNone(self.game.get_winner())
示例#5
0
class TestWonGame(unittest.TestCase):
  def setUp(self):
    self.game = Game()
    self.game.player1.alive = False

  def test_is_over(self):
    self.assertTrue(self.game.is_over())

  def test_is_tie(self):
    self.assertFalse(self.game.is_tie())

  def test_is_won(self):
    self.assertTrue(self.game.is_won())

  def test_get_winner(self):
    self.assertEqual(
      self.game.get_winner(), self.game.player2
    )