<commit_before>"""Tests for the main tournament class."""

import unittest
import axelrod
import logging


class TestTournament(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.game = axelrod.Game()
        cls.players = [axelrod.Defector(), axelrod.Defector(), axelrod.Defector()]
        cls.test_name = 'test'

    def test_init(self):
        tournament = axelrod.Tournament(name=self.test_name, players=self.players, processes=4)
        self.assertEqual([str(s) for s in tournament.players], ['Defector', 'Defector', 'Defector'])
        self.assertEqual(tournament.game.score(('C', 'C')), (3, 3))
        self.assertEqual(tournament.turns, 200)
        self.assertEqual(tournament.repetitions, 10)
        self.assertEqual(tournament.name, 'test')
        self.assertEqual(tournament._processes, 4)
        self.assertFalse(tournament.prebuilt_cache)
        self.assertIsInstance(tournament._logger, logging.Logger)
        self.assertIsInstance(tournament.result_set, axelrod.ResultSet)
        self.assertEqual(tournament.deterministic_cache, {})
        anonymous_tournament = axelrod.Tournament(players=self.players)
        self.assertEqual(anonymous_tournament.name, 'axelrod')

    def test_tournament(self):
        """Test tournament."""

        outcome = [('Cooperator', [1800, 1800, 1800, 1800, 1800]),
                   ('Defector', [1612, 1612, 1612, 1612, 1612]),
                   ('Go By Majority', [1999, 1999, 1999, 1999, 1999]),
                   ('Grudger', [1999, 1999, 1999, 1999, 1999]),
                   ('Tit For Tat', [1999, 1999, 1999, 1999, 1999])]

        outcome.sort()

        P1 = axelrod.Cooperator()
        P2 = axelrod.TitForTat()
        P3 = axelrod.Defector()
        P4 = axelrod.Grudger()
        P5 = axelrod.GoByMajority()
        tournament = axelrod.Tournament(name='test', players=[P1, P2, P3, P4, P5], game=self.game, turns=200, repetitions=5)
        names = [str(p) for p in tournament.players]
        results = tournament.play().results
        scores = [[sum([r[i] for ir,r in enumerate(res) if ir != ires]) for i in range(5)] for ires,res in enumerate(results)]<commit_msg>adds noise to tournament init test<commit_after>"""Tests for the main tournament class."""

import unittest
import axelrod
import logging


class TestTournament(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.game = axelrod.Game()
        cls.players = [axelrod.Defector(), axelrod.Defector(), axelrod.Defector()]
        cls.test_name = 'test'

    def test_init(self):
        tournament = axelrod.Tournament(name=self.test_name, players=self.players, processes=4, noise=0.2)
        self.assertEqual([str(s) for s in tournament.players], ['Defector', 'Defector', 'Defector'])
        self.assertEqual(tournament.game.score(('C', 'C')), (3, 3))
        self.assertEqual(tournament.turns, 200)
        self.assertEqual(tournament.repetitions, 10)
        self.assertEqual(tournament.name, 'test')
        self.assertEqual(tournament._processes, 4)
        self.assertFalse(tournament.prebuilt_cache)
        self.assertIsInstance(tournament._logger, logging.Logger)
        self.assertIsInstance(tournament.result_set, axelrod.ResultSet)
        self.assertEqual(tournament.deterministic_cache, {})
        self.assertEqual(tournament.noise, 0.2)
        anonymous_tournament = axelrod.Tournament(players=self.players)
        self.assertEqual(anonymous_tournament.name, 'axelrod')

    def test_tournament(self):
        """Test tournament."""

        outcome = [('Cooperator', [1800, 1800, 1800, 1800, 1800]),
                   ('Defector', [1612, 1612, 1612, 1612, 1612]),
                   ('Go By Majority', [1999, 1999, 1999, 1999, 1999]),
                   ('Grudger', [1999, 1999, 1999, 1999, 1999]),
                   ('Tit For Tat', [1999, 1999, 1999, 1999, 1999])]

        outcome.sort()

        P1 = axelrod.Cooperator()
        P2 = axelrod.TitForTat()
        P3 = axelrod.Defector()
        P4 = axelrod.Grudger()
        P5 = axelrod.GoByMajority()
        tournament = axelrod.Tournament(name='test', players=[P1, P2, P3, P4, P5], game=self.game, turns=200, repetitions=5)
        names = [str(p) for p in tournament.players]
        results = tournament.play().results
        scores = [[sum([r[i] for ir,r in enumerate(res) if ir != ires]) for i in range(5)] for ires,res in enumerate(results)]
{'fraction_non_alphanumeric': 0.13790760869565216, 'fraction_numerical': 0.057065217391304345, 'mean_word_length': 3.0264357338195076, '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': '1188174', 'n_tokens_mistral': 1635, 'n_tokens_neox': 1393, 'n_words': 299}