-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_api.py
173 lines (127 loc) · 3.54 KB
/
test_api.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
import requests
import json
import asyncio
import aiohttp
BACKENDURL = "http://127.0.0.1:5000"
def new_game():
response = requests.get(f"{BACKENDURL}/new_game/")
return json.loads(response.text)["game_id"], json.loads(response.text)["player_id"]
def join_game(game_id):
response = requests.get(f"{BACKENDURL}/join_game/{game_id}")
return json.loads(response.text)["player_id"]
def position(game_id, player_id, position):
data = {
"player_id": player_id,
"position" : position,
}
response = requests.post(f"{BACKENDURL}/position/{game_id}", json=data)
return response.status_code
def shot(game_id, player_a_id, coord):
data = {
"player_id": player_a_id,
"x": coord[0],
"y": coord[1],
}
response = requests.post(f"{BACKENDURL}/shot/{game_id}", json=data)
print(response.text)
return response.status_code
def strange_behaivior1():
game_id, player_a_id = new_game()
player_b_id = join_game(game_id)
player_b_id = join_game(game_id)
def strange_behaivior2():
position = [
[[1,2], [1,3], [1,4], [1,5], [1,6]],
[[3,2], [3,3], [3,4], [3,5]],
[[5,2], [5,3], [5,4]],
[[7,2], [7,3], [7,4]],
[[9,2], [9,3]],
]
game_id, player_a_id = new_game()
player_b_id = join_game(game_id)
position(game_id, player_a_id, position)
position(game_id, player_a_id, position)
def position_check():
p = [
[[1,2], [1,3], [1,4], [1,5], [1,6]],
[[3,2], [3,3], [3,4], [3,5]],
[[5,2], [5,3], [5,4]],
[[7,2], [7,3], [7,4]],
[[9,2], [9,3]],
] #correct position
p = [
[["a",2], [1,3], [1,4], [1,5], [1,6]],
[[3,2], [3,3], [3,4], [3,5]],
[[5,2], [5,3], [5,4]],
[[7,2], [7,3], [7,4]],
[[9,2], [9,3]],
] #wrong type
p = [
[[1,2], [1,3], [1,4], [1,5], [1,6]],
[[2,2], [2,3], [2,4], [2,5]],
[[3,2], [3,3], [3,4]],
[[4,2], [4,3], [4,4]],
[[5,2], [5,3]],
] # errror ships touch each other
p = [
[[1,2], [1,3], [1,4], [1,5], [1,6]],
[[2,2], [2,3], [2,4], [2,5]],
[[3,2], [3,3], [3,4]],
[[4,2], [4,3], [4,4]],
] # not enough numbers of ships
p = [
[[1,2], [1,3], [1,4], [1,5], [1,6]],
[[3,2], [3,3], [3,4], [3,5]],
[[5,2], [5,3], [5,4]],
[[7,2], [7,3]],
[[9,2], [9,3]],
] # wrong len of ship, not 5, 4, 3, 3, 2
p = [
[[1,2], [1,3], [1,4], [1,5], [1,6]],
[[3,2], [3,3], [3,4], [3,5]],
[[5,2], [5,3], [5,4]],
[[7,2], [7,3], [7,4]],
[[11,2], [11,3]],
] # ship is outside of 10 x 10 field
negative_position = [
[[1,2], [1,3], [1,4], [1,5], [1,6]],
[[3,2], [3,3], [3,4], [3,5]],
[[5,2], [5,3], [5,4]],
[[7,2], [7,3], [7,4]],
[[-2,2], [-2,3]],
] # negative coordinates
p = [
[[1,2], [1,3], [1,5], [1,6], [1,7]],
[[3,2], [3,3], [3,4], [3,5]],
[[5,2], [5,3], [5,4]],
[[7,2], [7,3], [7,4]],
[[9,2], [9,3]],
] #gap inside a ship
p = [
[[1,2], [1,3], [1,4], [1,5], [1,6]],
[[3,2], [3,3], [3,4], [3,5]],
[[5,2], [5,3], [5,4]],
[[7,2], [7,3], [7,4]],
[[7,4], [8,4]],
] #ships overlap
def game1():
p = [
[[1,2], [1,3], [1,4], [1,5], [1,6]],
[[3,2], [3,3], [3,4], [3,5]],
[[5,2], [5,3], [5,4]],
[[7,2], [7,3], [7,4]],
[[9,2], [9,3]],
]
game_id, player_a_id = new_game()
player_b_id = join_game(game_id)
print(f'game_id = {game_id}, player_a = {player_a_id}, player_b = {player_b_id}')
position(game_id, player_a_id, p)
position(game_id, player_b_id, p)
print(shot(game_id, player_b_id, [1,1]))
print(shot(game_id, player_a_id, [9,2]))
input("waiting for first shots, any key to continue")
print(shot(game_id, player_b_id, [1,2]))
print(shot(game_id, player_a_id, [9,3]))
print(shot(game_id, player_b_id, [10,10]))
if __name__ == "__main__":
game1()