]> iEval git - gruntmaster-data.git/blame - t/Gruntmaster-Data.t
Fix rerun_job (twice)
[gruntmaster-data.git] / t / Gruntmaster-Data.t
CommitLineData
4623c9f2 1#!/usr/bin/perl
1ce4e27c 2use v5.14;
4623c9f2 3use warnings;
bbf8209c 4
4623c9f2
MG
5use Gruntmaster::Data;
6use Test::Deep;
7use Test::More;
bbf8209c 8
4623c9f2
MG
9BEGIN {
10 eval {
11 Gruntmaster::Data::init 'dbi:Pg:dbname=gmtest'; 1;
12 } or plan skip_all => 'Cannot connect to test database. Create it by running make_test_db.sh before running this test. '. "Error: $@";
13 plan tests => 37;
14}
15
16note 'Running update_status';
17update_status;
18
19my $x = user_list->{us};
20is @$x, 2, 'user_list has two elements';
21is_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';
22is $x->[1]{admin}, 1, 'user_list second user is admin';
23
24$x = user_entry 'nobody';
25cmp_bag $x->{problems}, [
26 {problem => 'arc', problem_name => 'Problem in archive', solved => bool 1},
27 {problem => 'fca', problem_name => 'FC problem A', solved => bool 1},
28], 'user_entry problems';
29
30is_deeply $x->{contests}, [
31 {contest => 'fc', contest_name => 'Finished contest', rank => 2, score => 40},
32], 'user_entry contests';
33
34sub pbids { [map { $_->{id} } @{$x->{beginner}}] }
35
36$x = problem_list;
37cmp_bag pbids, [qw/arc fca/], 'problem_list';
38
39$x = problem_list private => 1;
40cmp_bag pbids, [qw/arc fca rca pca prv/], 'problem_list private => 1';
41
42$x = problem_list contest => 'rc';
43cmp_bag pbids, [qw/rca/], q/problem_list contest => 'rc'/;
44
45$x = problem_list contest => 'rc', solution => 1;
46ok exists $x->{beginner}[0]{solution}, q/problem_list contest => 'rc', solution => 1 has solution/;
47
48$x = problem_list owner => 'nobody';
49cmp_bag pbids, [], q/problem_list owner => 'nobody'/;
50
51$x = problem_entry 'arc';
52cmp_bag $x->{limits}, [{format => 'C', timeout => 0.1}, {format => 'CPP', timeout => 0.1}], 'problem_entry limits';
53is $x->{solution}, 'Sample Text', 'problem_entry has solution';
54
55$x = problem_entry 'rca', 'rc';
56ok !exists $x->{solution}, 'problem_entry during contest does not have solution';
57ok exists $x->{contest_start}, 'problem_entry during contest has contest_start ';
58
59$x = contest_list;
60is $x->{finished}[0]{id}, 'fc', 'contest_list fc is finished';
61is $x->{running}[0]{id}, 'rc', 'contest_list rc is running';
62is $x->{pending}[0]{id}, 'pc', 'contest_list pc is pending';
63
64$x = contest_entry 'fc';
65cmp_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';
66
67$x = contest_full 'fc';
68ok exists $x->{editorial}, 'contest_full fc has editorial';
69
70ok contest_has_problem('rc', 'rca'), 'contest rc has problem rca';
71ok contest_has_problem('rc', 'arc'), 'contest rc does not have problem arc';
72
73sub jobids { [ map { $_->{id} } @{$x->{log}} ] }
74
75$x = job_list;
76cmp_bag jobids, [1..5], 'job_list';
77is $x->{current_page}, 1, 'current page is 1';
78is $x->{last_page}, 1, 'last page is 1';
79ok !exists $x->{previous_page}, 'there is no previous page';
80ok !exists $x->{next_page}, 'there is no next page';
81
82$x = job_list private => 1;
83cmp_bag jobids, [1..7], 'job_list private => 1';
84
85$x = job_list contest => 'fc';
86cmp_bag jobids, [1..3], 'job_list contest => fc';
87
88$x = job_list owner => 'MGV';
89cmp_bag jobids, [1], 'job_ids owner => MGV';
90
91$x = job_list problem => 'fca';
92cmp_bag jobids, [1..4], 'job_ids problem => fca';
93
94$x = job_list problem => 'fca', result => 1;
95cmp_bag jobids, [2], 'job_ids problem => fca, result => 1';
96
97$x = job_entry 1;
98is $x->{size}, 21, 'job_entry size';
99ok !exists $x->{source}, 'job_entry does not have source';
100is_deeply $x->{results}, [], 'job_entry results';
101
102$x = job_entry 7;
103ok !defined $x->{result}, 'job_entry 7 has NULL result';
104
105$x = job_full 1;
106ok exists $x->{source}, 'job_full has source';
107
108$x = standings 'fc';
109is_deeply $x, {
110 problems => [[fca => 'FC problem A']],
111 st => [
112 {rank => 1, user => 'MGV', user_name => undef, score => 50, scores => [50]},
113 {rank => 2, user => 'nobody', user_name => undef, score => 40, scores => [40]},
114 ]
115}, 'standings fc';
This page took 0.039664 seconds and 4 git commands to generate.