def test_evaluate_player_share_fluctuation(self): game = GameState(initial_cash_for_players=500) game.add_player(player_name='Barbara') game.par_company(company_name='IC', price=50) game.buy_shares(player_name='Barbara', company_name='IC', price=50, quantity=1) self.assertEqual(500, game.evaluate_player('Barbara')) game.set_company_price(company_name='IC', new_price=0) self.assertEqual(450, game.evaluate_player('Barbara'))
def test_evaluate_player_multiple_shares(self): game = GameState(initial_cash_for_players=200) game.add_player(player_name='Dwight') self.assertEqual(200, game.evaluate_player('Dwight')) game.par_company(company_name='PRR', price=50) game.par_company(company_name='B&O', price=100) game.buy_shares(player_name='Dwight', company_name='PRR', price=50, quantity=2) game.buy_shares(player_name='Dwight', company_name='B&O', price=100, quantity=1) self.assertEqual(200, game.evaluate_player('Dwight'))
class Controller: def __init__(self, data: str = None): self.state = GameState() self.matchers = SentenceMatcherFabric(self).get_all() self.data = data def notify(self, match: Match): if match.action == 'add_player': self.state.add_player(match.results['player']) if match.action == 'stock_round': self.state.set_stock_round(match.results['stock_round']) self.state.store_valuation() if match.action == 'operation_round': self.state.set_operation_round(match.results['operation_round']) self.state.store_valuation() if match.action == 'par': self.state.par_company(match.results['corporation'], int(match.results['value'])) if match.action == 'buy_shares': self.state.buy_shares(match.results['player'], match.results['corporation'], int(match.results['value']), int(match.results['shares']) / 10) if match.action == 'sell_shares': self.state.sell_shares(match.results['player'], match.results['corporation'], int(match.results['value']), int(match.results['number_of_shares'])) if match.action == 'corporation_share_price_change': self.state.set_company_price(match.results['corporation'], int(match.results['value'])) if match.action == 'player_receives': self.state.player_receives(match.results['player'], int(match.results['value'])) if match.action == 'player_buys_private': self.state.player_receives(match.results['player'], int(match.results['value']) * -1) if match.action == 'player_collects': self.state.player_receives(match.results['player'], int(match.results['value'])) def run(self): if self.data is None: raise ValueError('No data to calculate') for sentence in self.data: for matcher in self.matchers: matcher.match(sentence)
def test_evaluate_player(self): game = GameState(initial_cash_for_players=400) game.add_player(player_name='Cake') self.assertEqual(400, game.evaluate_player('Cake')) game.par_company(company_name='NYC', price=50) game.buy_shares(player_name='Cake', company_name='NYC', price=50, quantity=2) self.assertEqual(400, game.evaluate_player('Cake')) game.set_company_price(company_name='NYC', new_price=100) self.assertEqual(500, game.evaluate_player('Cake')) game.sell_shares(player_name='Cake', company_name='NYC', price=200, quantity=1) self.assertEqual(600, game.evaluate_player('Cake'))
def test_store_valuation(self): game = GameState(initial_cash_for_players=100) game.add_player(player_name='John') game.add_player(player_name='Paul') game.store_valuation() self.assertEqual(100, game.players['John'].valuation['Start']) self.assertEqual(100, game.players['Paul'].valuation['Start']) game.game_round = 'OR1.1' game.par_company(company_name='NYC', price=50) game.buy_shares(player_name='John', company_name='NYC', price=50, quantity=2) game.set_company_price(company_name='NYC', new_price=500) game.players['Paul'].cash = 10 game.store_valuation() self.assertEqual(1000, game.players['John'].valuation['OR1.1']) self.assertEqual(10, game.players['Paul'].valuation['OR1.1'])