forked from andy-lenox/CardGameProject
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplay_area.py
90 lines (72 loc) · 1.68 KB
/
play_area.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
#!/usr/bin/env python
# encoding: utf-8
"""
play_area.py
Created by Andrew Lenox on 2010-10-10.
Copyright (c) 2010 __MyCompanyName__. All rights reserved.
"""
import sys
import os
import unittest
import math
import stack
class play_area:
def __init__(self):
self.p1Stack = stack.stack()
self.p2Stack = stack.stack()
self.stacks = [self.p1Stack, self.p2Stack]
def compare(self):
return math.fabs( self.p1Stack.top() - self.p2Stack.top() )
def clear(self):
self.p1Stack.clear()
self.p2Stack.clear()
def clearP1Pile(self):
discard = []
for x in self.p1Stack:
discard.append(self.p1Stack.pop())
return discard
def clearP2Pile(self):
discard = []
for x in self.p2Stack:
discard.append(self.p2Stack)
return discard
#untested
def clearPlayArea(self):
self.clearP1Pile()
self.clearP2Pile()
#untested
def playCard(self, player, card):
self.stacks[player - 1].push(card)
def start(self):
pass
class play_areaTests(unittest.TestCase):
def setUp(self):
self.play = play_area()
def test_setup(self):
p = self.play
p.p1Stack.push(1)
p.p2Stack.push(1)
# 1-1 should be 0
self.assertEqual(0,p.compare())
def test_clear(self):
p = self.play
for x in range(10):
p.p1Stack.push(x)
p.p2Stack.push(x)
self.assertEqual(10, p.p1Stack.size())
self.assertEqual(10, p.p1Stack.size())
p.clear()
self.assertEqual(0, p.p1Stack.size())
self.assertEqual(0, p.p1Stack.size())
def test_clearPiles(self):
p = self.play
for x in range(10):
p.p1Stack.push(x)
p.p2Stack.push(x)
discard = p.clearP1Pile()
index = 0
for card in discard:
assertEqual(index, card)
index += 1
if __name__ == '__main__':
unittest.main()