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