@@ -594,45 +594,82 @@ def test_init(self):
594
594
self .assertTrue (tournament ._with_morality )
595
595
self .assertIsInstance (tournament ._logger , logging .Logger )
596
596
self .assertEqual (tournament .noise , 0.2 )
597
+ self .assertEqual (tournament .match_generator .noise , 0.2 )
597
598
anonymous_tournament = axelrod .Tournament (players = self .players )
598
599
self .assertEqual (anonymous_tournament .name , 'axelrod' )
599
600
600
- @given (strategies = strategy_lists (strategies = deterministic_strategies ,
601
- min_size = 2 , max_size = 2 ),
602
- turns = integers (min_value = 1 , max_value = 20 ))
603
-
604
- def test_complete_tournament (self , strategies , turns ):
605
- """
606
- A test to check that a spatial tournament on the complete multigraph
607
- gives the same results as the round robin.
608
- """
609
-
610
- players = [s () for s in strategies ]
611
- # edges
612
- edges = []
613
- for i in range (0 , len (players )) :
614
- for j in range (i , len (players )) :
615
- edges .append ((i , j ))
616
- # create a round robin tournament
617
- tournament = axelrod .Tournament (players , turns = turns )
618
- results = tournament .play ()
619
- # create a complete spatial tournament
620
- spatial_tournament = axelrod .SpatialTournament (players , turns = turns ,
621
- edges = edges )
622
- spatial_results = spatial_tournament .play ()
623
- self .assertEqual (results .ranked_names , spatial_results .ranked_names )
624
- self .assertEqual (results .nplayers , spatial_results .nplayers )
625
- self .assertEqual (results .nrepetitions , spatial_results .nrepetitions )
626
- self .assertEqual (results .payoff_diffs_means , spatial_results .payoff_diffs_means )
627
- self .assertEqual (results .payoff_matrix , spatial_results .payoff_matrix )
628
- self .assertEqual (results .payoff_stddevs , spatial_results .payoff_stddevs )
629
- self .assertEqual (results .payoffs , spatial_results .payoffs )
630
- self .assertEqual (results .cooperating_rating , spatial_results .cooperating_rating )
631
- self .assertEqual (results .cooperation , spatial_results .cooperation )
632
- self .assertEqual (results .normalised_cooperation , spatial_results .normalised_cooperation )
633
- self .assertEqual (results .normalised_scores , spatial_results .normalised_scores )
634
- self .assertEqual (results .good_partner_matrix , spatial_results .good_partner_matrix )
635
- self .assertEqual (results .good_partner_rating , spatial_results .good_partner_rating )
601
+ @given (strategies = strategy_lists (strategies = deterministic_strategies ,
602
+ min_size = 2 , max_size = 2 ),
603
+ turns = integers (min_value = 1 , max_value = 20 ),
604
+ repetitions = integers (min_value = 1 , max_value = 5 ),
605
+ noise = floats (min_value = 0 , max_value = 1 ),
606
+ seed = integers (min_value = 0 , max_value = 4294967295 ))
607
+ @settings (max_examples = 50 , timeout = 0 )
608
+ def test_complete_tournament (self , strategies , turns , repetitions ,
609
+ noise , seed ):
610
+ """
611
+ A test to check that a spatial tournament on the complete multigraph
612
+ gives the same results as the round robin.
613
+ """
614
+
615
+ players = [s () for s in strategies ]
616
+ # edges
617
+ edges = []
618
+ for i in range (0 , len (players )):
619
+ for j in range (i , len (players )):
620
+ edges .append ((i , j ))
621
+
622
+ # create a round robin tournament
623
+ tournament = axelrod .Tournament (players , repetitions = repetitions ,
624
+ turns = turns , noise = noise )
625
+ # create a complete spatial tournament
626
+ spatial_tournament = axelrod .SpatialTournament (players ,
627
+ repetitions = repetitions ,
628
+ turns = turns ,
629
+ noise = noise ,
630
+ edges = edges )
631
+
632
+ axelrod .seed (seed )
633
+ results = tournament .play (progress_bar = False )
634
+ axelrod .seed (seed )
635
+ spatial_results = spatial_tournament .play (progress_bar = False )
636
+
637
+ self .assertEqual (results .ranked_names , spatial_results .ranked_names )
638
+ self .assertEqual (results .nplayers , spatial_results .nplayers )
639
+ self .assertEqual (results .nrepetitions , spatial_results .nrepetitions )
640
+ self .assertEqual (results .payoff_diffs_means ,
641
+ spatial_results .payoff_diffs_means )
642
+ self .assertEqual (results .payoff_matrix , spatial_results .payoff_matrix )
643
+ self .assertEqual (results .payoff_stddevs , spatial_results .payoff_stddevs )
644
+ self .assertEqual (results .payoffs , spatial_results .payoffs )
645
+ self .assertEqual (results .cooperating_rating ,
646
+ spatial_results .cooperating_rating )
647
+ self .assertEqual (results .cooperation , spatial_results .cooperation )
648
+ self .assertEqual (results .normalised_cooperation ,
649
+ spatial_results .normalised_cooperation )
650
+ self .assertEqual (results .normalised_scores ,
651
+ spatial_results .normalised_scores )
652
+ self .assertEqual (results .good_partner_matrix ,
653
+ spatial_results .good_partner_matrix )
654
+ self .assertEqual (results .good_partner_rating ,
655
+ spatial_results .good_partner_rating )
656
+
657
+ def test_particular_tournament (self ):
658
+ """A test for a tournament that has caused failures during some bug
659
+ fixing"""
660
+ players = [axelrod .Cooperator (), axelrod .Defector (),
661
+ axelrod .TitForTat (), axelrod .Grudger ()]
662
+ edges = [(0 , 2 ), (0 , 3 ), (1 , 2 ), (1 , 3 )]
663
+ tournament = axelrod .SpatialTournament (players , edges = edges )
664
+ results = tournament .play (progress_bar = False )
665
+ expected_ranked_names = ['Cooperator' , 'Tit For Tat' ,
666
+ 'Grudger' , 'Defector' ]
667
+ self .assertEqual (results .ranked_names , expected_ranked_names )
668
+
669
+ # Check that this tournament runs with noise
670
+ tournament = axelrod .SpatialTournament (players , edges = edges , noise = .5 )
671
+ results = tournament .play (progress_bar = False )
672
+ self .assertIsInstance (results , axelrod .ResultSetFromFile )
636
673
637
674
638
675
class TestProbEndingSpatialTournament (unittest .TestCase ):
@@ -671,8 +708,11 @@ def test_init(self):
671
708
@given (strategies = strategy_lists (strategies = deterministic_strategies ,
672
709
min_size = 2 , max_size = 2 ),
673
710
prob_end = floats (min_value = .1 , max_value = .9 ),
711
+ reps = integers (min_value = 1 , max_value = 3 ),
674
712
seed = integers (min_value = 0 , max_value = 4294967295 ))
675
- def test_complete_tournament (self , strategies , prob_end , seed ):
713
+ @settings (max_examples = 50 , timeout = 0 )
714
+ def test_complete_tournament (self , strategies , prob_end ,
715
+ seed , reps ):
676
716
"""
677
717
A test to check that a spatial tournament on the complete graph
678
718
gives the same results as the round robin.
@@ -683,12 +723,14 @@ def test_complete_tournament(self, strategies, prob_end, seed):
683
723
for j in range (i , len (players ))]
684
724
# create a prob end round robin tournament
685
725
axelrod .seed (seed )
686
- tournament = axelrod .ProbEndTournament (players , prob_end = prob_end )
726
+ tournament = axelrod .ProbEndTournament (players , prob_end = prob_end ,
727
+ repetitions = reps )
687
728
results = tournament .play (progress_bar = False )
688
729
# create a complete spatial tournament
689
730
axelrod .seed (seed )
690
731
spatial_tournament = axelrod .ProbEndSpatialTournament (players ,
691
732
prob_end = prob_end ,
733
+ repetitions = reps ,
692
734
edges = edges )
693
735
spatial_results = spatial_tournament .play (progress_bar = False )
694
736
self .assertEqual (results .match_lengths , spatial_results .match_lengths )
@@ -700,8 +742,10 @@ def test_complete_tournament(self, strategies, prob_end, seed):
700
742
701
743
702
744
@given (tournament = spatial_tournaments (strategies = axelrod .basic_strategies ,
703
- max_turns = 1 ),
745
+ max_turns = 1 , max_noise = 0 ,
746
+ max_repetitions = 3 ),
704
747
seed = integers (min_value = 0 , max_value = 4294967295 ))
748
+ @settings (max_examples = 50 , timeout = 0 )
705
749
def test_one_turn_tournament (self , tournament , seed ):
706
750
"""
707
751
Tests that gives same result as the corresponding spatial round robin
0 commit comments