X-Git-Url: https://git.ctpug.org.za/?a=blobdiff_plain;f=naja%2Ftests%2Ftest_player.py;h=b1457c8876d3ad28c85fe118b861e01840f2a9aa;hb=3e9c783ef3e6a7ad83233270f513dcdbb22009df;hp=2e17379213db3d9e4a8f5f6d0603c199ddf88eb8;hpb=266021313a1501c86c11c803851c2b4bb50a8c00;p=naja.git diff --git a/naja/tests/test_player.py b/naja/tests/test_player.py index 2e17379..b1457c8 100644 --- a/naja/tests/test_player.py +++ b/naja/tests/test_player.py @@ -2,6 +2,7 @@ from unittest import TestCase from naja.constants import BITS, MOVES from naja.player import PlayerBits, Player +from naja.gameboard import GameBoard class TestPlayerBits(TestCase): @@ -85,10 +86,40 @@ class TestPlayerBits(TestCase): bits.toggle_bits([BITS.NORTH, BITS.BLUE, BITS.MSB]) self.assertEqual(bits._bits, 0x92) + def test_shift_bits_left(self): + bits = PlayerBits(0x03) + self.assertEqual(bits._bits, 0x03) + bits.shift_bits_left(1) + self.assertEqual(bits._bits, 0x06) + bits.shift_bits_left(6) + self.assertEqual(bits._bits, 0x81) + + def test_shift_bits_right(self): + bits = PlayerBits(0x06) + self.assertEqual(bits._bits, 0x06) + bits.shift_bits_right(1) + self.assertEqual(bits._bits, 0x03) + bits.shift_bits_right(1) + self.assertEqual(bits._bits, 0x81) + class TestPlayer(TestCase): + + def setUp(self): + self.board = GameBoard.new_game({'cards': [ + {'card_name': 'card1', 'actions': [ + { + 'action_class': 'LoseHealthOrMSB', + 'required_bits': [], + }, { + 'action_class': 'GainHealth', + 'required_bits': [BITS.RED], + }, + ]} + ]}) + def test_new_player(self): - player = Player(0x0f, (0, 1)) + player = Player(0x0f, (0, 1), self.board) self.assertEqual(player.bits.bits, 0x0f) self.assertEqual(player.position, (0, 1)) @@ -119,32 +150,32 @@ class TestPlayer(TestCase): }) def test_legal_moves_all_available(self): - player = Player(0x0f, (2, 2)) + player = Player(0x0f, (2, 2), gameboard=self.board) self.assertEqual( player.legal_moves(), [(2, 2), (2, 1), (2, 3), (3, 2), (1, 2)]) def test_legal_moves_some_unavailable(self): - player = Player(0x0f, (0, 2)) + player = Player(0x0f, (0, 2), gameboard=self.board) player.bits.clear_bit(BITS.NORTH) self.assertEqual(player.legal_moves(), [(0, 2), (0, 3), (1, 2)]) def test_legal_moves_castle(self): - player = Player(0x0f, (1, 3), MOVES.CASTLE) + player = Player(0x0f, (1, 3), MOVES.CASTLE, gameboard=self.board) self.assertEqual(player.legal_moves(), [ (0, 3), (1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (2, 3), (3, 3), (4, 3)]) def test_legal_moves_bishop(self): - player = Player(0x0f, (1, 3), MOVES.BISHOP) + player = Player(0x0f, (1, 3), MOVES.BISHOP, gameboard=self.board) self.assertEqual(player.legal_moves(), [ (0, 2), (0, 4), (1, 3), (2, 2), (2, 4), (3, 1), (4, 0)]) def test_legal_moves_knight(self): - player = Player(0x0f, (1, 3), MOVES.KNIGHT) + player = Player(0x0f, (1, 3), MOVES.KNIGHT, gameboard=self.board) self.assertEqual(player.legal_moves(), [ (0, 1), (1, 3), (2, 1), (3, 2), (3, 4)]) def test_set_position(self): - player = Player(0x0f, (3, 3), MOVES.BISHOP) + player = Player(0x0f, (3, 3), MOVES.BISHOP, gameboard=self.board) player.set_position((4, 4)) self.assertEqual(player.movement_mode, MOVES.ADJACENT)