forked from pycon2018-ya-contest/alice-skill
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_dialog_manager.py
76 lines (47 loc) · 1.93 KB
/
test_dialog_manager.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
# coding: utf-8
from __future__ import unicode_literals
from seabattle import dialog_manager as dm, game as gm
from seabattle import session
import mock
user_id = 'user1'
session_obj = session.get(user_id)
def say(message):
return dm.DialogManager(session_obj).handle_message(message).text
def newgame(opponent):
return dm.MESSAGE_TEMPLATES['newgame'] % {'opponent': opponent}
def shot(shot):
return dm.MESSAGE_TEMPLATES['shot'] % {'shot': shot}
def miss(shot):
return dm.MESSAGE_TEMPLATES['miss'] % {'shot': shot}
def kill():
return dm.MESSAGE_TEMPLATES['kill']
def hit():
return dm.MESSAGE_TEMPLATES['hit']
def defeat():
return dm.MESSAGE_TEMPLATES['defeat']
def opponent(name):
return '%s, ' % name
def test_game_1():
assert say('новая игра. соперник яндекс') == newgame('яндекс')
field = [gm.EMPTY, gm.EMPTY, gm.EMPTY,
gm.SHIP, gm.EMPTY, gm.SHIP,
gm.EMPTY, gm.EMPTY, gm.SHIP]
my_field = [gm.EMPTY, gm.SHIP, gm.EMPTY,
gm.EMPTY, gm.EMPTY, gm.EMPTY,
gm.EMPTY, gm.SHIP, gm.SHIP]
shots = ['1, 1', '1, 2', '2, 3', '3, 3', '1, 3']
game = gm.Game()
game.start_new_game(3, field, [2, 1])
game.do_shot = mock.Mock(side_effect=shots)
game.repeat = mock.Mock(return_value='2, 3')
session_obj['game'] = game
assert say('начинай') == opponent('яндекс') + shot(shots[0])
assert say('мимо. я хожу 2 2') == miss(shots[1])
assert say('мимо. я хожу 3 2') == hit()
assert say('я хожу 3 3') == kill()
assert say('я хожу 2 3') == miss(shots[2])
assert say('я не понял') == opponent('яндекс') + miss('2, 3')
assert say('ты попала') == shot(shots[3])
assert say('корабль утонул') == shot(shots[4])
assert say('мимо. я хожу 1 2') == kill()
assert say('ура победа') == defeat()