1000 across 5 bins that the distribution is not even. The highest and lowest bin seem to have about half the frequency of the other bins. This is due to the use of the round function. int would make the distribution more even (white) at the cost of not returning the limiting number.
79 lines
2.2 KiB
Perl
79 lines
2.2 KiB
Perl
#-------------------------------------------------------------------
|
|
# WebGUI is Copyright 2001-2006 Plain Black Corporation.
|
|
#-------------------------------------------------------------------
|
|
# Please read the legal notices (docs/legal.txt) and the license
|
|
# (docs/license.txt) that came with this distribution before using
|
|
# this software.
|
|
#-------------------------------------------------------------------
|
|
# http://www.plainblack.com info@plainblack.com
|
|
#-------------------------------------------------------------------
|
|
|
|
use FindBin;
|
|
use strict;
|
|
use lib "$FindBin::Bin/../lib";
|
|
|
|
use WebGUI::Test;
|
|
use WebGUI::Macro;
|
|
use WebGUI::Session;
|
|
use WebGUI::Group;
|
|
use WebGUI::User;
|
|
use WebGUI::Macro_Config;
|
|
|
|
my $session = WebGUI::Test->session;
|
|
|
|
use Test::More; # increment this value for each test you create
|
|
use List::Util qw/max min/;
|
|
use Data::Dumper;
|
|
|
|
##Note, testing statistical functions is kind of weird. All we really
|
|
##need to do is make sure that the macro functions as advertised.
|
|
|
|
plan tests => 4;
|
|
|
|
unless ($session->config->get('macros')->{'Splat_random'}) {
|
|
Macro_Config::insert_macro($session, '*', 'Splat_random');
|
|
}
|
|
|
|
my $macroText = q!^*(%s);!;
|
|
my $output;
|
|
my $inBounds = 1;
|
|
BOUNDED: for (my $i=0; $i<=99; $i++) {
|
|
my $output = sprintf $macroText, 10;
|
|
WebGUI::Macro::process($session, \$output);
|
|
if (($output > 10) or ($output < 0)) {
|
|
$inBounds = 0;
|
|
last BOUNDED;
|
|
}
|
|
}
|
|
|
|
ok($inBounds, "100 fetches were in bounds");
|
|
|
|
$output = '^*;';
|
|
WebGUI::Macro::process($session, \$output);
|
|
ok($output >= 0 and $output < 1_000_000_000, "Empty argument returns a number");
|
|
|
|
my $wholeNumber = 1;
|
|
WHOLE: for (my $i=0; $i<=99; $i++) {
|
|
my $output = sprintf $macroText, 1;
|
|
WebGUI::Macro::process($session, \$output);
|
|
if (int($output) != $output) {
|
|
$wholeNumber = 0;
|
|
last WHOLE;
|
|
}
|
|
}
|
|
|
|
ok($wholeNumber, "100 fetches were all whole numbers");
|
|
|
|
my @bins = ();
|
|
WHOLE: for (my $i=0; $i<=999; $i++) {
|
|
my $output = sprintf $macroText, 4;
|
|
WebGUI::Macro::process($session, \$output);
|
|
++$bins[$output];
|
|
}
|
|
|
|
is(scalar(@bins), 5, "All bins have values on a sample size of 1000");
|
|
|
|
##Early work in analyzing a frequency distribution showed that the highest
|
|
##and lowest bin have half the frequency of center bins. Splat_random doesn't
|
|
##seem very random
|
|
#diag Dumper \@bins;
|