Changeset 213 for trunk/t/10Vote_DB.t
- Timestamp:
- 04/16/09 20:47:17 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/t/10Vote_DB.t
r202 r213 5 5 # $Id$ 6 6 7 my $test_polls = [ 8 # Structure: 7 # Tpoll Structure: 9 8 # { 10 9 # poll => { var => $val }, … … 18 17 # results => { var => $val }, # wanted results 19 18 # } 19 my $test_polls = [ 20 20 { # an empty poll 21 21 poll => { label => 'empty poll' }, 22 22 choices => [ qw(ch1 ch2) ], 23 results => { 24 ballot_count => 0, 25 absolute_majority => 1, 23 test_count => 4, 24 tests => sub { 25 my ($r) = @_; 26 is($r->absolute_majority, 1, "Can get absolute_majority"); 27 is($r->ballot_count, 0, "can get ballot count"); 28 is($r->voting_count, 0, "can get voting count"); 29 is($r->signing_count, 0, "can get signing count"); 30 } 31 }, 32 { 33 poll => { label => 'some vals' }, 34 choices => [ qw(ch1 ch2) ], 35 voting => [ qw(a b c d e f) ], 36 ballot => { 37 a => { sbal => [ 'ch1' ] }, 38 b => { sbal => [ 'ch1', 'ch10' ] }, 39 d => { sbal => [ 'ch1', 'ch2' ] }, 40 f => {}, 41 }, 42 test_count => 7, 43 tests => sub { 44 my ($r) = @_; 45 is($r->absolute_majority, 2, "Can get absolute_majority"); 46 is($r->ballot_count, 4, "can get ballot count"); 47 is($r->ballot_count_nonull, 3, "can get ballot count"); 48 is($r->voting_count, 6, "can get voting count"); 49 is($r->signing_count, 4, "can get signing count"); 50 my $res = $r->results_nonull; 51 is($res->[0]->{value}, 'ch1', "winner is ch1"); 52 is($res->[0]->{count}, 3, "winner has 3 voices"); 53 } 54 }, 55 { 56 poll => { label => 'some vals with mapped values' }, 57 choices => [ qw(ch1 ch2 ch3) ], 58 voting => [ qw(a b c d e f) ], 59 ballot => { 60 a => { sbal => [ 'ch1' ] }, 61 b => { sbal => [ 'ch1', 'ch10' ] }, 62 d => { sbal => [ 'ch1', 'ch2' ] }, 63 f => {}, 64 }, 65 test_count => 9, 66 tests => sub { 67 my ($r) = @_; 68 $r->map_value('ch10', 'ch1'); 69 is($r->absolute_majority, 2, "Can get absolute_majority"); 70 is($r->ballot_count, 4, "can get ballot count"); 71 is($r->ballot_count_nonull, 3, "can get ballot count"); 72 is($r->voting_count, 6, "can get voting count"); 73 is($r->signing_count, 4, "can get signing count"); 74 my $res = $r->results_nonull; 75 is($res->[0]->{value}, 'ch1', "winner is ch1"); 76 is($res->[0]->{count}, 3, "winner has 3 voices"); 77 is(@$res, 3, "count of winners"); 78 is($res->[2]->{count}, 0, "last has 0 voices"); 26 79 } 27 80 }, 28 81 ]; 29 82 83 my $poll_test_count = 0; 84 $poll_test_count += ($_->{test_count} || 0) foreach(@$test_polls); 85 30 86 plan tests => 31 3 # Fixed test32 + scalar(@$test_polls) * # number of tested polls scenario33 6; # per poll number of tests87 3 # Fixed test 88 + scalar(@$test_polls) * 4 # number of tested polls scenario 89 + $poll_test_count; # poll test 34 90 35 91 use_ok 'Vote', 'Vote'; 36 92 use_ok 'Vote::DB'; 37 38 93 $ENV{EPOLL_NO_COMMIT} = 1; 39 40 94 isa_ok(my $vote = Vote::DB->new(Vote->config->{db}), 'Vote::DB'); 41 95 … … 65 119 foreach my $name (keys %{ $tpoll->{ballot} || {} }) { 66 120 $poll->register_ballot( 67 $name, $tpoll->{ballot}{$name}{sbal}, $tpoll->{ballot}{$name}{ sbal}, "localtest"121 $name, $tpoll->{ballot}{$name}{sbal}, $tpoll->{ballot}{$name}{fsbal}, 'localhost' 68 122 ); 69 123 } … … 71 125 isa_ok(my $results = $vote->results($pollid), 'Vote::DB::Poll'); 72 126 73 is($results->ballot_count, $tpoll->{results}{ballot_count} || 0, 74 "can get ballot count"); 75 is($results->absolute_majority, $tpoll->{results}{absolute_majority}, 76 "can get absolute majority"); 127 $tpoll->{tests}->($results); 77 128 78 my $res = $results->results_count; 129 $vote->db->rollback; # really rollback 130 } 79 131 80 $vote->rollback;81 }
Note: See TracChangeset
for help on using the changeset viewer.