Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing tests for lookerup.py #900

Merged
merged 7 commits into from
Mar 14, 2017
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion axelrod/tests/strategies/test_lookerup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Test for the Looker Up strategy."""
import copy
import unittest

import axelrod
from axelrod.strategies.lookerup import (
Expand Down Expand Up @@ -28,6 +27,31 @@ class TestLookerUp(TestPlayer):
expected_class_classifier = copy.copy(expected_classifier)
expected_class_classifier['memory_depth'] = float('inf')

def test_create_lookup_table_keys(self):
expected = [
('C', 'C', 'C'), ('C', 'C', 'D'), ('C', 'D', 'C'), ('C', 'D', 'D'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use C, D = Actions.C, Actions.D throughout

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with what was already there in the existing test, but yes, you're right. I'll fix the whole lot.

('D', 'C', 'C'), ('D', 'C', 'D'), ('D', 'D', 'C'), ('D', 'D', 'D')
]
actual = create_lookup_table_keys(1, 1, 1)
self.assertEqual(actual, expected)

def test_create_lookup_table_from_pattern(self):
expected = {
('C', 'C', 'C'): 'C',
('C', 'C', 'D'): 'C',
('C', 'D', 'C'): 'D',
('C', 'D', 'D'): 'C',
('D', 'C', 'C'): 'C',
('D', 'C', 'D'): 'D',
('D', 'D', 'C'): 'C',
('D', 'D', 'D'): 'C'
}
actual = create_lookup_table_from_pattern(1, 1, 1, 'CCDCCDCC')
self.assertEqual(actual, expected)

with self.assertRaises(ValueError):
create_lookup_table_from_pattern(2, 2, 2, 'CCC')

def test_init(self):
# Test empty table
player = self.player(dict())
Expand Down Expand Up @@ -62,10 +86,19 @@ def test_pattern_init(self):
self.assertEqual(player.lookup_table, expected_lookup_table)

def test_strategy(self):
self.first_play_test(C)
self.second_play_test(C, D, C, D) # TFT
self.responses_test([C], [C] * 4, [C, C, C, C])
self.responses_test([D], [C] * 5, [C, C, C, C, D])

opponent = axelrod.MockPlayer()
actions = [(C, C), (C, C), (C, C), (C, C)]
self.versus_test(
opponent,
expected_actions=actions,
init_kwargs={'parameters': (1, 1, 0)}
)

def test_defector_table(self):
"""
Testing a lookup table that always defects if there is enough history.
Expand Down