X-Git-Url: http://git.ieval.ro/?a=blobdiff_plain;f=t%2FGruntmaster-Data.t;h=d7e2d7faedbd54b4fc3db3267b31d7f6bdfec040;hb=4623c9f2c2bd5309fcd57e9da2f2e18fe3dcdb45;hp=b3b8672a44ee5d740b03dd97333b8907a005924e;hpb=6c0423f49be4a1e609bbcf961824097c07edbe1b;p=gruntmaster-data.git diff --git a/t/Gruntmaster-Data.t b/t/Gruntmaster-Data.t index b3b8672..d7e2d7f 100644 --- a/t/Gruntmaster-Data.t +++ b/t/Gruntmaster-Data.t @@ -1,6 +1,115 @@ -#!/usr/bin/perl -w +#!/usr/bin/perl use v5.14; +use warnings; -use Test::More tests => 1; +use Gruntmaster::Data; +use Test::Deep; +use Test::More; -BEGIN { use_ok('Gruntmaster::Data') }; +BEGIN { + eval { + Gruntmaster::Data::init 'dbi:Pg:dbname=gmtest'; 1; + } or plan skip_all => 'Cannot connect to test database. Create it by running make_test_db.sh before running this test. '. "Error: $@"; + plan tests => 37; +} + +note 'Running update_status'; +update_status; + +my $x = user_list->{us}; +is @$x, 2, 'user_list has two elements'; +is_deeply $x->[0], {id => 'nobody', admin => 0, name => undef, town => undef, university => undef, country => undef, level => undef, lastjob => undef, contests => 1, solved => 2, attempted => 0}, 'user_list first element is correct'; +is $x->[1]{admin}, 1, 'user_list second user is admin'; + +$x = user_entry 'nobody'; +cmp_bag $x->{problems}, [ + {problem => 'arc', problem_name => 'Problem in archive', solved => bool 1}, + {problem => 'fca', problem_name => 'FC problem A', solved => bool 1}, +], 'user_entry problems'; + +is_deeply $x->{contests}, [ + {contest => 'fc', contest_name => 'Finished contest', rank => 2, score => 40}, +], 'user_entry contests'; + +sub pbids { [map { $_->{id} } @{$x->{beginner}}] } + +$x = problem_list; +cmp_bag pbids, [qw/arc fca/], 'problem_list'; + +$x = problem_list private => 1; +cmp_bag pbids, [qw/arc fca rca pca prv/], 'problem_list private => 1'; + +$x = problem_list contest => 'rc'; +cmp_bag pbids, [qw/rca/], q/problem_list contest => 'rc'/; + +$x = problem_list contest => 'rc', solution => 1; +ok exists $x->{beginner}[0]{solution}, q/problem_list contest => 'rc', solution => 1 has solution/; + +$x = problem_list owner => 'nobody'; +cmp_bag pbids, [], q/problem_list owner => 'nobody'/; + +$x = problem_entry 'arc'; +cmp_bag $x->{limits}, [{format => 'C', timeout => 0.1}, {format => 'CPP', timeout => 0.1}], 'problem_entry limits'; +is $x->{solution}, 'Sample Text', 'problem_entry has solution'; + +$x = problem_entry 'rca', 'rc'; +ok !exists $x->{solution}, 'problem_entry during contest does not have solution'; +ok exists $x->{contest_start}, 'problem_entry during contest has contest_start '; + +$x = contest_list; +is $x->{finished}[0]{id}, 'fc', 'contest_list fc is finished'; +is $x->{running}[0]{id}, 'rc', 'contest_list rc is running'; +is $x->{pending}[0]{id}, 'pc', 'contest_list pc is pending'; + +$x = contest_entry 'fc'; +cmp_deeply $x, {id => 'fc', name => 'Finished contest', start => ignore, stop => ignore, owner => 'MGV', owner_name => undef, finished => bool (1), started => bool (1), description => undef}, 'contest_entry fc'; + +$x = contest_full 'fc'; +ok exists $x->{editorial}, 'contest_full fc has editorial'; + +ok contest_has_problem('rc', 'rca'), 'contest rc has problem rca'; +ok contest_has_problem('rc', 'arc'), 'contest rc does not have problem arc'; + +sub jobids { [ map { $_->{id} } @{$x->{log}} ] } + +$x = job_list; +cmp_bag jobids, [1..5], 'job_list'; +is $x->{current_page}, 1, 'current page is 1'; +is $x->{last_page}, 1, 'last page is 1'; +ok !exists $x->{previous_page}, 'there is no previous page'; +ok !exists $x->{next_page}, 'there is no next page'; + +$x = job_list private => 1; +cmp_bag jobids, [1..7], 'job_list private => 1'; + +$x = job_list contest => 'fc'; +cmp_bag jobids, [1..3], 'job_list contest => fc'; + +$x = job_list owner => 'MGV'; +cmp_bag jobids, [1], 'job_ids owner => MGV'; + +$x = job_list problem => 'fca'; +cmp_bag jobids, [1..4], 'job_ids problem => fca'; + +$x = job_list problem => 'fca', result => 1; +cmp_bag jobids, [2], 'job_ids problem => fca, result => 1'; + +$x = job_entry 1; +is $x->{size}, 21, 'job_entry size'; +ok !exists $x->{source}, 'job_entry does not have source'; +is_deeply $x->{results}, [], 'job_entry results'; + +$x = job_entry 7; +ok !defined $x->{result}, 'job_entry 7 has NULL result'; + +$x = job_full 1; +ok exists $x->{source}, 'job_full has source'; + +$x = standings 'fc'; +is_deeply $x, { + problems => [[fca => 'FC problem A']], + st => [ + {rank => 1, user => 'MGV', user_name => undef, score => 50, scores => [50]}, + {rank => 2, user => 'nobody', user_name => undef, score => 40, scores => [40]}, + ] +}, 'standings fc';