-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest_functional.py
119 lines (109 loc) · 4.17 KB
/
test_functional.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
import adjudicator
import agent
import constants
import copy
import logging
import numpy as np
import config
def unit_test(test_name,method,input_states,output_states):
print("Starting tests for "+test_name)
for i in range( len(input_states) ):
output = method( input_states[i] )
flag = True
for attribute in output_states[i]:
if attribute in output:
if output_states[i][attribute] != output[attribute]:
flag = False
else:
flag = False
break
if flag:
print("Pass")
else:
print("Fail")
print("Expected Output: "+str(output_states[i]))
print("Received Output: "+str(output))
def test_handle_property():
input_states = [[
2, #player turn; 0
[0,0,1,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], #player properties; 1
[12,9],#player's position; 2
[1300,1380], #player's cash; 3
0, #phase number; 4
{} #phase payload; 5
],
[
2, #player turn; 0
[0,0,1,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], #player properties; 1
[9,9],#player's position; 2
[1300,1380], #player's cash; 3
0, #phase number; 4
{} #phase payload; 5
],
[
2, #player turn; 0
[0,0,1,-1,-1,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], #player properties; 1
[9,9],#player's position; 2
[1300,1380], #player's cash; 3
0, #phase number; 4
{} #phase payload; 5
],
[
2, #player turn; 0
[0,0,1,-1,-1,-2,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], #player properties; 1
[9,9],#player's position; 2
[1300,1380], #player's cash; 3
0, #phase number; 4
{} #phase payload; 5
],
[
2, #player turn; 0
[0,0,1,-1,-1,-2,0,0,0,0,-1,0,0,0,0,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0], #player properties; 1
[15,9],#player's position; 2
[1300,1380], #player's cash; 3
0, #phase number; 4
{} #phase payload; 5
]
]
output_states = [{'phase': 3, 'phase_properties': {'cash': 150, 'source': 'bank'}},
{'phase_properties': {'cash': 8, 'source': 'opponent'}},
{'phase_properties': {'cash': 16, 'source': 'opponent'}},
{'phase_properties': {'cash': 40, 'source': 'opponent'}},
{'phase_properties': {'cash': 50, 'source': 'opponent'}}]
adjud = adjudicator.Adjudicator(agent.Agent,agent.Agent)
unit_test("handle_property method",adjud.handle_property,input_states,output_states)
def test_handle_cards_pre_turn():
input_states = [[
2, #player turn; 0
[0,0,1,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], #player properties; 1
[2,9],#player's position; 2
[1300,1380], #player's cash; 3
0, #phase number; 4
{} #phase payload; 5
],
[
2, #player turn; 0
[0,0,1,0,0,-1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], #player properties; 1
[7,9],#player's position; 2
[1300,1380], #player's cash; 3
0, #phase number; 4
{} #phase payload; 5
]]
print("Starting tests for handle_cards_pre_turn method")
for i in range( len(input_states) ):
current_player = input_states[i][0]%2
current_position = input_states[i][2][current_player]
deck_type = constants.board[current_position]['class']
cards = constants.communityChestCards
if deck_type == 'Chance':
cards = constants.chanceCards
adjud = adjudicator.Adjudicator(agent.Agent,agent.Agent)
for card in cards:
input_modified = copy.deepcopy(input_states[i])
adjud.handle_cards_pre_turn( input_modified ,card,deck_type )
flag = True
print("Card: "+deck_type+" "+str(card['id'])+", Text: "+str(card['content']))
print("State before card effect: "+str(input_states[i]))
print("State after card effect: "+str(input_modified))
test_handle_property()
#test_handle_cards_pre_turn()