Beispiel #1
0
 def test_print_aliases(self):
   mapu = mapuche.mapuche()
   minqlx_fake.call_command('!mapuche_aliases')
   clean_log = [l.replace(' ', '') for l in minqlx_fake.Plugin.messages]
   for alias, data in MULTI_ALIAS_DATA.items():
     self.assertIn('%s:%s(%s)' % (alias, data['mapname'], data['factory']),
                   clean_log)
Beispiel #2
0
 def test_lagparatodos_reset(self, m):
     lpt = lagparatodos.lagparatodos()
     player = PLAYER_ID_MAP[10]
     minqlx_fake.start_game(PLAYER_ID_MAP, [10, 11], [12, 13], 7, 15)
     minqlx_fake.call_command('!lagparatodos remove', player)
     self.assertMessages('LagParaTodos: Rules removed. Back to normal.')
     self.assertSavedConfig(None, m)
Beispiel #3
0
  def test_remove(self):
    mapu = mapuche.mapuche()
    self.assertEqual(MULTI_ALIAS_DATA, mapu.get_aliases())
    minqlx_fake.call_command('!mapuche_remove patio')

    self.assertEqual({
        'asilo': {
            'mapname': 'asylum',
            'factory': 'ad'
        },
        'balcon': {
            'mapname': '13camp',
            'factory': 'ad'
        },
        'herradura': {
            'mapname': 'courtyard',
            'factory': 'ad'
        },
        'lapidas': {
            'mapname': 'railyard',
            'factory': 'ad'
        },
        'playa': {
            'mapname': 'q3wcp16',
            'factory': 'ad'
        },
    }, mapu.get_aliases())
Beispiel #4
0
  def test_oloraculo(self):

    def match_key(team_a, team_b):
      return repr(sorted((sorted(team_a), sorted(team_b))))

    olor = oloraculo.oloraculo()
    minqlx_fake.Plugin.set_players_by_team({
        'red': [PLAYER_ID_MAP[12], PLAYER_ID_MAP[34]],
        'blue': [PLAYER_ID_MAP[56], PLAYER_ID_MAP[78]]
    })
    minqlx_fake.call_command('!oloraculo')

    expected_predictions = [[1.0000, ['john', 'ringo'], ['paul', 'george']],
                            [0.6667, ['john', 'george'], ['paul', 'ringo']],
                            [0.4286, ['john', 'paul'], ['george', 'ringo']]]

    actual_predictions = [l for l in minqlx_fake.Plugin.messages if ' vs ' in l]
    self.assertEqual(len(expected_predictions), len(actual_predictions))

    for index, expected in enumerate(expected_predictions):
      actual = actual_predictions[index]
      parts = actual.replace(' vs ', ':').replace(' ', '').split(':')
      self.assertEqual(expected[0], float(parts[0]))
      self.assertEqual(
          match_key(expected[1], expected[2]),
          match_key(parts[1].split(','), parts[2].split(',')))
Beispiel #5
0
 def test_bet_new_player(self):
     tim = timba.timba()
     # id 666 isn't in data
     minqlx_fake.countdown_game()
     new_player = minqlx_fake.Player(666, '*Cthugha*')
     minqlx_fake.call_command('!timba blue 1000', new_player)
     self.assertEqual({666: make_bet('blue', 1000)}, tim.get_current_bets())
Beispiel #6
0
  def test_oloraculo_move_players(self):
    olor = oloraculo.oloraculo()
    minqlx_fake.Plugin.set_players_by_team({
        'red': [
            PLAYER_ID_MAP[12], PLAYER_ID_MAP[34], PLAYER_ID_MAP[56],
            PLAYER_ID_MAP[78]
        ],
        'blue': [],
    })

    # predictions are:
    #   '1.0000 : john, ringo vs paul, george'
    #   '0.6667 : john, george vs paul, ringo'
    #   '0.4286 : john, paul vs george, ringo'
    def teams():
      return [PLAYER_ID_MAP[i].team for i in [12, 34, 56, 78]]

    # invalid, no change
    minqlx_fake.call_command('!oloraculo 0')
    self.assertEqual(['red', 'red', 'red', 'red'], teams())

    minqlx_fake.call_command('!oloraculo 1')
    self.assertEqual(['red', 'blue', 'blue', 'red'], teams())

    minqlx_fake.call_command('!oloraculo 2')
    self.assertEqual(['red', 'blue', 'red', 'blue'], teams())

    minqlx_fake.call_command('!oloraculo 3')
    self.assertEqual(['red', 'red', 'blue', 'blue'], teams())

    # invalid, no change
    minqlx_fake.call_command('!oloraculo 4')
    self.assertEqual(['red', 'red', 'blue', 'blue'], teams())
