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

Added tests for grumpy strategy #6

Closed
wants to merge 1 commit into from
Closed
Changes from all 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
47 changes: 47 additions & 0 deletions axelrod/tests/test_grumpy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
"""
Test for the grudger strategy
"""
import unittest
import axelrod

class TestGrumpy(unittest.TestCase):

def test_initial_nice_strategy(self):
"""
Starts by cooperating
"""
P1 = axelrod.Grumpy()
P2 = axelrod.Player()
self.assertEqual(P1.strategy(P2), 'C')

def test_initial_grumpy_strategy(self):
"""
Starts by defecting if grumpy
"""
P1 = axelrod.Grumpy(starting_state = 'Grumpy')
P2 = axelrod.Player()
self.assertEqual(P1.strategy(P2), 'D')

def test_effect_of_strategy(self):
"""
Tests that grumpy will play c until threshold is ht at which point it will become grumpy.
Player will then not become nice until lower nice threshold is hit.
"""
P1 = axelrod.Grumpy(grumpy_threshold = 3, nice_threshold=0)
P2 = axelrod.Player()
P1.history = ['C', 'D', 'D', 'D']
P2.history = ['C', 'C', 'C', 'C']
self.assertEqual(P1.strategy(P2), 'C')
P1.history = ['C', 'C', 'D', 'D', 'D']
P2.history = ['D', 'D', 'D', 'D', 'D']
self.assertEqual(P1.strategy(P2), 'D')
P1.history = ['C', 'C', 'D', 'D', 'D', 'D', 'D', 'D']
P2.history = ['D', 'D', 'D', 'D', 'D', 'C', 'C', 'C']
self.assertEqual(P1.strategy(P2), 'D')
P1.history = ['C', 'C', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D', 'D']
P2.history = ['D', 'D', 'D', 'D', 'D', 'C', 'C', 'C', 'C', 'C', 'C']
self.assertEqual(P1.strategy(P2), 'C')

def test_representation(self):
P1 = axelrod.Grumpy()
self.assertEqual(str(P1), 'Grumpy')