Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
59 lines (43 sloc) 1.2 KB
#!/usr/bin/env perl
# Test the extrema.
use strict;
use warnings;
use Test::More;
use Test::WWW::Mechanize;
use IO::All;
my $disordered = -1; # 1 for "disordered", 0 for "no disorder", -1 for random response
my $base = 'http://0.0.0.0:5000';
my $max = 10;
my ( $plus, $minus );
if ( $disordered ) {
( $plus, $minus ) = ( $max, 1 );
}
else {
( $plus, $minus ) = ( 1, $max );
}
# Read-in quiz questions
my @quiz = io('public/dpda-questions.txt')->slurp;
my $mech = Test::WWW::Mechanize->new();
$mech->get("$base/question");
if ( $mech->status eq '200' ) {
for my $i ( 0 .. @quiz - 1 ) {
my $question_num = $mech->scrape_text_by_id('question_num');
my $inv = ( split /\s+/, ( split /\|/, $quiz[$question_num] )[0] )[-1];
my $answer;
if ( $disordered == -1 ) {
$answer = 1 + int rand $max;
}
else {
$answer = $inv eq '+' ? $plus : $minus;
}
$mech->submit_form_ok(
{ fields => { answer => $answer } },
"submit form for $inv question $question_num = $answer"
);
}
is $mech->base, "$base/chart", '/chart';
}
else {
print "Can't connect to $base\n";
}
done_testing();