Beispiel #7
0
 def test_lagparatodos_no_command(self):
     lpt = lagparatodos.lagparatodos()
     player = PLAYER_ID_MAP[10]
     minqlx_fake.start_game(PLAYER_ID_MAP, [10, 11], [12, 13], 7, 15)
     minqlx_fake.call_command('!lagparatodos', player)
     self.assertEqual(['Format: !lagparatodos <set|remove>'],
                      player.messages)
Beispiel #8
0
    def test_handles_game_start(self):
        tim = timba.timba()
        self.assertEqual({}, tim.get_current_bets())

        minqlx_fake.call_command('!timba blue 1000', PLAYER_ID_MAP[10])
        self.assertEqual({}, tim.get_current_bets())

        minqlx_fake.countdown_game()
        minqlx_fake.call_command('!timba blue 1000', PLAYER_ID_MAP[10])
        minqlx_fake.call_command('!timba red 123', PLAYER_ID_MAP[11])
        expected_bets = {10: make_bet('blue', 1000), 11: make_bet('red', 123)}
        self.assertEqual(expected_bets, tim.get_current_bets())
        minqlx_fake.start_game(PLAYER_ID_MAP, [10, 11], [12, 13], 7, 15)
        TestTimba.fake_time += 1000
        minqlx_fake.frame()
        self.assertInMessages(
            'Betting is now closed. The pot is 1123 credits.')

        # should not be allowed
        minqlx_fake.call_command('!timba red 200', PLAYER_ID_MAP[10])
        self.assertEqual(expected_bets, tim.get_current_bets())
        minqlx_fake.end_game()

        # should not be allowed
        minqlx_fake.call_command('!timba red 200', PLAYER_ID_MAP[10])
        self.assertEqual({}, tim.get_current_bets())
Beispiel #9
0
 def test_bet_no_args(self):
     tim = timba.timba()
     player = PLAYER_ID_MAP[10]
     player.clear_messages()
     minqlx_fake.countdown_game()
     minqlx_fake.call_command('!timba', PLAYER_ID_MAP[10])
     self.assertEqual({}, tim.get_current_bets())
     self.assertEqual(['You have 1000 credits to bet.'], player.messages)
Beispiel #10
0
 def test_bets_all_loser(self):
     tim = timba.timba()
     minqlx_fake.countdown_game()
     minqlx_fake.call_command('!timba red 1000', PLAYER_ID_MAP[10])
     minqlx_fake.call_command('!timba r 200', PLAYER_ID_MAP[11])
     # blue won
     self.run_game([10, 11], [12, 13], 7, 15)
     self.assertEqual({10: 0, 11: 1800}, tim.get_credits())
     self.assertInMessages('Everyone bet on the loser.')
Beispiel #11
0
 def test_bets_not_enought(self):
     tim = timba.timba()
     player = PLAYER_ID_MAP[10]
     player.clear_messages()
     minqlx_fake.countdown_game()
     # 10 only has 1000 credits
     minqlx_fake.call_command('!timba blue 10000', PLAYER_ID_MAP[10])
     self.assertEqual({}, tim.get_current_bets())
     self.assertEqual(['You only have 1000 credits to bet.'],
                      player.messages)
Beispiel #12
0
 def test_bets_all_winner(self):
     tim = timba.timba()
     minqlx_fake.countdown_game()
     minqlx_fake.call_command('!timba red 1000', PLAYER_ID_MAP[10])
     minqlx_fake.call_command('!timba r 200', PLAYER_ID_MAP[11])
     # red won
     self.run_game([10, 11], [12, 13], 17, 15)
     self.assertEqual({10: 1000, 11: 2000}, tim.get_credits())
     self.assertInMessages(
         'When everyone wins, no one wins: everyone bet on the winner.')
