diff options
author | Ivan Enderlin <ivan.enderlin@hoa-project.net> | 2013-09-17 16:21:55 +0200 |
---|---|---|
committer | Ivan Enderlin <ivan.enderlin@hoa-project.net> | 2013-09-17 16:21:55 +0200 |
commit | 49d1f2ae3de6214f75bea56170f6d4e2f2ef84ad (patch) | |
tree | 0dd0963e67de93b69d5323d42f990759b0be03d3 /Praspel.php | |
parent | fe57496b2d32826beff4da7e0bee877cbf8ff4a8 (diff) | |
download | Praspel-49d1f2ae3de6214f75bea56170f6d4e2f2ef84ad.zip Praspel-49d1f2ae3de6214f75bea56170f6d4e2f2ef84ad.tar.gz Praspel-49d1f2ae3de6214f75bea56170f6d4e2f2ef84ad.tar.bz2 |
generateData() make an isotropic random generation
Diffstat (limited to 'Praspel.php')
-rw-r--r-- | Praspel.php | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/Praspel.php b/Praspel.php index c853e8f..fce03fc 100644 --- a/Praspel.php +++ b/Praspel.php @@ -551,21 +551,40 @@ class Praspel { } /** - * Generate data from the @requires clause. + * Isotropic random generation of data from the @requires clause. * * @access public * @return array */ public function generateData ( ) { - $data = array(); - $specification = $this->getSpecification(); + $data = array(); + $behavior = $this->getSpecification(); + + do { + + if(true === $behavior->clauseExists('requires')) { + + foreach($behavior->getClause('requires') as $name => $variable) + $data[$name] = $variable->sample(); + } + + if(false === $behavior->clauseExists('behavior')) + break; + + $behaviors = $behavior->getClause('behavior'); + $count = count($behaviors); + $i = mt_rand(0, $count); + + if($i === $count) { - if(false === $specification->clauseExists('requires')) - return $data; + if(true === $behavior->clauseExists('default')) + $behavior = $behavior->getClause('default'); + } + else + $behavior = $behaviors->getNth($i); - foreach($specification->getClause('requires') as $name => $variable) - $data[$name] = $variable->sample(); + } while(true); $this->setData($data); |