projects
/
naja.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
One. Extra. Line!
[naja.git]
/
naja
/
tests
/
test_actions.py
diff --git
a/naja/tests/test_actions.py
b/naja/tests/test_actions.py
index 891936799d4ab0827bf9aeeb5c6a781e321a3a2b..b233df76adc709c73ac0ea31570f9b20cc40cc84 100644
(file)
--- a/
naja/tests/test_actions.py
+++ b/
naja/tests/test_actions.py
@@
-2,11
+2,15
@@
from unittest import TestCase
from naja.constants import BITS, MOVES
from naja.gameboard import GameBoard, LocationCard
from naja.constants import BITS, MOVES
from naja.gameboard import GameBoard, LocationCard
+from naja.options import parse_args
from naja.player import Player
from naja import actions
class TestActions(TestCase):
from naja.player import Player
from naja import actions
class TestActions(TestCase):
+ def setUp(self):
+ parse_args([])
+
def make_player(self, *bits):
player_bits = 0
for bit in bits:
def make_player(self, *bits):
player_bits = 0
for bit in bits:
@@
-15,13
+19,16
@@
class TestActions(TestCase):
def make_board(self, player_bits=None, locations=None):
if locations is None:
def make_board(self, player_bits=None, locations=None):
if locations is None:
- locations = [{'actions': []}]
- board = GameBoard.new_game(
locations
)
+ locations = [{'
card_name': 'card', '
actions': []}]
+ board = GameBoard.new_game(
{'cards': locations}
)
if player_bits is not None:
board.player.bits.bits = 0
board.player.bits.set_bits(player_bits)
return board
if player_bits is not None:
board.player.bits.bits = 0
board.player.bits.set_bits(player_bits)
return board
+ def make_location_card(self, bits=(), name='card', actions=()):
+ return LocationCard(name, set(bits), list(actions), None)
+
def assert_player_bits(self, board, *bits):
self.assertEqual(sum(1 << bit for bit in bits), board.player.bits.bits)
def assert_player_bits(self, board, *bits):
self.assertEqual(sum(1 << bit for bit in bits), board.player.bits.bits)
@@
-103,7
+110,7
@@
class TestActions(TestCase):
def test_SetBits(self):
board = self.make_board()
state_before = board.export()
def test_SetBits(self):
board = self.make_board()
state_before = board.export()
- card =
LocationCard(set([BITS.MSB, BITS.NORTH]), [
])
+ card =
self.make_location_card([BITS.MSB, BITS.NORTH
])
actions.SetBits(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(
actions.SetBits(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(
@@
-113,7
+120,7
@@
class TestActions(TestCase):
def test_ToggleBits(self):
board = self.make_board(player_bits=[BITS.NORTH])
state_before = board.export()
def test_ToggleBits(self):
board = self.make_board(player_bits=[BITS.NORTH])
state_before = board.export()
- card =
LocationCard(set([BITS.MSB, BITS.NORTH]), [
])
+ card =
self.make_location_card([BITS.MSB, BITS.NORTH
])
actions.ToggleBits(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(board.player.bits.check_bit(BITS.MSB), True)
actions.ToggleBits(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(board.player.bits.check_bit(BITS.MSB), True)
@@
-123,7
+130,7
@@
class TestActions(TestCase):
def test_LoseHealthOrMSBAndSetBits_MSB_clear(self):
board = self.make_board(player_bits=[])
state_before = board.export()
def test_LoseHealthOrMSBAndSetBits_MSB_clear(self):
board = self.make_board(player_bits=[])
state_before = board.export()
- card =
LocationCard(set([BITS.BLUE, BITS.NORTH]), [
])
+ card =
self.make_location_card([BITS.BLUE, BITS.NORTH
])
actions.LoseHealthOrMSBAndSetBits(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(state_after['health'], state_before['health'] - 1)
actions.LoseHealthOrMSBAndSetBits(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(state_after['health'], state_before['health'] - 1)
@@
-135,7
+142,7
@@
class TestActions(TestCase):
def test_LoseHealthOrMSBAndSetBits_MSB_set(self):
board = self.make_board(player_bits=[BITS.MSB])
state_before = board.export()
def test_LoseHealthOrMSBAndSetBits_MSB_set(self):
board = self.make_board(player_bits=[BITS.MSB])
state_before = board.export()
- card =
LocationCard(set([BITS.BLUE, BITS.NORTH]), [
])
+ card =
self.make_location_card([BITS.BLUE, BITS.NORTH
])
actions.LoseHealthOrMSBAndSetBits(set()).perform_action(board, card)
state_after = board.export()
self.assert_player_bits(board, BITS.BLUE, BITS.NORTH)
actions.LoseHealthOrMSBAndSetBits(set()).perform_action(board, card)
state_after = board.export()
self.assert_player_bits(board, BITS.BLUE, BITS.NORTH)
@@
-144,7
+151,7
@@
class TestActions(TestCase):
def test_LoseHealthOrMSBAndSetBits_MSB_set_and_on_card(self):
board = self.make_board(player_bits=[BITS.MSB])
state_before = board.export()
def test_LoseHealthOrMSBAndSetBits_MSB_set_and_on_card(self):
board = self.make_board(player_bits=[BITS.MSB])
state_before = board.export()
- card =
LocationCard(set([BITS.MSB, BITS.NORTH]), [
])
+ card =
self.make_location_card([BITS.MSB, BITS.NORTH
])
actions.LoseHealthOrMSBAndSetBits(set()).perform_action(board, card)
state_after = board.export()
self.assert_player_bits(board, BITS.MSB, BITS.NORTH)
actions.LoseHealthOrMSBAndSetBits(set()).perform_action(board, card)
state_after = board.export()
self.assert_player_bits(board, BITS.MSB, BITS.NORTH)
@@
-166,7
+173,7
@@
class TestActions(TestCase):
board = self.make_board(player_bits=[BITS.NORTH])
board.lose_health()
state_before = board.export()
board = self.make_board(player_bits=[BITS.NORTH])
board.lose_health()
state_before = board.export()
- card =
LocationCard(set([BITS.BLUE, BITS.NORTH]), [
])
+ card =
self.make_location_card([BITS.BLUE, BITS.NORTH
])
actions.GainHealthAndClearBitsOrMSB(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(state_after['health'], state_before['health'] + 1)
actions.GainHealthAndClearBitsOrMSB(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(state_after['health'], state_before['health'] + 1)
@@
-179,7
+186,7
@@
class TestActions(TestCase):
board = self.make_board(player_bits=[BITS.MSB, BITS.NORTH])
board.lose_health()
state_before = board.export()
board = self.make_board(player_bits=[BITS.MSB, BITS.NORTH])
board.lose_health()
state_before = board.export()
- card =
LocationCard(set([BITS.BLUE, BITS.NORTH]), [
])
+ card =
self.make_location_card([BITS.BLUE, BITS.NORTH
])
actions.GainHealthAndClearBitsOrMSB(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(state_after['health'], state_before['health'] + 1)
actions.GainHealthAndClearBitsOrMSB(set()).perform_action(board, card)
state_after = board.export()
self.assertEqual(state_after['health'], state_before['health'] + 1)