Beispiel #13
0
 def test_loads_aliases_invalid_json(self):
   mapu = mapuche.mapuche()
   self.assertEqual({}, mapu.get_aliases())
   # still usable
   minqlx_fake.call_command('!mapuche_set patio duelingkeeps ctf')
   self.assertEqual({
       'patio': {
           'mapname': 'duelingkeeps',
           'factory': 'ctf'
       }
   }, mapu.get_aliases())
Beispiel #14
0
    def test_saves_credits_one_winner(self, m):
        tim = timba.timba()
        self.assertEqual(CREDITS_DATA, tim.get_credits())

        minqlx_fake.countdown_game()
        minqlx_fake.call_command('!timba blue 1000', PLAYER_ID_MAP[10])
        # blue won
        self.run_game([10, 11], [12, 13], 7, 15)

        expected = copy.deepcopy(CREDITS_DATA)
        self.assertSavedJson(expected, m)
Beispiel #15
0
  def test_oloraculo_no_predictions(self):
    olor = oloraculo.oloraculo()
    # no players loaded
    minqlx_fake.call_command('!oloraculo')
    self.assertFalse(
        [l for l in minqlx_fake.Plugin.messages if 'predictions' in l])

    # only 1 player loaded
    minqlx_fake.Plugin.set_players_by_team({'red': [PLAYER_ID_MAP[12]]})
    minqlx_fake.call_command('!oloraculo')
    self.assertFalse(
        [l for l in minqlx_fake.Plugin.messages if 'predictions' in l])
Beispiel #16
0
 def test_lagparatodos_set(self, m):
     lpt = lagparatodos.lagparatodos()
     player = PLAYER_ID_MAP[10]
     minqlx_fake.start_game(PLAYER_ID_MAP, [10, 11], [12, 13], 7, 15)
     minqlx_fake.call_command('!lagparatodos set', player)
     # self.assertMessages(
     #     'LagParaTodos: Rules set. Max ping is 1000ms. Enjoy your lag.')
     self.assertSavedConfig(['1.2.3.7:1000', '1.2.3.5:990', '1.2.3.4:334'],
                            m)
     self.assertInMessages('          zoth-ommog: 1000ms added')
     self.assertInMessages('      shub niggurath:  990ms added')
     self.assertInMessages('             cthulhu:  334ms added')
     self.assertInMessages('Rules set. Enjoy your lag! >:[')
Beispiel #17
0
    def test_saves_credits_multiple_winners(self, m):
        tim = timba.timba()
        minqlx_fake.countdown_game()
        minqlx_fake.call_command('!timba blue 1000', PLAYER_ID_MAP[10])
        minqlx_fake.call_command('!timba r 200', PLAYER_ID_MAP[11])
        minqlx_fake.call_command('!timba b 10', PLAYER_ID_MAP[12])
        minqlx_fake.call_command('!timba 4000 red', PLAYER_ID_MAP[13])

        # blue won. pot is 5210. 10 and 12 won.
        # original credits:
        #   10: 1000
        #   12: 5000 (empty)
        # winning percentages:
        #   10: 1000 / (1000 + 10) == 0.99..
        #   12: 10 / (1000 + 10) == 0.0099..
        # wins:
        #   10: 5210 * 0.99.. == round(5158.415841584158) == 5158
        #   12: 5210 * 0.0099.. == round(51.584158415841586) == 52
        self.run_game([10, 11], [12, 13], 7, 15)
        self.assertEqual(
            {
                10: 5158,  # original - bet + win == (1000 - 1000 + 5158)
                11: 1800,  # original - bet + win == (2000 - 200 + 0)
                12: 5042,  # original - bet + win == (5000 - 10 + 52)
                13: 1000  # original - bet + win == (5000 - 4000 + 0)
            },
            tim.get_credits())

        expected = {'10': 5158, '11': 1800, '12': 5042, '13': 1000}
        self.assertSavedJson(expected, m)
