[LON-CAPA-cvs] cvs: modules /jerf compute_points_test.pl
bowersj2
lon-capa-cvs@mail.lon-capa.org
Sat, 25 Feb 2006 20:22:54 -0000
bowersj2 Sat Feb 25 15:22:54 2006 EDT
Added files:
/modules/jerf compute_points_test.pl
Log:
A script to test the compute_points rounding algorithm that is about
to be committed.
Index: modules/jerf/compute_points_test.pl
+++ modules/jerf/compute_points_test.pl
# This tests the compute_points function in Apache::grades.
use Test::More 'no_plan';
use lib '/home/httpd/lib/perl';
use lib 'tests/';
use Apache::grades;
use strict;
use warnings;
sub compute_points
{ return Apache::grades::compute_points(@_); }
# Check the basic cases to make sure we didn't screw them up.
is(compute_points(1, 0), 0);
is(compute_points(0, 1), 0);
is(compute_points(.5, 1), .5);
is(compute_points(.25, 1), .25);
is(compute_points(1/3, 1), 1/3);
# Now, start getting fancy; this next one is what started this
# whole function...
is(compute_points(1/3 ,18), 6);
is(compute_points(.250001, 1), .25);
is(compute_points(2/3, 3), 2);
for my $i (1..100)
{
my $smidge = .00001 / 1001;
my $little = .001;
for my $j (1..$i)
{
is(compute_points($j/$i, $i), $j);
is(compute_points($j/$i + $smidge, $i), $j);
is(compute_points($j/$i - $smidge, $i), $j);
isnt(compute_points($j/$i + $little, $i), $j);
isnt(compute_points($j/$i - $little, $i), $j);
# test thirds
is(compute_points($j/3/$i, $i), $j/3);
is(compute_points($j/3/$i + $smidge, $i), $j/3);
is(compute_points($j/3/$i - $smidge, $i), $j/3);
isnt(compute_points($j/3/$i + $little, $i), $j/3);
isnt(compute_points($j/3/$i - $little, $i), $j/3);
# test quarters
is(compute_points($j/4/$i, $i), $j/4);
is(compute_points($j/4/$i + $smidge, $i), $j/4);
is(compute_points($j/4/$i - $smidge, $i), $j/4);
isnt(compute_points($j/4/$i + $little, $i), $j/4);
isnt(compute_points($j/4/$i - $little, $i), $j/4);
}
}