<commit_before>"""Test for the Thue-Morse strategies."""
import unittest

import axelrod
from .test_player import TestPlayer, TestOpponent
from axelrod.strategies.sequence_player import recursive_thue_morse, SequencePlayer


C, D = axelrod.Actions.C, axelrod.Actions.D

class TestThueMoreGenerator(unittest.TestCase):
    def test_sequence(self):
        expected = [0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0]
        for i, e in enumerate(expected):
            self.assertEqual(recursive_thue_morse(i), e)


class TestSequencePlayer(unittest.TestCase):
    def test_sequence_player(self):
        """Basic test for SequencePlayer."""
        def cooperate_gen():
            yield C
        player = SequencePlayer(cooperate_gen)
        opponent = TestOpponent()
        self.assertEqual(C, player.strategy(opponent))


class TestThueMorse(TestPlayer):

    name = 'ThueMorse'
    player = axelrod.ThueMorse
    expected_classifier = {
        'memory_depth': float('inf'),
        'stochastic': False,
        'makes_use_of': set(),
        'inspects_source': False,
        'manipulates_source': False,
        'manipulates_state': False
    }

    def test_strategy(self):
        """Test that strategy is randomly picked (not affected by history)."""
        self.first_play_test(D)

    def test_effect_of_strategy(self):
        self.markov_test([C, C, C, C])
        self.responses_test([], [], [D, C, C, D, C, D, D, C, C, D, D, C, D, C,
                                     C, D])
        self.responses_test([C], [C], [C, C, D, C, D, D, C, C, D, D, C, D, C, C,
                                       D])
        self.responses_test([D], [D], [C, C, D, C, D, D, C, C, D, D, C, D, C, C,
                                       D])
        self.responses_test([C, C, C, D], [C, C, C, D], [C, D, D, C, C, D, D, C,
                                                         D, C, C, D])


class TestThueMorseInverse(TestPlayer):

    name = 'ThueMorseInverse'
    player = axelrod.ThueMorseInverse
    expected_classifier = {
        'memory_depth': float('inf'),
        'stochastic': False,
        'makes_use_of': set(),
        'inspects_source': False,
        'manipulates_source': False,
        'manipulates_state': False
    }

    def test_strategy(self):
        """Test that strategy always picks C first."""
        self.first_play_test(C)
        self.first_play_test(C)

    def test_effect_of_strategy(self):
        self.markov_test([D, D, D, D])
        self.responses_test([], [], [C, D, D, C, D, C, C, D, D, C, C, D, C, D,
                                     D, C])
        self.responses_test([C], [C], [D, D, C, D, C, C, D, D, C, C, D, C, D, D,
                                       C])
        self.responses_test([D], [D], [D, D, C, D, C, C, D, D, C, C, D, C, D, D,
                                       C])
        self.responses_test([C, C, C, D], [C, C, C, D], [D, C, C, D, D, C, C, D,
                                                         C, D, D, C])<commit_msg>Remove test docstrings and combine tests<commit_after>"""Test for the Thue-Morse strategies."""
import unittest

import axelrod
from .test_player import TestPlayer, TestOpponent
from axelrod.strategies.sequence_player import recursive_thue_morse, SequencePlayer


C, D = axelrod.Actions.C, axelrod.Actions.D

class TestThueMoreGenerator(unittest.TestCase):
    def test_sequence(self):
        expected = [0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0]
        for i, e in enumerate(expected):
            self.assertEqual(recursive_thue_morse(i), e)


class TestSequencePlayer(unittest.TestCase):
    def test_sequence_player(self):
        """Basic test for SequencePlayer."""
        def cooperate_gen():
            yield C
        player = SequencePlayer(cooperate_gen)
        opponent = TestOpponent()
        self.assertEqual(C, player.strategy(opponent))


class TestThueMorse(TestPlayer):

    name = 'ThueMorse'
    player = axelrod.ThueMorse
    expected_classifier = {
        'memory_depth': float('inf'),
        'stochastic': False,
        'makes_use_of': set(),
        'inspects_source': False,
        'manipulates_source': False,
        'manipulates_state': False
    }

    def test_strategy(self):
        self.first_play_test(D)
        self.markov_test([C, C, C, C])
        self.responses_test([], [], [D, C, C, D, C, D, D, C, C, D, D, C, D, C,
                                     C, D])
        self.responses_test([C], [C], [C, C, D, C, D, D, C, C, D, D, C, D, C, C,
                                       D])
        self.responses_test([D], [D], [C, C, D, C, D, D, C, C, D, D, C, D, C, C,
                                       D])
        self.responses_test([C, C, C, D], [C, C, C, D], [C, D, D, C, C, D, D, C,
                                                         D, C, C, D])


class TestThueMorseInverse(TestPlayer):

    name = 'ThueMorseInverse'
    player = axelrod.ThueMorseInverse
    expected_classifier = {
        'memory_depth': float('inf'),
        'stochastic': False,
        'makes_use_of': set(),
        'inspects_source': False,
        'manipulates_source': False,
        'manipulates_state': False
    }

    def test_strategy(self):
        self.first_play_test(C)
        self.markov_test([D, D, D, D])
        self.responses_test([], [], [C, D, D, C, D, C, C, D, D, C, C, D, C, D,
                                     D, C])
        self.responses_test([C], [C], [D, D, C, D, C, C, D, D, C, C, D, C, D, D,
                                       C])
        self.responses_test([D], [D], [D, D, C, D, C, C, D, D, C, C, D, C, D, D,
                                       C])
        self.responses_test([C, C, C, D], [C, C, C, D], [D, C, C, D, D, C, C, D,
                                                         C, D, D, C])
{'fraction_non_alphanumeric': 0.14379423442085276, 'fraction_numerical': 0.005523908165026756, 'mean_word_length': 1.8471744471744471, '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': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '121034', 'n_tokens_mistral': 2054, 'n_tokens_neox': 1973, 'n_words': 552}