From 7a5ea00ceb65d1874d44758cdce2050f85bc9e7e Mon Sep 17 00:00:00 2001 From: Alex Karle Date: Wed, 25 Mar 2020 00:01:30 -0400 Subject: [PATCH] Euchre::Game: Clean up score_round API I think it's cleaner to return the index of the winning team along with how many points they scored (as opposed to points for each team, one of which is always zero). --- lib/Euchre/Game.pm | 13 ++++++------- t/Game.t | 15 ++++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/Euchre/Game.pm b/lib/Euchre/Game.pm index 6663cd8..ba143ca 100644 --- a/lib/Euchre/Game.pm +++ b/lib/Euchre/Game.pm @@ -76,6 +76,7 @@ sub trick_winner { # Given # tricks per player, who won? What score? # Use X to indicate sat-out. $callers either 0 or 1 +# Returns idx of team, points to give sub score_round { my ($callers, @tricks) = @_; @@ -90,25 +91,23 @@ sub score_round { } } - my @points = (0, 0); - $DB::single = 1; if ($totals[$callers] == 5) { if ($loner) { # Hot diggity dog! - $points[$callers] = 4; + return $callers, 4; } else { # Respectable - $points[$callers] = 2; + return $callers, 2; } } elsif($totals[$callers] > $totals[$setters]) { # Made your point... - $points[$callers] = 1; + return $callers, 1; } else { # We've been Euched, Bill! - $points[$setters] = 2; + return $setters, 2; } - return \@points; + die 'assert'; } 1; diff --git a/t/Game.t b/t/Game.t index afaf9d9..78da3ec 100644 --- a/t/Game.t +++ b/t/Game.t @@ -48,16 +48,17 @@ sub test_trick_winner { sub test_score_round { my @tests = ( - [[0, 1,2,1,1], [0, 2], 'Euched!'], - [[1, 2,1,1,1], [2, 0], 'Euched again!'], - [[1, 2,3,0,0], [0,1], 'Made your point'], - [[1, 0,3,0,2], [0,2], 'Got em all!'], - [[0, 5,0,'X',0], [4,0], 'Loneeeer!'], - [[0, 3,1,'X',1], [1,0], 'Failed loner'], + [[0, 1,2,1,1], [1, 2], 'Euched!'], + [[1, 2,1,1,1], [0, 2], 'Euched again!'], + [[1, 2,3,0,0], [1,1], 'Made your point'], + [[1, 0,3,0,2], [1,2], 'Got em all!'], + [[0, 5,0,'X',0], [0,4], 'Loneeeer!'], + [[0, 3,1,'X',1], [0,1], 'Failed loner'], ); for my $t (@tests) { - is_deeply(score_round(@{$t->[0]}), $t->[1], $t->[2]); + my ($winners, $points) = score_round(@{$t->[0]}); + is_deeply([$winners, $points], $t->[1], $t->[2]); } } -- libgit2 1.1.1