Beispiel #18
0
 def test_set(self):
   expected = {
       'playa': {
           'mapname': 'q3wcp16',
           'factory': 'ad'
       },
       'patio': {
           'mapname': 'duelingkeeps',
           'factory': 'ctf'
       },
   }
   mapu = mapuche.mapuche()
   self.assertEqual(SINGLE_ALIAS_DATA, mapu.get_aliases())
   minqlx_fake.call_command('!mapuche_set patio duelingkeeps ctf')
   self.assertEqual(expected, mapu.get_aliases())
Beispiel #19
0
 def test_change_map(self):
   mapu = mapuche.mapuche()
   self.assertEqual(None, minqlx_fake.Plugin.current_factory)
   self.assertEqual(None, minqlx_fake.Plugin.current_map_name)
   # force factory
   minqlx_fake.call_command('!mapuche patio ad')
   self.assertEqual('ad', minqlx_fake.Plugin.current_factory)
   self.assertEqual(MULTI_ALIAS_DATA['patio']['mapname'],
                    minqlx_fake.Plugin.current_map_name)
   # default factory
   minqlx_fake.call_command('!mapuche patio')
   self.assertEqual(MULTI_ALIAS_DATA['patio']['factory'],
                    minqlx_fake.Plugin.current_factory)
   self.assertEqual(MULTI_ALIAS_DATA['patio']['mapname'],
                    minqlx_fake.Plugin.current_map_name)
Beispiel #20
0
  def test_oloraculo_stats_no_stats(self):
    olor = oloraculo.oloraculo()
    player_names = [PLAYER_ID_MAP[id].name for id in PLAYER_ID_MAP]

    # no players loaded yet
    minqlx_fake.call_command('!oloraculo_stats')
    for player_name in player_names:
      self.assertFalse(player_name in ''.join(minqlx_fake.Plugin.messages))

    minqlx_fake.Plugin.reset_log()

    # players loaded
    for player_id in PLAYER_ID_MAP:
      minqlx_fake.load_player(PLAYER_ID_MAP[player_id])
    minqlx_fake.call_command('!oloraculo_stats')
    for player_name in player_names:
      self.assertTrue(player_name in ''.join(minqlx_fake.Plugin.messages))
Beispiel #21
0
 def test_handles_game_end(self):
     tim = timba.timba()
     minqlx_fake.countdown_game()
     new_player = minqlx_fake.Player(666, '*Cthugha*')
     minqlx_fake.Plugin.players_list.append(new_player)
     minqlx_fake.call_command('!timba blue 1000', PLAYER_ID_MAP[10])
     minqlx_fake.call_command('!timba red 200', PLAYER_ID_MAP[11])
     minqlx_fake.call_command('!timba blue 10', PLAYER_ID_MAP[12])
     minqlx_fake.call_command('!timba red 5000', PLAYER_ID_MAP[13])
     minqlx_fake.call_command('!timba red 4000', new_player)
     # blue won
     self.run_game([10, 11], [12, 13], 7, 15)
     self.assertInMessages('cthulhu :  1000 on blue')
     self.assertInMessages('nyarlathotep :    10 on blue')
     self.assertInMessages('shub niggurath :  -200 on red')
     self.assertInMessages('zoth-ommog : -5000 on red')
     self.assertInMessages('cthugha : -4000 on red')
Beispiel #22
0
    def test_bets_multiple_winners(self):
        tim = timba.timba()
        minqlx_fake.countdown_game()
        minqlx_fake.call_command('!timba blue 100', PLAYER_ID_MAP[10])
        minqlx_fake.call_command('!timba b 25', PLAYER_ID_MAP[11])
        minqlx_fake.call_command('!timba 875 red', PLAYER_ID_MAP[12])

        # blue won. pot is 1000. 10 and 11 won.
        # original credits:
        #   10: 1000
        #   11: 2000
        # winning percentages:
        #   10: 100 / (100 + 25) == 0.8
        #   11: 25 / (100 + 25) == 0.2
        # wins:
        #   10: 1000 * 0.8 == round(800) == 800
        #   12: 1000 * 0.2 == round(200) == 200
        self.run_game([10, 11], [12, 13], 7, 15)
        self.assertEqual(
            {
                10: 1700,  # original - bet + win == (1000 - 100 + 800)
                11: 2175,  # original - bet + win == (2000 - 25 + 200)
                12: 4125  # original - bet + win == (5000 - 875 + 0)
            },
            tim.get_credits())
