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