<s> """<STR_LIT>""" <EOL> import axelrod <EOL> import random <EOL> from . test_player import TestPlayer , TestHeadsUp <EOL> from axelrod import random_choice , Actions <EOL> C , D = axelrod . Actions . C , axelrod . Actions . D <EOL> class TestGambler ( TestPlayer ) : <EOL> name = "<STR_LIT>" <EOL> player = axelrod . Gambler <EOL> expected_classifier = { <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : set ( [ '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False <EOL> } <EOL> def test_init ( self ) : <EOL> player = self . player ( dict ( ) ) <EOL> opponent = axelrod . Cooperator ( ) <EOL> self . assertEqual ( player . strategy ( opponent ) , C ) <EOL> player = self . player ( ) <EOL> expected_lookup_table = { <EOL> ( '<STR_LIT>' , '<STR_LIT:C>' , '<STR_LIT:D>' ) : <NUM_LIT:0> , <EOL> ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:D>' ) : <NUM_LIT:0> , <EOL> ( '<STR_LIT>' , '<STR_LIT:C>' , '<STR_LIT:C>' ) : <NUM_LIT:1> , <EOL> ( '<STR_LIT>' , '<STR_LIT:D>' , '<STR_LIT:C>' ) : <NUM_LIT:1> , <EOL> } <EOL> self . assertEqual ( player . lookup_table , expected_lookup_table ) <EOL> table = { ( C , C ) : <NUM_LIT:1> , ( '<STR_LIT>' , '<STR_LIT>' ) : <NUM_LIT:1> } <EOL> with self . assertRaises ( ValueError ) : <EOL> player = self . player ( table ) <EOL> def test_strategy ( self ) : <EOL> self . responses_test ( [ C ] * <NUM_LIT:4> , [ C , C , C , C ] , [ C ] ) <EOL> self . responses_test ( [ C ] * <NUM_LIT:5> , [ C , C , C , C , D ] , [ D ] ) <EOL> def test_defector_table ( self ) : <EOL> """<STR_LIT>""" <EOL> defector_table = { <EOL> ( '<STR_LIT>' , C , D ) : <NUM_LIT:0> , <EOL> ( '<STR_LIT>' , D , D ) : <NUM_LIT:0> , <EOL> ( '<STR_LIT>' , C , C ) : <NUM_LIT:0> , <EOL> ( '<STR_LIT>' , D , C ) : <NUM_LIT:0> , <EOL> } <EOL> self . player = lambda : axelrod . Gambler ( defector_table ) <EOL> self . responses_test ( [ C , C ] , [ C , C ] , [ D ] ) <EOL> self . responses_test ( [ C , D ] , [ D , C ] , [ D ] ) <EOL> self . responses_test ( [ D , D ] , [ D , D ] , [ D ] ) <EOL> class TestPSOGambler ( TestPlayer ) : <EOL> name = "<STR_LIT>" <EOL> player = axelrod . PSOGambler <EOL> expected_classifier = { <EOL> '<STR_LIT>' : float ( '<STR_LIT>' ) , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : set ( [ '<STR_LIT>' ] ) , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False , <EOL> '<STR_LIT>' : False <EOL> } <EOL> def test_init ( self ) : <EOL> known_pairs = { ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <NUM_LIT> , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) : <NUM_LIT> } <EOL> player = self . player ( ) <EOL> for k , v in known_pairs . items ( ) : <EOL> self . assertEqual ( player . lookup_table [ k ] , v ) <EOL> def test_strategy ( self ) : <EOL> """<STR_LIT>""" <EOL> self . first_play_test ( C ) <EOL> self . responses_test ( [ C ] * <NUM_LIT> , [ C ] * <NUM_LIT> , [ C , D , D ] , <EOL> tournament_length = <NUM_LIT:200> ) <EOL> class PSOGamblervsDefector ( TestHeadsUp ) : <EOL> def test_vs ( self ) : <EOL> self . versus_test ( axelrod . PSOGambler ( ) , axelrod . Defector ( ) , <EOL> [ C , C , D , D ] , [ D , D , D , D ] ) <EOL> class PSOGamblervsCooperator ( TestHeadsUp ) : <EOL> def test_vs ( self ) : <EOL> self . versus_test ( axelrod . PSOGambler ( ) , axelrod . Cooperator ( ) , <EOL> [ C , C , C , C ] , [ C , C , C , C ] ) <EOL> class PSOGamblervsTFT ( TestHeadsUp ) : <EOL> def test_vs ( self ) : <EOL> outcomes = zip ( ) <EOL> self . versus_test ( axelrod . PSOGambler ( ) , axelrod . TitForTat ( ) , <EOL> [ C , C , C , C ] , [ C , C , C , C ] ) <EOL> class PSOGamblervsAlternator ( TestHeadsUp ) : <EOL> def test_vs ( self ) : <EOL> self . versus_test ( axelrod . PSOGambler ( ) , axelrod . Alternator ( ) , <EOL> [ C , C , D , D , D , D ] , [ C , D , C , D , C , D ] ) </s>