Beispiel #23
0
 def test_bet_invalid_args(self):
     tim = timba.timba()
     minqlx_fake.countdown_game()
     minqlx_fake.call_command('!timba bblue 1000', PLAYER_ID_MAP[10])
     self.assertEqual({}, tim.get_current_bets())
     minqlx_fake.call_command('!timba blue onemillion', PLAYER_ID_MAP[10])
     self.assertEqual({}, tim.get_current_bets())
     minqlx_fake.call_command('!timba blue one million', PLAYER_ID_MAP[10])
     self.assertEqual({}, tim.get_current_bets())
Beispiel #24
0
 def test_bets_one_winner(self):
     tim = timba.timba()
     minqlx_fake.countdown_game()
     new_player = minqlx_fake.Player(666, '*Cthugha*')
     minqlx_fake.Plugin.players_list.append(new_player)
     minqlx_fake.call_command('!timba blue 1000', PLAYER_ID_MAP[10])
     minqlx_fake.call_command('!timba r 200', PLAYER_ID_MAP[11])
     minqlx_fake.call_command('!timba 4000 red', new_player)
     # blue won. pot is 5200
     self.run_game([10, 11], [12, 13], 7, 15)
     self.assertEqual({10: 5200, 11: 1800, 666: 1000}, tim.get_credits())
Beispiel #25
0
    def test_betting_window(self):
        tim = timba.timba()
        player = PLAYER_ID_MAP[10]
        player.clear_messages()
        minqlx_fake.Plugin.set_players_by_team({
            'red': [PLAYER_ID_MAP[13], PLAYER_ID_MAP[11]],
            'blue': [PLAYER_ID_MAP[12], PLAYER_ID_MAP[10]]
        })

        self.assertEqual({}, tim.get_current_bets())
        minqlx_fake.countdown_game()
        minqlx_fake.call_command('!timba blue 1000', player)
        self.assertEqual({10: make_bet('blue', 1000)}, tim.get_current_bets())
        self.assertEqual(('You bet 1000 credits on team blue. ' +
                          'You have 30 seconds to change your bet.'),
                         player.messages.pop())
        # 10 secs passed, we can still bet
        TestTimba.fake_time += 10
        minqlx_fake.frame()
        minqlx_fake.call_command('!timba red 1000', player)
        self.assertEqual({10: make_bet('red', 1000)}, tim.get_current_bets())
        self.assertEqual(('You bet 1000 credits on team red. ' +
                          'You have 20 seconds to change your bet.'),
                         player.messages.pop())
        # 29 secs passed, can still bet
        TestTimba.fake_time += 19
        minqlx_fake.frame()
        minqlx_fake.call_command('!timba red 100', player)
        self.assertEqual({10: make_bet('red', 100)}, tim.get_current_bets())
        self.assertEqual(('You bet 100 credits on team red. ' +
                          'You have 1 seconds to change your bet.'),
                         player.messages.pop())
        # 30 secs passed, bets closed
        TestTimba.fake_time += 1
        minqlx_fake.frame()
        self.assertInMessages('Betting is now closed. The pot is 100 credits.')
        self.assertEqual(('You bet 100 credits on team red. ' +
                          'You have 900 credits left. Good luck!'),
                         player.messages.pop())
        minqlx_fake.call_command('!timba red 1', player)
        self.assertEqual({10: make_bet('red', 100)}, tim.get_current_bets())
        self.assertEqual(
            'Betting is not allowed now. You have 900 credits to bet.',
            player.messages.pop())
Beispiel #26
0
 def test_handles_game_countdown(self):
     tim = timba.timba()
     player = PLAYER_ID_MAP[10]
     player.clear_messages()
     self.assertEqual({}, tim.get_current_bets())
     # cannot bet until countdown
     minqlx_fake.call_command('!timba blue 1000', player)
     self.assertEqual({}, tim.get_current_bets())
     self.assertEqual(
         ['Betting is not allowed now. You have 1000 credits to bet.'],
         player.messages)
     minqlx_fake.countdown_game()
     self.assertInMessages(
         'Betting is now open: you have 30 seconds to place your bets!')
     minqlx_fake.call_command('!timba blue 1000', player)
     self.assertEqual({10: make_bet('blue', 1000)}, tim.get_current_bets())
     minqlx_fake.call_command('!timba red 200', player)
     self.assertEqual({10: make_bet('red', 200)}, tim.get_current_bets())
     minqlx_fake.call_command('!timba red 0', player)
