示例#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)
  def setUp(self):
    self.game                = Game()
    self.game.current_player = self.game.player1
    self.game.last_player    = self.game.player2

    self.copy       = GameCopier(self.game).generate()
    self.arena      = self.game.arena
    self.arena_copy = self.copy.arena
示例#5
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())
示例#6
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
    )
  def setUp(self):
    self.game            = Game()
    self.space           = self.game.arena.space
    self.player          = self.game.player1
    self.player2         = self.game.player2
    self.player.position = (1, 1)
    self.move            = Move(self.player, DIRECTIONS.west)
    self.new_position    = translated_position(
      self.player.position, DIRECTIONS.west
    )

    GameAdvancement(self.game, self.move).do()
  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()
class TestGameCopier(unittest.TestCase):
  def setUp(self):
    self.game                = Game()
    self.game.current_player = self.game.player1
    self.game.last_player    = self.game.player2

    self.copy       = GameCopier(self.game).generate()
    self.arena      = self.game.arena
    self.arena_copy = self.copy.arena

  def test_arena_identity(self):
    self.assertFalse(
      self.game.arena is self.copy.arena
    )

  def test_arena_width(self):
    self.assertEqual(
      self.arena_copy.get_width(),  self.arena.get_width()
    )

  def test_arena_length(self):
    self.assertEqual(
      self.arena_copy.get_length(), self.arena.get_length()
    )

  def test_arena_space(self):
    self.assertEqual(
      self.arena_copy.space,  self.arena.space
    )

  def test_player_one(self):
    self.assertEqual(
      self.game.player1, self.copy.player1
    )

  def test_player_one_identity(self):
    self.assertTrue(
      self.game.player1 is not self.copy.player1
    )

  def test_player_two(self):
    self.assertEqual(
      self.game.player2, self.copy.player2
    )

  def test_player_two_identity(self):
    self.assertTrue(
      self.game.player2 is not self.copy.player2
    )

  def test_current_player(self):
    self.assertEqual(
      self.game.current_player, self.copy.current_player
    )

  def test_current_player_identity(self):
    self.assertTrue(
      self.game.current_player is not self.copy.current_player
    )

  def test_next_player(self):
    self.assertEqual(
      self.game.get_next_player(), self.copy.get_next_player()
    )

  def test_next_player_identity(self):
    self.assertTrue(
      self.game.get_next_player() is not self.copy.get_next_player()
    )

  def test_last_player(self):
    self.assertEqual(
      self.game.last_player, self.copy.last_player
    )

  def test_last_player_identity(self):
    self.assertTrue(
      self.game.last_player is not self.copy.last_player
    )
示例#10
0
 def setUp(self):
   self.game = Game()
   self.game.player1.alive = False
   self.game.player2.alive = False
示例#11
0
 def setUp(self):
   self.game = Game()