Login   Register  
PHP Classes
elePHPant
Icontem

File: test-suite.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Jonas Raoni Soares Silva  >  Advanced Randomizer  >  test-suite.php  >  Download  
File: test-suite.php
Role: Unit test script
Content type: text/plain
Description: Test to show up the algorithm precision
Class: Advanced Randomizer
Retrieve random items based on given probability
Author: By
Last change:
Date: 9 years ago
Size: 1,137 bytes
 

Contents

Class file image Download
<?php
header
'Content-Type: text/plain' );
include( 
'lib.probabilityRandom.php' );

$prExample = new probabilityRandom;

$data = array(
    array( 
'G'30),
    array( 
'F'20),
    array( 
'E'10),
    array( 
'D'3),
    array( 
'C'12),
    array( 
'B'15),
    array( 
'A'25)
);

for( 
$i sizeof$data ); $i--; $prExample->add$i$data[$i][1] ) );


$testMultiplier 100;

for( 
$total $i $prExample->universe $testMultiplier$i--; ){
     
$data[  $prExample->get() ][ ]++;
}

print <<<END
Permutations Sum: \t$prExample->universe
Test Mutiplier: \t
$testMultiplier
TOTAL SAMPLES: \t\t
$total

Data\tProbability\tMatches\t\tExpected Ratio\tReal Ratio\tPerfection
END;


for( print 
"\n"$i sizeof$data ); $i--; print
    
$data[$i][0] . "\t"
    
$data[$i][1] . "\t\t"
    
$data[$i][2] . "\t\t"
    
round$expectedRatio $data[$i][1] / $total 100 $testMultiplier) . "%\t\t"
    
round$realRatio $data[$i][2]/$total 100) . "%\t\t"
    
round( ( $realRatio $expectedRatio 2*$expectedRatio $realRatio $realRatio ) / $expectedRatio 100)
    . 
"%\n"
);
?>