Beispiel #27
0
    def test_funes(self):
        fun = funes.funes()
        player_names = [PLAYER_ID_MAP[id].name for id in PLAYER_ID_MAP]

        # no players loaded yet
        minqlx_fake.call_command('!funes')
        for player_name in player_names:
            self.assertNotInMessages(player_name)

        # no matches today and no history
        minqlx_fake.Plugin.reset_log()
        minqlx_fake.Plugin.set_players_by_team({
            'red': [PLAYER_ID_MAP[13], PLAYER_ID_MAP[16]],
            'blue': [PLAYER_ID_MAP[12], PLAYER_ID_MAP[10]]
        })
        minqlx_fake.call_command('!funes')
        self.assertInMessages('Since 2018w10: no history with these players.')
        self.assertInMessages('Today: no history with these players.')

        # no matches with this game type (but one with a different one)
        minqlx_fake.Plugin.reset_log()
        minqlx_fake.Plugin.set_players_by_team({
            'red': [PLAYER_ID_MAP[15], PLAYER_ID_MAP[16]],
            'blue': [PLAYER_ID_MAP[10], PLAYER_ID_MAP[12]]
        })
        minqlx_fake.call_command('!funes')
        self.assertInMessages('Since 2018w10: no history with these players.')
        self.assertInMessages('Today: no history with these players.')

        # no matches today, some history
        minqlx_fake.Plugin.reset_log()
        minqlx_fake.Plugin.set_players_by_team({
            'red': [PLAYER_ID_MAP[13], PLAYER_ID_MAP[16], PLAYER_ID_MAP[15]],
            'blue': [PLAYER_ID_MAP[12], PLAYER_ID_MAP[10], PLAYER_ID_MAP[14]]
        })
        minqlx_fake.call_command('!funes')
        msgs = minqlx_fake.Plugin.messages
        self.assertInMessages(
            'mandiok, toro, blues  0  v  3  p-lu-k, renga, coco')
        self.assertInMessages(
            'mandiok, p-lu-k, blues  2  v  0  toro, renga, coco')
        self.assertInMessages(
            'mandiok, toro, renga  1  v  0  p-lu-k, coco, blues')
        self.assertInMessages(
            'mandiok, toro, coco  0  v  1  p-lu-k, renga, blues')
        self.assertInMessages('Today: no history with these players.')

        # both matches today and history
        minqlx_fake.Plugin.reset_log()
        minqlx_fake.Plugin.set_players_by_team({
            'red': [PLAYER_ID_MAP[10], PLAYER_ID_MAP[11], PLAYER_ID_MAP[12]],
            'blue': [PLAYER_ID_MAP[13], PLAYER_ID_MAP[14], PLAYER_ID_MAP[15]]
        })
        minqlx_fake.call_command('!funes')
        msgs = minqlx_fake.Plugin.messages
        self.assertInMessages(
            'mandiok, toro, coco  2  v  1  fundi, p-lu-k, renga')
        self.assertInMessages(
            'mandiok, toro, p-lu-k  1  v  1  fundi, renga, coco')
        self.assertInMessages(
            'mandiok, fundi, toro  1  v  0  p-lu-k, renga, coco')
        self.assertInMessages(
            'mandiok, fundi, toro  5  v  2  p-lu-k, renga, coco')
        self.assertInMessages(
            'mandiok, toro, coco  3  v  1  fundi, p-lu-k, renga')
        self.assertInMessages(
            'mandiok, toro, p-lu-k  1  v  1  fundi, renga, coco')
        self.assertInMessages(
            'mandiok, toro, renga  0  v  1  fundi, p-lu-k, coco')
Beispiel #28
0
 def test_loads_credits_invalid_json(self):
     tim = timba.timba()
     self.assertEqual({}, tim.get_credits())
     # still usable
     minqlx_fake.countdown_game()
     minqlx_fake.call_command('!timba red 1000', PLAYER_ID_MAP[10])