<commit_before>from unittest import TestCase
from ..game import AI
from ..competition import Competition
import time

class TestCompetition(TestCase):
    def test_competition_can_add_entry(self):
        """ Test the competition can add an entry. """
        competition = Competition(threaded=False)

        competition.add("ai", AI)

        self.assertEquals(len(competition.entries), 1)

    def test_competition_runs_games(self):
        """ Test the competition runs games when entries are added. """
        competition = Competition(games_to_run=100, threaded=False)

        competition.add("ai1", AI)

        self.assertEquals(competition.entries["ai1"].total_games, 0)

        competition.add("ai2", AI)

        self.assertEquals(competition.entries["ai1"].total_games, 100)
        self.assertEquals(competition.entries["ai2"].total_games, 100)

        competition.add("ai3", AI)

        self.assertEquals(competition.entries["ai1"].total_games, 200)
        self.assertEquals(competition.entries["ai2"].total_games, 200)
        self.assertEquals(competition.entries["ai2"].total_games, 200)

    def test_competition_replaces_entries(self):
        """ Test that reusing an ID replaces the entry. """
        competition = Competition(games_to_run=100, threaded=False)

        competition.add("ai1", AI)

        self.assertEquals(competition.entries["ai1"].total_games, 0)

        competition.add("ai2", AI)

        self.assertEquals(competition.entries["ai1"].total_games, 100)
        self.assertEquals(competition.entries["ai2"].total_games, 100)

        competition.add("ai2", AI)

        self.assertEquals(competition.entries["ai1"].total_games, 100)
        self.assertEquals(competition.entries["ai2"].total_games, 100)

    def test_threaded(self):
        """ Test that the competition still runs threaded. """
        competition = Competition(games_to_run=100)
        competition.add("ai1", AI)
        self.assertEquals(competition.entries["ai1"].total_games, 0)
        competition.add("ai2", AI)
        self.assertLess(competition.entries["ai1"].total_games, 100)
        # Hasn't had time to run all the tests yet
        time.sleep(0.1)
        self.assertEqual(competition.entries["ai1"].total_games, 100)<commit_msg>Added failing test for small bug. Will fix later<commit_after>from unittest import TestCase
from ..game import AI
from ..competition import Competition
import time

class TestCompetition(TestCase):
    def test_competition_can_add_entry(self):
        """ Test the competition can add an entry. """
        competition = Competition(threaded=False)

        competition.add("ai", AI)

        self.assertEquals(len(competition.entries), 1)

    def test_competition_runs_games(self):
        """ Test the competition runs games when entries are added. """
        competition = Competition(games_to_run=100, threaded=False)

        competition.add("ai1", AI)

        self.assertEquals(competition.entries["ai1"].total_games, 0)

        competition.add("ai2", AI)

        self.assertEquals(competition.entries["ai1"].total_games, 100)
        self.assertEquals(competition.entries["ai2"].total_games, 100)

        competition.add("ai3", AI)

        self.assertEquals(competition.entries["ai1"].total_games, 200)
        self.assertEquals(competition.entries["ai2"].total_games, 200)
        self.assertEquals(competition.entries["ai2"].total_games, 200)

    def test_competition_replaces_entries(self):
        """ Test that reusing an ID replaces the entry. """
        competition = Competition(games_to_run=100, threaded=False)

        competition.add("ai1", AI)

        self.assertEquals(competition.entries["ai1"].total_games, 0)

        competition.add("ai2", AI)

        self.assertEquals(competition.entries["ai1"].total_games, 100)
        self.assertEquals(competition.entries["ai2"].total_games, 100)

        competition.add("ai2", AI)

        self.assertEquals(competition.entries["ai1"].total_games, 100)
        self.assertEquals(competition.entries["ai2"].total_games, 100)

    def test_threaded(self):
        """ Test that the competition still runs threaded. """
        competition = Competition(games_to_run=100)
        competition.add("ai1", AI)
        self.assertEquals(competition.entries["ai1"].total_games, 0)
        competition.add("ai2", AI)
        self.assertLess(competition.entries["ai1"].total_games, 100)
        # Hasn't had time to run all the tests yet
        time.sleep(0.1)
        self.assertEqual(competition.entries["ai1"].total_games, 100)

    def test_cant_submit_twice(self):
        """ Test that submitting too quickly won't double games played. """
        competition = Competition(games_to_run=100)
        competition.add("ai1", AI)
        self.assertEquals(competition.entries["ai1"].total_games, 0)
        competition.add("ai2", AI)
        competition.add("ai2", AI)
        time.sleep(0.1)
        self.assertEqual(competition.entries["ai1"].total_games, 100)
{'fraction_non_alphanumeric': 0.12249799839871897, 'fraction_numerical': 0.030824659727782224, 'mean_word_length': 3.4378330373001775, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4018710', 'n_tokens_mistral': 1582, 'n_tokens_neox': 1417, 'n_words': 277}