forked from skrubly/rajbots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_raj.py
93 lines (75 loc) · 2.62 KB
/
test_raj.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""
Unit tests for Raj
"""
from collections import defaultdict
from operator import attrgetter
from raj import Player, Board
from robots.rand_bot import RandBot
import unittest
def debug(text):
try:
if DEBUG:
print(text)
except:
pass
class TestPlayer(unittest.TestCase):
def setUp(self):
self.names = ['Alice', 'Bob']
def test_create(self):
self.players = [Player(x) for x in self.names]
debug((self.players, self.names))
self.assertEquals(self.names, [x.name for x in self.players])
def test_held_cards(self):
self.player = Player('Carl')
debug(self.player.held_cards)
self.assertEquals(self.player.held_cards, range(1, 16))
def test_played_cards(self):
self.player = Player('Dudley')
self.player.cards.pop()
debug(self.player.played_cards)
self.assertEquals(self.player.played_cards, [15])
class TestRobot(unittest.TestCase):
def setUp(self):
self.robot = RandBot('RandBot')
def test_play(self):
choice = self.robot.play_turn()
debug(self.robot.__dict__)
debug(choice)
self.assertEquals(type(choice.number), type(int()))
class TestSorting(unittest.TestCase):
def setUp(self):
self.names = ['Alice', 'Bob', 'Carl']
self.players = [Player(x) for x in self.names]
self.board = Board(self.players)
def test_high_unique(self):
self.pile = []
self.pile.append(self.players[0].select_card(15))
self.pile.append(self.players[1].select_card(15))
self.pile.append(self.players[2].select_card(13))
debug('Highest unique card: %s' % self.board.find_highest(self.pile))
self.assertEqual(self.board.find_highest(self.pile).owner.name, 'Carl')
def test_low_unique(self):
self.pile = []
self.pile.append(self.players[0].select_card(1))
self.pile.append(self.players[1].select_card(1))
self.pile.append(self.players[2].select_card(3))
debug('Lowest unique card: %s' % self.board.find_lowest(self.pile))
self.assertEqual(self.board.find_lowest(self.pile).owner.name, 'Carl')
def test_tied(self):
""" Test for a tie when all cards are the same """
self.pile = []
self.pile.append(self.players[0].select_card(15))
self.pile.append(self.players[1].select_card(15))
self.pile.append(self.players[2].select_card(15))
self.assertEqual(self.board.find_highest(self.pile), None)
class TestPlay(unittest.TestCase):
def setUp(self):
self.names = ['Alice', 'Bob', 'Carl']
self.players = [RandBot(x) for x in self.names]
self.board = Board(self.players)
def test_playthrough(self):
self.board.run()
print self.board.games
if __name__ == '__main__':
DEBUG = False
unittest.main()