-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_strategies.py
77 lines (58 loc) · 2.25 KB
/
test_strategies.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
import pytest
from tests import clone
from data import TurnContext
from data import UP, DOWN, LEFT, RIGHT
from strategies import (
choose_strategy,
RandomStrategy,
CornerStrategy,
PreferFoodStrategy,
AvoidFoodStrategy,
)
@pytest.fixture
def sample_snake():
return {
"id": "snake-id-string",
"name": "Sneky Snek",
"health": 41,
"body": [{"x": 1, "y": 3,}],
}
@pytest.fixture
def directions():
return [UP, DOWN, LEFT, RIGHT]
def test_choose_strategy_force_strategy(sample_snake):
result = choose_strategy(
TurnContext(0, 0, 0, [], sample_snake, [sample_snake], []),
{"FORCE_STRATEGY": "RANDOM"},
)
assert isinstance(result, RandomStrategy)
def test_choose_strategy_corner_strategy(sample_snake):
result = choose_strategy(TurnContext(0, 0, 0, [], sample_snake, [sample_snake], []))
assert isinstance(result, CornerStrategy)
def test_choose_strategy_prefer_food_strategy(sample_snake):
snake = clone(sample_snake, health=40)
result = choose_strategy(TurnContext(0, 0, 0, [], snake, [snake], []))
assert isinstance(result, PreferFoodStrategy)
def test_choose_strategy_avoid_food_strategy(sample_snake):
snake = clone(sample_snake, health=41, body=sample_snake["body"] * 4)
result = choose_strategy(TurnContext(0, 0, 0, [], snake, [snake], []))
assert isinstance(result, AvoidFoodStrategy)
def test_corner_strategy(sample_snake, directions):
strategy = CornerStrategy(
TurnContext(0, 0, 0, [], sample_snake, [sample_snake], [])
)
direction = strategy.get_action()
assert isinstance(direction, str)
assert direction in directions
def test_prefer_food_strategy(sample_snake, directions):
snake = clone(sample_snake, health=40)
strategy = PreferFoodStrategy(TurnContext(0, 0, 0, [], snake, [snake], []))
direction = strategy.get_action()
assert isinstance(direction, str)
assert direction in directions
def test_avoid_food_strategy(sample_snake, directions):
snake = clone(sample_snake, health=41, body=sample_snake["body"] * 4)
strategy = AvoidFoodStrategy(TurnContext(0, 0, 0, [], snake, [snake], []))
direction = strategy.get_action()
assert isinstance(direction, str)
assert direction in directions