add tests on win conditions
This commit is contained in:
parent
1842b2c412
commit
655fde3e2b
@ -385,6 +385,9 @@ class Game:
|
||||
self.someone_won = True
|
||||
self.sio.emit('chat_message', room=self.name, data=f'_won|{p.name}|{p.role.name}')
|
||||
p.notify_self()
|
||||
if hasattr(self.sio, 'is_fake'):
|
||||
print('announces_winners(): Running for tests, you will have to call reset manually!')
|
||||
return
|
||||
for i in range(5):
|
||||
self.sio.emit('chat_message', room=self.name, data=f'_lobby_reset|{5-i}')
|
||||
eventlet.sleep(1)
|
||||
|
@ -1,4 +1,6 @@
|
||||
|
||||
class DummySocket():
|
||||
def emit(self, event, data=None, to=None, room=None, skip_sid=None, namespace=None, callback=None, **kwargs):
|
||||
# print(f'event: {event}, data: {data}, to: {to}, room: {room}')
|
||||
return True
|
||||
is_fake = True
|
115
backend/tests/roles_test.py
Normal file
115
backend/tests/roles_test.py
Normal file
@ -0,0 +1,115 @@
|
||||
from bang.characters import Character
|
||||
from tests.dummy_socket import DummySocket
|
||||
from bang.deck import Deck
|
||||
from bang.game import Game
|
||||
from bang.players import Player, PendingAction
|
||||
from bang.roles import *
|
||||
from bang.cards import *
|
||||
|
||||
# test that a game with 3 player the deputy kills renegade and wins
|
||||
def test_3p_deputy_win():
|
||||
sio = DummySocket()
|
||||
g = Game('test', sio)
|
||||
for i in range(3):
|
||||
p = Player(f'p{i}', f'p{i}', sio)
|
||||
g.add_player(p)
|
||||
g.start_game()
|
||||
for p in g.players:
|
||||
p.available_characters = [Character('test_char', 4)]
|
||||
p.set_character(p.available_characters[0].name)
|
||||
roles = {g.players[i].role.name:i for i in range(len(g.players))}
|
||||
print(roles)
|
||||
assert len(roles) == 3
|
||||
assert isinstance(g.players[g.turn].role, Vice)
|
||||
for i in range(3):
|
||||
g.players[i].lives = 1
|
||||
g.players[i].hand = []
|
||||
g.players[g.turn].draw('')
|
||||
g.players[g.turn].hand = [Bang(0,0)]
|
||||
g.players[g.turn].play_card(0, against=g.players[roles['Rinnegato']].name)
|
||||
assert (hasattr(g.players[g.turn], 'win_status') and g.players[g.turn].win_status)
|
||||
assert not (hasattr(g.players[roles['Rinnegato']], 'win_status') and g.players[roles['Rinnegato']].win_status)
|
||||
assert not (hasattr(g.players[roles['Fuorilegge']], 'win_status') and g.players[roles['Fuorilegge']].win_status)
|
||||
|
||||
# test that a game with 3 player the renegade kills the outlaw and wins
|
||||
def test_3p_renegade_win():
|
||||
sio = DummySocket()
|
||||
g = Game('test', sio)
|
||||
for i in range(3):
|
||||
p = Player(f'p{i}', f'p{i}', sio)
|
||||
g.add_player(p)
|
||||
g.start_game()
|
||||
for p in g.players:
|
||||
p.available_characters = [Character('test_char', 4)]
|
||||
p.set_character(p.available_characters[0].name)
|
||||
roles = {g.players[i].role.name:i for i in range(len(g.players))}
|
||||
print(roles)
|
||||
assert len(roles) == 3
|
||||
assert isinstance(g.players[g.turn].role, Vice)
|
||||
for i in range(3):
|
||||
g.players[i].lives = 1
|
||||
g.players[i].hand = []
|
||||
g.turn = roles['Rinnegato']
|
||||
g.play_turn()
|
||||
g.players[g.turn].draw('')
|
||||
g.players[g.turn].hand = [Bang(0,0)]
|
||||
g.players[g.turn].play_card(0, against=g.players[roles['Fuorilegge']].name)
|
||||
assert (hasattr(g.players[g.turn], 'win_status') and g.players[g.turn].win_status)
|
||||
assert not (hasattr(g.players[roles['Vice']], 'win_status') and g.players[roles['Vice']].win_status)
|
||||
assert not (hasattr(g.players[roles['Fuorilegge']], 'win_status') and g.players[roles['Fuorilegge']].win_status)
|
||||
|
||||
# test that a game with 3 player the outlaw kills the deputy and wins
|
||||
def test_3p_outlaw_win():
|
||||
sio = DummySocket()
|
||||
g = Game('test', sio)
|
||||
for i in range(3):
|
||||
p = Player(f'p{i}', f'p{i}', sio)
|
||||
g.add_player(p)
|
||||
g.start_game()
|
||||
for p in g.players:
|
||||
p.available_characters = [Character('test_char', 4)]
|
||||
p.set_character(p.available_characters[0].name)
|
||||
roles = {g.players[i].role.name:i for i in range(len(g.players))}
|
||||
print(roles)
|
||||
assert len(roles) == 3
|
||||
assert isinstance(g.players[g.turn].role, Vice)
|
||||
for i in range(3):
|
||||
g.players[i].lives = 1
|
||||
g.players[i].hand = []
|
||||
g.turn = roles['Fuorilegge']
|
||||
g.play_turn()
|
||||
g.players[g.turn].draw('')
|
||||
g.players[g.turn].hand = [Bang(0,0)]
|
||||
g.players[g.turn].play_card(0, against=g.players[roles['Vice']].name)
|
||||
assert (hasattr(g.players[g.turn], 'win_status') and g.players[g.turn].win_status)
|
||||
assert not (hasattr(g.players[roles['Vice']], 'win_status') and g.players[roles['Vice']].win_status)
|
||||
assert not (hasattr(g.players[roles['Rinnegato']], 'win_status') and g.players[roles['Rinnegato']].win_status)
|
||||
|
||||
# test that a game with 4 player the outlaw kills the sheriff and win
|
||||
def test_4p_outlaw_win():
|
||||
sio = DummySocket()
|
||||
g = Game('test', sio)
|
||||
for i in range(4):
|
||||
p = Player(f'p{i}', f'p{i}', sio)
|
||||
g.add_player(p)
|
||||
g.start_game()
|
||||
for p in g.players:
|
||||
p.available_characters = [Character('test_char', 4)]
|
||||
p.set_character(p.available_characters[0].name)
|
||||
roles = {g.players[i].role.name:i for i in range(len(g.players))}
|
||||
print(roles)
|
||||
assert len(roles) == 3
|
||||
assert isinstance(g.players[g.turn].role, Sheriff)
|
||||
for i in range(4):
|
||||
g.players[i].lives = 1
|
||||
g.players[i].hand = []
|
||||
g.turn = roles['Fuorilegge']
|
||||
g.play_turn()
|
||||
g.players[g.turn].draw('')
|
||||
g.players[g.turn].hand = [Bang(0,0)]
|
||||
g.players[g.turn].play_card(0, against=g.players[roles['Sceriffo']].name)
|
||||
for i in range(4):
|
||||
if isinstance(g.players[i].role, Outlaw):
|
||||
assert (hasattr(g.players[i], 'win_status') and g.players[i].win_status)
|
||||
else:
|
||||
assert not (hasattr(g.players[i], 'win_status') and g.players[i].win_status)
|
Loading…
Reference in New Issue
Block a user