| 1 | 4 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 4 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 4 | ▶ | use 5.024; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | # use feature qw /postderef signatures/; | ||||||||||
| 5 | |||||||||||
| 6 | package Vote::Count::Helper::TestBalance; | ||||||||||
| 7 | |||||||||||
| 8 | 4 | our $VERSION='2.02'; | |||||||||
| 9 | |||||||||||
| 10 | # ABSTRACT: Custom Test for checking STV charge calculations. | ||||||||||
| 11 | |||||||||||
| 12 | =head1 NAME | ||||||||||
| 13 | |||||||||||
| 14 | Vote::Count::Helper::TestBalance; | ||||||||||
| 15 | |||||||||||
| 16 | =head1 VERSION 2.02 | ||||||||||
| 17 | |||||||||||
| 18 | =head1 Synopsis | ||||||||||
| 19 | |||||||||||
| 20 | my $Charges = { 'choice1' => 55, 'choice2' => 79 }; | ||||||||||
| 21 | my $balanceValue = $remaining_vote_value; | ||||||||||
| 22 | balance_ok( $BallotSet, $charges, $balanceValue, [ @elected ], $test_name); | ||||||||||
| 23 | |||||||||||
| 24 | =head1 balance_ok | ||||||||||
| 25 | |||||||||||
| 26 | Compare current charges with the ballotset and the remaining vote_value to confirm that the charges would balance. Used for testing FullCascade Charge. | ||||||||||
| 27 | |||||||||||
| 28 | This method is exported. | ||||||||||
| 29 | |||||||||||
| 30 | =cut | ||||||||||
| 31 | |||||||||||
| 32 | 4 | ▶ | use Test2::API qw/context/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 33 | |||||||||||
| 34 | 4 | our @EXPORT = qw/balance_ok/; | |||||||||
| 35 | 4 | ▶ | use base 'Exporter'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 36 | |||||||||||
| 37 | sub balance_ok :prototype($$$$;$) { | ||||||||||
| 38 | 1 | ▶ | my ( $Ballots, $charge, $balance, $elected, $name ) = @_; | ||||||||
|
Subroutine
balance_ok: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||
| 39 | 1 | ▶ | $name = 'check balance of charges and votes' unless $name; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | 1 | my $valelect = 0; | |||||||||
| 41 | 1 | for ( @{$elected} ) { | |||||||||
| 42 | 3 | $valelect += $charge->{$_}{'value'}; | |||||||||
| 43 | } | ||||||||||
| 44 | 1 | my $valremain = 0; | |||||||||
| 45 | 1 | for my $k ( keys $Ballots->%* ) { | |||||||||
| 46 | $valremain += | ||||||||||
| 47 | 1014 | $Ballots->{$k}{'votevalue'} * $Ballots->{$k}{'count'}; | |||||||||
| 48 | } | ||||||||||
| 49 | 1 | my $valsum = $valremain + $valelect; | |||||||||
| 50 | 1 | my $warning = "### $valsum ($valremain + $valelect) != $balance ###"; | |||||||||
| 51 | 1 | my $ctx = context(); # Get a context | |||||||||
| 52 | 1 | $ctx->ok( $valsum == $balance, $name, [ "$name\n\t$warning"] ); | |||||||||
| 53 | 1 | $ctx->release; # Release the context | |||||||||
| 54 | 1 | return 1; | |||||||||
| 55 | } | ||||||||||
| 56 | |||||||||||
| 57 | 4 | 1; | |||||||||
| 58 | |||||||||||
| 59 | #FOOTER | ||||||||||
| 60 | |||||||||||
| 61 | =pod | ||||||||||
| 62 | |||||||||||
| 63 | BUG TRACKER | ||||||||||
| 64 | |||||||||||
| 65 | L<https://github.com/brainbuz/Vote-Count/issues> | ||||||||||
| 66 | |||||||||||
| 67 | AUTHOR | ||||||||||
| 68 | |||||||||||
| 69 | John Karr (BRAINBUZ) brainbuz@cpan.org | ||||||||||
| 70 | |||||||||||
| 71 | CONTRIBUTORS | ||||||||||
| 72 | |||||||||||
| 73 | Copyright 2019-2021 by John Karr (BRAINBUZ) brainbuz@cpan.org. | ||||||||||
| 74 | |||||||||||
| 75 | LICENSE | ||||||||||
| 76 | |||||||||||
| 77 | This module is released under the GNU Public License Version 3. See license file for details. For more information on this license visit L<http://fsf.org>. | ||||||||||
| 78 | |||||||||||
| 79 | SUPPORT | ||||||||||
| 80 | |||||||||||
| 81 | This software is provided as is, per the terms of the GNU Public License. Professional support and customisation services are available from the author. | ||||||||||
| 82 | |||||||||||
| 83 | =cut | ||||||||||
| 84 | |||||||||||