<s> import unittest <EOL> import axelrod <EOL> from axelrod import MockPlayer , simulate_play , update_history <EOL> from axelrod . tests . unit . test_player import TestOpponent <EOL> C , D = axelrod . Actions . C , axelrod . Actions . D <EOL> class TestMockPlayer ( unittest . TestCase ) : <EOL> def test_strategy ( self ) : <EOL> for move in [ C , D ] : <EOL> m = MockPlayer ( axelrod . Player ( ) , move ) <EOL> p2 = axelrod . Player ( ) <EOL> self . assertEqual ( move , m . strategy ( p2 ) ) <EOL> def test_cloning ( self ) : <EOL> p1 = axelrod . Cooperator ( ) <EOL> p2 = axelrod . Defector ( ) <EOL> moves = <NUM_LIT:10> <EOL> for i in range ( moves ) : <EOL> p1 . play ( p2 ) <EOL> m1 = MockPlayer ( p1 , C ) <EOL> m2 = MockPlayer ( p2 , D ) <EOL> self . assertEqual ( m1 . move , C ) <EOL> self . assertEqual ( m1 . history , p1 . history ) <EOL> self . assertEqual ( m1 . cooperations , p1 . cooperations ) <EOL> self . assertEqual ( m1 . defections , p1 . defections ) <EOL> self . assertEqual ( m2 . move , D ) <EOL> self . assertEqual ( m2 . history , p2 . history ) <EOL> self . assertEqual ( m2 . cooperations , p2 . cooperations ) <EOL> self . assertEqual ( m2 . defections , p2 . defections ) <EOL> class TestUpdateHistories ( unittest . TestCase ) : <EOL> def test_various ( self ) : <EOL> p1 = TestOpponent ( ) <EOL> p2 = TestOpponent ( ) <EOL> update_history ( p1 , C ) <EOL> update_history ( p2 , C ) <EOL> self . assertEqual ( p1 . history , [ C ] ) <EOL> self . assertEqual ( p2 . history , [ C ] ) <EOL> self . assertEqual ( p1 . cooperations , <NUM_LIT:1> ) <EOL> self . assertEqual ( p2 . cooperations , <NUM_LIT:1> ) <EOL> self . assertEqual ( p1 . defections , <NUM_LIT:0> ) <EOL> self . assertEqual ( p2 . defections , <NUM_LIT:0> ) <EOL> update_history ( p1 , D ) <EOL> update_history ( p2 , D ) <EOL> self . assertEqual ( p1 . history , [ C , D ] ) <EOL> self . assertEqual ( p2 . history , [ C , D ] ) <EOL> self . assertEqual ( p1 . cooperations , <NUM_LIT:1> ) <EOL> self . assertEqual ( p2 . cooperations , <NUM_LIT:1> ) <EOL> self . assertEqual ( p1 . defections , <NUM_LIT:1> ) <EOL> self . assertEqual ( p2 . defections , <NUM_LIT:1> ) <EOL> class TestSimulatePlay ( unittest . TestCase ) : <EOL> def test_various ( self ) : <EOL> p1 = TestOpponent ( ) <EOL> p2 = TestOpponent ( ) <EOL> self . assertEqual ( simulate_play ( p1 , p2 ) , ( C , C ) ) <EOL> self . assertEqual ( p1 . cooperations , <NUM_LIT:1> ) <EOL> self . assertEqual ( p2 . cooperations , <NUM_LIT:1> ) <EOL> self . assertEqual ( p1 . defections , <NUM_LIT:0> ) <EOL> self . assertEqual ( p2 . defections , <NUM_LIT:0> ) <EOL> for h1 in [ C , D ] : <EOL> for h2 in [ C , D ] : <EOL> self . assertEqual ( simulate_play ( p1 , p2 , h1 , h2 ) , ( h1 , h2 ) ) <EOL> self . assertEqual ( p1 . cooperations , <NUM_LIT:3> ) <EOL> self . assertEqual ( p2 . cooperations , <NUM_LIT:3> ) <EOL> self . assertEqual ( p1 . defections , <NUM_LIT:2> ) <EOL> self . assertEqual ( p2 . defections , <NUM_LIT:2> ) <EOL> def test_various2 ( self ) : <EOL> p1 = axelrod . Cooperator ( ) <EOL> p2 = axelrod . Defector ( ) <EOL> self . assertEqual ( simulate_play ( p1 , p2 ) , ( C , D ) ) <EOL> self . assertEqual ( p1 . cooperations , <NUM_LIT:1> ) <EOL> self . assertEqual ( p2 . cooperations , <NUM_LIT:0> ) <EOL> self . assertEqual ( p1 . defections , <NUM_LIT:0> ) <EOL> self . assertEqual ( p2 . defections , <NUM_LIT:1> ) <EOL> self . assertEqual ( simulate_play ( p1 , p2 ) , ( C , D ) ) <EOL> self . assertEqual ( p1 . cooperations , <NUM_LIT:2> ) <EOL> self . assertEqual ( p2 . cooperations , <NUM_LIT:0> ) <EOL> self . assertEqual ( p1 . defections , <NUM_LIT:0> ) <EOL> self . assertEqual ( p2 . defections , <NUM_LIT:2> ) <EOL> self . assertEqual ( p1 . history , [ C ] * <NUM_LIT:2> ) <EOL> self . assertEqual ( p2 . history , [ D ] * <NUM_LIT:2> ) </s>
