<s> """<STR_LIT>""" <EOL> import axelrod <EOL> import logging <EOL> from multiprocess import Queue , cpu_count <EOL> import unittest <EOL> import random <EOL> import tempfile <EOL> import csv <EOL> from hypothesis import given , example , settings <EOL> from hypothesis . strategies import integers , lists , sampled_from , random_module , floats <EOL> try : <EOL> from unittest . mock import MagicMock <EOL> except ImportError : <EOL> from mock import MagicMock <EOL> test_strategies = [ axelrod . Cooperator , <EOL> axelrod . TitForTat , <EOL> axelrod . Defector , <EOL> axelrod . Grudger , <EOL> axelrod . GoByMajority ] <EOL> test_repetitions = <NUM_LIT:5> <EOL> test_turns = <NUM_LIT:100> <EOL> test_prob_end = <NUM_LIT> <EOL> class TestTournament ( unittest . TestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> cls . game = axelrod . Game ( ) <EOL> cls . players = [ s ( ) for s in test_strategies ] <EOL> cls . test_name = '<STR_LIT:test>' <EOL> cls . test_repetitions = test_repetitions <EOL> cls . test_turns = test_turns <EOL> cls . expected_payoff = [ <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT:1000> , <NUM_LIT> , <NUM_LIT:200> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] , <EOL> [ <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> ] ] <EOL> cls . expected_cooperation = [ <EOL> [ <NUM_LIT:200> , <NUM_LIT:200> , <NUM_LIT:200> , <NUM_LIT:200> , <NUM_LIT:200> ] , <EOL> [ <NUM_LIT:200> , <NUM_LIT:200> , <NUM_LIT:1> , <NUM_LIT:200> , <NUM_LIT:200> ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> ] , <EOL> [ <NUM_LIT:200> , <NUM_LIT:200> , <NUM_LIT:1> , <NUM_LIT:200> , <NUM_LIT:200> ] , <EOL> [ <NUM_LIT:200> , <NUM_LIT:200> , <NUM_LIT:1> , <NUM_LIT:200> , <NUM_LIT:200> ] ] <EOL> def test_init ( self ) : <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> turns = self . test_turns , <EOL> processes = <NUM_LIT:4> , <EOL> noise = <NUM_LIT> ) <EOL> self . assertEqual ( len ( tournament . players ) , len ( test_strategies ) ) <EOL> self . assertIsInstance ( <EOL> tournament . players [ <NUM_LIT:0> ] . match_attributes [ '<STR_LIT>' ] , axelrod . Game <EOL> ) <EOL> self . assertEqual ( tournament . game . score ( ( '<STR_LIT:C>' , '<STR_LIT:C>' ) ) , ( <NUM_LIT:3> , <NUM_LIT:3> ) ) <EOL> self . assertEqual ( tournament . turns , self . test_turns ) <EOL> self . assertEqual ( tournament . repetitions , <NUM_LIT:10> ) <EOL> self . assertEqual ( tournament . name , '<STR_LIT:test>' ) <EOL> self . assertEqual ( tournament . _processes , <NUM_LIT:4> ) <EOL> self . assertTrue ( tournament . _with_morality ) <EOL> self . assertIsInstance ( tournament . _logger , logging . Logger ) <EOL> self . assertEqual ( tournament . deterministic_cache , { } ) <EOL> self . assertEqual ( tournament . noise , <NUM_LIT> ) <EOL> self . assertEqual ( tournament . _parallel_repetitions , <NUM_LIT:10> ) <EOL> anonymous_tournament = axelrod . Tournament ( players = self . players ) <EOL> self . assertEqual ( anonymous_tournament . name , '<STR_LIT>' ) <EOL> cache = axelrod . DeterministicCache ( ) <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> turns = self . test_turns , <EOL> processes = <NUM_LIT:4> , <EOL> noise = <NUM_LIT> , <EOL> deterministic_cache = cache ) <EOL> self . assertEqual ( tournament . deterministic_cache , cache ) <EOL> def test_serial_play ( self ) : <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> turns = <NUM_LIT:200> , <EOL> repetitions = self . test_repetitions ) <EOL> results = tournament . play ( ) <EOL> self . assertIsInstance ( results , axelrod . ResultSet ) <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> turns = <NUM_LIT:200> , <EOL> repetitions = self . test_repetitions ) <EOL> tournament . _run_serial_repetitions = MagicMock ( <EOL> name = '<STR_LIT>' ) <EOL> tournament . _run_parallel_repetitions = MagicMock ( <EOL> name = '<STR_LIT>' ) <EOL> tournament . play ( ) <EOL> tournament . _run_serial_repetitions . assert_called_once_with ( [ ] ) <EOL> self . assertFalse ( tournament . _run_parallel_repetitions . called ) <EOL> @ given ( s = lists ( sampled_from ( axelrod . strategies ) , <EOL> min_size = <NUM_LIT:2> , <EOL> max_size = <NUM_LIT:5> , unique = True ) , <EOL> turns = integers ( min_value = <NUM_LIT:2> , max_value = <NUM_LIT:50> ) , <EOL> repetitions = integers ( min_value = <NUM_LIT:2> , max_value = <NUM_LIT:4> ) , <EOL> rm = random_module ( ) ) <EOL> @ settings ( max_examples = <NUM_LIT:50> , timeout = <NUM_LIT:0> ) <EOL> @ example ( s = test_strategies , turns = test_turns , repetitions = test_repetitions , <EOL> rm = random . seed ( <NUM_LIT:0> ) ) <EOL> @ example ( s = [ axelrod . BackStabber , axelrod . MindReader ] , turns = <NUM_LIT:2> , repetitions = <NUM_LIT:1> , <EOL> rm = random . seed ( <NUM_LIT:0> ) ) <EOL> @ example ( s = [ axelrod . ThueMorse , axelrod . MindReader ] , turns = <NUM_LIT:2> , repetitions = <NUM_LIT:1> , <EOL> rm = random . seed ( <NUM_LIT:0> ) ) <EOL> def test_property_serial_play ( self , s , turns , repetitions , rm ) : <EOL> """<STR_LIT>""" <EOL> players = [ strat ( ) for strat in s ] <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = players , <EOL> game = self . game , <EOL> turns = turns , <EOL> repetitions = repetitions ) <EOL> results = tournament . play ( ) <EOL> self . assertIsInstance ( results , axelrod . ResultSet ) <EOL> self . assertEqual ( results . nplayers , len ( players ) ) <EOL> self . assertEqual ( results . players , players ) <EOL> def test_parallel_play ( self ) : <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> turns = <NUM_LIT:200> , <EOL> repetitions = self . test_repetitions , <EOL> processes = <NUM_LIT:2> ) <EOL> results = tournament . play ( ) <EOL> self . assertIsInstance ( results , axelrod . ResultSet ) <EOL> players = [ axelrod . Cooperator ( ) , axelrod . Defector ( ) , <EOL> axelrod . BackStabber ( ) , axelrod . PSOGambler ( ) , <EOL> axelrod . ThueMorse ( ) , axelrod . DoubleCrosser ( ) ] <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = players , <EOL> game = self . game , <EOL> turns = <NUM_LIT:20> , <EOL> repetitions = self . test_repetitions , <EOL> processes = <NUM_LIT:2> ) <EOL> scores = tournament . play ( ) . scores <EOL> self . assertEqual ( len ( scores ) , len ( players ) ) <EOL> def test_build_cache_required ( self ) : <EOL> cache = axelrod . DeterministicCache ( ) <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> processes = <NUM_LIT:4> , <EOL> noise = <NUM_LIT> , <EOL> deterministic_cache = cache ) <EOL> self . assertFalse ( tournament . _build_cache_required ( ) ) <EOL> key = ( axelrod . TitForTat , axelrod . Defector , <NUM_LIT:3> ) <EOL> cache [ key ] = [ ( '<STR_LIT:C>' , '<STR_LIT:D>' ) , ( '<STR_LIT:D>' , '<STR_LIT:D>' ) , ( '<STR_LIT:D>' , '<STR_LIT:D>' ) ] <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> processes = <NUM_LIT:4> , <EOL> noise = <NUM_LIT> , <EOL> deterministic_cache = cache ) <EOL> self . assertFalse ( tournament . _build_cache_required ( ) ) <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> processes = <NUM_LIT:4> , <EOL> deterministic_cache = cache ) <EOL> self . assertFalse ( tournament . _build_cache_required ( ) ) <EOL> cache = axelrod . DeterministicCache ( ) <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> processes = <NUM_LIT:4> , <EOL> deterministic_cache = cache ) <EOL> self . assertTrue ( tournament . _build_cache_required ( ) ) <EOL> def test_build_cache ( self ) : <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> turns = <NUM_LIT:200> , <EOL> repetitions = self . test_repetitions , <EOL> processes = <NUM_LIT:2> ) <EOL> tournament . _run_single_repetition = MagicMock ( <EOL> name = '<STR_LIT>' ) <EOL> tournament . _build_cache ( [ ] ) <EOL> tournament . _run_single_repetition . assert_called_once_with ( [ ] ) <EOL> self . assertEqual ( <EOL> tournament . _parallel_repetitions , self . test_repetitions - <NUM_LIT:1> ) <EOL> def test_run_single_repetition ( self ) : <EOL> interactions = [ ] <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> turns = <NUM_LIT:200> , <EOL> repetitions = self . test_repetitions ) <EOL> tournament . _run_single_repetition ( interactions ) <EOL> self . assertEqual ( len ( tournament . interactions ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( len ( tournament . interactions [ <NUM_LIT:0> ] ) , <NUM_LIT:15> ) <EOL> def test_run_serial_repetitions ( self ) : <EOL> interactions = [ ] <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> turns = <NUM_LIT:200> , <EOL> repetitions = self . test_repetitions ) <EOL> tournament . _run_serial_repetitions ( interactions ) <EOL> self . assertEqual ( len ( tournament . interactions ) , self . test_repetitions ) <EOL> def test_run_parallel_repetitions ( self ) : <EOL> interactions = [ ] <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> turns = <NUM_LIT:200> , <EOL> repetitions = self . test_repetitions , <EOL> processes = <NUM_LIT:2> ) <EOL> tournament . _run_parallel_repetitions ( interactions ) <EOL> self . assertEqual ( len ( interactions ) , self . test_repetitions ) <EOL> for r in interactions : <EOL> self . assertEqual ( len ( r . values ( ) ) , <NUM_LIT:15> ) <EOL> def test_n_workers ( self ) : <EOL> max_processes = cpu_count ( ) <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> turns = <NUM_LIT:200> , <EOL> repetitions = self . test_repetitions , <EOL> processes = <NUM_LIT:1> ) <EOL> self . assertEqual ( tournament . _n_workers ( ) , max_processes ) <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> turns = <NUM_LIT:200> , <EOL> repetitions = self . test_repetitions , <EOL> processes = max_processes + <NUM_LIT:2> ) <EOL> self . assertEqual ( tournament . _n_workers ( ) , max_processes ) <EOL> @ unittest . skipIf ( <EOL> cpu_count ( ) < <NUM_LIT:2> , <EOL> "<STR_LIT>" ) <EOL> def test_2_workers ( self ) : <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> turns = <NUM_LIT:200> , <EOL> repetitions = self . test_repetitions , <EOL> processes = <NUM_LIT:2> ) <EOL> self . assertEqual ( tournament . _n_workers ( ) , <NUM_LIT:2> ) <EOL> def test_start_workers ( self ) : <EOL> workers = <NUM_LIT:2> <EOL> work_queue = Queue ( ) <EOL> done_queue = Queue ( ) <EOL> for repetition in range ( self . test_repetitions ) : <EOL> work_queue . put ( repetition ) <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> turns = <NUM_LIT:200> , <EOL> repetitions = self . test_repetitions ) <EOL> tournament . _start_workers ( workers , work_queue , done_queue ) <EOL> stops = <NUM_LIT:0> <EOL> while stops < workers : <EOL> payoffs = done_queue . get ( ) <EOL> if payoffs == '<STR_LIT>' : <EOL> stops += <NUM_LIT:1> <EOL> self . assertEqual ( stops , workers ) <EOL> def test_process_done_queue ( self ) : <EOL> workers = <NUM_LIT:2> <EOL> done_queue = Queue ( ) <EOL> matches = [ ] <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> turns = <NUM_LIT:200> , <EOL> repetitions = self . test_repetitions ) <EOL> for r in range ( self . test_repetitions ) : <EOL> done_queue . put ( { } ) <EOL> for w in range ( workers ) : <EOL> done_queue . put ( '<STR_LIT>' ) <EOL> tournament . _process_done_queue ( workers , done_queue , matches ) <EOL> self . assertEqual ( len ( matches ) , self . test_repetitions ) <EOL> def test_worker ( self ) : <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> turns = <NUM_LIT:200> , <EOL> repetitions = self . test_repetitions ) <EOL> work_queue = Queue ( ) <EOL> for repetition in range ( self . test_repetitions ) : <EOL> work_queue . put ( repetition ) <EOL> work_queue . put ( '<STR_LIT>' ) <EOL> done_queue = Queue ( ) <EOL> tournament . _worker ( work_queue , done_queue ) <EOL> for r in range ( self . test_repetitions ) : <EOL> new_matches = done_queue . get ( ) <EOL> self . assertEqual ( len ( new_matches ) , <NUM_LIT:15> ) <EOL> for index_pair , match in new_matches . items ( ) : <EOL> self . assertIsInstance ( index_pair , tuple ) <EOL> self . assertIsInstance ( match , list ) <EOL> queue_stop = done_queue . get ( ) <EOL> self . assertEqual ( queue_stop , '<STR_LIT>' ) <EOL> def test_build_result_set ( self ) : <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> turns = <NUM_LIT:200> , <EOL> repetitions = self . test_repetitions ) <EOL> results = tournament . _build_result_set ( ) <EOL> self . assertIsInstance ( results , axelrod . ResultSet ) <EOL> @ given ( turns = integers ( min_value = <NUM_LIT:1> , max_value = <NUM_LIT:200> ) ) <EOL> @ example ( turns = <NUM_LIT:3> ) <EOL> @ example ( turns = <NUM_LIT:200> ) <EOL> def test_play_matches ( self , turns ) : <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> repetitions = self . test_repetitions ) <EOL> def make_generator ( ) : <EOL> """<STR_LIT>""" <EOL> player_classes = [ axelrod . Cooperator , axelrod . TitForTat , <EOL> axelrod . Defector , axelrod . Grudger ] <EOL> for i , player_cls in enumerate ( player_classes ) : <EOL> for j , opponent_cls in enumerate ( player_classes ) : <EOL> if j >= i : <EOL> players = ( player_cls ( ) , opponent_cls ( ) ) <EOL> match = axelrod . Match ( players , turns = turns ) <EOL> yield ( ( i , j ) , match ) <EOL> matches_generator = make_generator ( ) <EOL> interactions = tournament . _play_matches ( matches_generator ) <EOL> self . assertEqual ( len ( interactions ) , <NUM_LIT:10> ) <EOL> for index_pair , inter in interactions . items ( ) : <EOL> self . assertEqual ( len ( inter ) , turns ) <EOL> self . assertEqual ( len ( index_pair ) , <NUM_LIT:2> ) <EOL> for plays in inter : <EOL> self . assertIsInstance ( plays , tuple ) <EOL> self . assertEqual ( len ( plays ) , <NUM_LIT:2> ) <EOL> self . assertEqual ( ( len ( list ( matches_generator ) ) ) , <NUM_LIT:0> ) <EOL> def test_play_and_write_to_csv ( self ) : <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> turns = <NUM_LIT:2> , <EOL> repetitions = <NUM_LIT:2> ) <EOL> tmp_file = tempfile . NamedTemporaryFile ( mode = '<STR_LIT:w>' , delete = False ) <EOL> tournament . play ( filename = tmp_file . name ) <EOL> with open ( tmp_file . name , '<STR_LIT:r>' ) as f : <EOL> written_data = [ [ int ( r [ <NUM_LIT:0> ] ) , int ( r [ <NUM_LIT:1> ] ) ] + r [ <NUM_LIT:2> : ] for r in csv . reader ( f ) ] <EOL> expected_data = [ [ <NUM_LIT:0> , <NUM_LIT:1> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:3> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:2> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:4> , <NUM_LIT:4> , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:4> , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:1> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:3> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:3> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:4> , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:4> , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:3> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:4> , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:2> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> self . assertEqual ( sorted ( written_data ) , sorted ( expected_data ) ) <EOL> def test_write_to_csv ( self ) : <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> turns = <NUM_LIT:2> , <EOL> repetitions = <NUM_LIT:2> ) <EOL> tournament . play ( ) <EOL> tmp_file = tempfile . NamedTemporaryFile ( mode = '<STR_LIT:w>' , delete = False ) <EOL> tournament . _write_to_csv ( tmp_file . name ) <EOL> with open ( tmp_file . name , '<STR_LIT:r>' ) as f : <EOL> written_data = [ [ int ( r [ <NUM_LIT:0> ] ) , int ( r [ <NUM_LIT:1> ] ) ] + r [ <NUM_LIT:2> : ] for r in csv . reader ( f ) ] <EOL> expected_data = [ [ <NUM_LIT:0> , <NUM_LIT:1> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:3> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:2> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:4> , <NUM_LIT:4> , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:4> , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:1> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:3> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:3> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:4> , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:4> , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:3> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:4> , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:2> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> self . assertEqual ( sorted ( written_data ) , sorted ( expected_data ) ) <EOL> def test_data_for_csv ( self ) : <EOL> tournament = axelrod . Tournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> turns = <NUM_LIT:2> , <EOL> repetitions = <NUM_LIT:2> ) <EOL> tournament . play ( ) <EOL> expected_data = [ [ <NUM_LIT:0> , <NUM_LIT:1> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:2> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:0> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:3> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:2> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:4> , <NUM_LIT:4> , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:4> , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:1> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:1> , <NUM_LIT:3> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:3> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:4> , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:2> , <NUM_LIT:4> , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:3> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:3> , <NUM_LIT:4> , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ] , <EOL> [ <NUM_LIT:0> , <NUM_LIT:2> , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ] <EOL> generator_data = tournament . _data_for_csv ( ) <EOL> for row , expected_row in zip ( sorted ( generator_data ) , sorted ( expected_data ) ) : <EOL> self . assertEqual ( row , expected_row ) <EOL> class TestProbEndTournament ( unittest . TestCase ) : <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> cls . game = axelrod . Game ( ) <EOL> cls . players = [ s ( ) for s in test_strategies ] <EOL> cls . test_name = '<STR_LIT:test>' <EOL> cls . test_repetitions = test_repetitions <EOL> cls . test_prob_end = test_prob_end <EOL> def test_init ( self ) : <EOL> tournament = axelrod . ProbEndTournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> prob_end = self . test_prob_end , <EOL> noise = <NUM_LIT> ) <EOL> self . assertEqual ( tournament . match_generator . prob_end , tournament . prob_end ) <EOL> self . assertEqual ( len ( tournament . players ) , len ( test_strategies ) ) <EOL> self . assertEqual ( tournament . game . score ( ( '<STR_LIT:C>' , '<STR_LIT:C>' ) ) , ( <NUM_LIT:3> , <NUM_LIT:3> ) ) <EOL> self . assertEqual ( tournament . turns , float ( "<STR_LIT>" ) ) <EOL> self . assertEqual ( tournament . repetitions , <NUM_LIT:10> ) <EOL> self . assertEqual ( tournament . name , '<STR_LIT:test>' ) <EOL> self . assertEqual ( tournament . _processes , None ) <EOL> self . assertTrue ( tournament . _with_morality ) <EOL> self . assertIsInstance ( tournament . _logger , logging . Logger ) <EOL> self . assertEqual ( tournament . deterministic_cache , { } ) <EOL> self . assertEqual ( tournament . noise , <NUM_LIT> ) <EOL> self . assertEqual ( tournament . _parallel_repetitions , <NUM_LIT:10> ) <EOL> anonymous_tournament = axelrod . Tournament ( players = self . players ) <EOL> self . assertEqual ( anonymous_tournament . name , '<STR_LIT>' ) <EOL> cache = axelrod . DeterministicCache ( ) <EOL> tournament = axelrod . ProbEndTournament ( <EOL> name = self . test_name , <EOL> players = self . players , <EOL> game = self . game , <EOL> prob_end = self . test_prob_end , <EOL> processes = <NUM_LIT:4> , <EOL> noise = <NUM_LIT> , <EOL> deterministic_cache = cache ) <EOL> self . assertEqual ( tournament . deterministic_cache , cache ) <EOL> @ given ( s = lists ( sampled_from ( axelrod . strategies ) , <EOL> min_size = <NUM_LIT:2> , <EOL> max_size = <NUM_LIT:5> , unique = True ) , <EOL> prob_end = floats ( min_value = <NUM_LIT> , max_value = <NUM_LIT> ) , <EOL> repetitions = integers ( min_value = <NUM_LIT:2> , max_value = <NUM_LIT:4> ) , <EOL> rm = random_module ( ) ) <EOL> @ settings ( max_examples = <NUM_LIT:50> , timeout = <NUM_LIT:0> ) <EOL> @ example ( s = test_strategies , prob_end = <NUM_LIT> , repetitions = test_repetitions , <EOL> rm = random . seed ( <NUM_LIT:0> ) ) <EOL> @ example ( s = [ axelrod . BackStabber , axelrod . MindReader ] , prob_end = <NUM_LIT> , repetitions = <NUM_LIT:1> , <EOL> rm = random . seed ( <NUM_LIT:0> ) ) <EOL> @ example ( s = [ axelrod . ThueMorse , axelrod . MindReader ] , prob_end = <NUM_LIT> , repetitions = <NUM_LIT:1> , <EOL> rm = random . seed ( <NUM_LIT:0> ) ) <EOL> def test_property_serial_play ( self , s , prob_end , repetitions , rm ) : <EOL> """<STR_LIT>""" <EOL> players = [ strat ( ) for strat in s ] <EOL> tournament = axelrod . ProbEndTournament ( <EOL> name = self . test_name , <EOL> players = players , <EOL> game = self . game , <EOL> prob_end = prob_end , <EOL> repetitions = repetitions ) <EOL> results = tournament . play ( ) <EOL> self . assertIsInstance ( results , axelrod . ResultSet ) <EOL> self . assertEqual ( results . nplayers , len ( players ) ) <EOL> self . assertEqual ( results . players , players ) <EOL> self . assertEqual ( len ( results . interactions ) , repetitions ) </s>
