Changeset 213 for trunk/t


Ignore:
Timestamp:
04/16/09 20:47:17 (15 years ago)
Author:
nanardon
Message:
  • more tests and the fix need to have it passing
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/t/10Vote_DB.t

    r202 r213  
    55# $Id$ 
    66 
    7 my $test_polls = [ 
    8 # Structure: 
     7# Tpoll Structure: 
    98#    { 
    109#        poll => { var => $val }, 
     
    1817#        results => { var => $val }, # wanted results  
    1918#    } 
     19my $test_polls = [ 
    2020    { # an empty poll 
    2121        poll => { label => 'empty poll' }, 
    2222        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"); 
    2679        } 
    2780    }, 
    2881]; 
    2982 
     83my $poll_test_count = 0; 
     84$poll_test_count += ($_->{test_count} || 0) foreach(@$test_polls); 
     85 
    3086plan tests =>  
    31     3                        # Fixed test  
    32     + scalar(@$test_polls) * # number of tested polls scenario 
    33     6;                       # per poll number of tests 
     87    3                          # Fixed test  
     88    + scalar(@$test_polls) * 4 # number of tested polls scenario 
     89    + $poll_test_count;        # poll test 
    3490 
    3591use_ok 'Vote', 'Vote'; 
    3692use_ok 'Vote::DB'; 
    37  
    3893$ENV{EPOLL_NO_COMMIT} = 1; 
    39  
    4094isa_ok(my $vote = Vote::DB->new(Vote->config->{db}), 'Vote::DB'); 
    4195 
     
    65119    foreach my $name (keys %{ $tpoll->{ballot} || {} }) { 
    66120        $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' 
    68122        ); 
    69123    } 
     
    71125    isa_ok(my $results = $vote->results($pollid), 'Vote::DB::Poll'); 
    72126 
    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); 
    77128 
    78     my $res = $results->results_count; 
     129    $vote->db->rollback; # really rollback 
     130} 
    79131 
    80     $vote->rollback; 
    81 } 
Note: See TracChangeset for help on using the changeset viewer.