diff options
author | Ivan Enderlin <ivan.enderlin@hoa-project.net> | 2013-11-25 11:41:12 +0100 |
---|---|---|
committer | Ivan Enderlin <ivan.enderlin@hoa-project.net> | 2013-11-25 11:41:12 +0100 |
commit | fc0c70751c490b51d2a16ff88654cc8bd19935d5 (patch) | |
tree | f62af20d62a440cea0fe7c6a043c26225064f174 | |
parent | 380dba95fb9f2db92e401db1c11bcaf26975a2e4 (diff) | |
download | Praspel-fc0c70751c490b51d2a16ff88654cc8bd19935d5.zip Praspel-fc0c70751c490b51d2a16ff88654cc8bd19935d5.tar.gz Praspel-fc0c70751c490b51d2a16ff88654cc8bd19935d5.tar.bz2 |
The generateData method is now static…
… and it has been moved into `Hoa\Praspel\AssertionChecker` class.
-rw-r--r-- | AssertionChecker/AssertionChecker.php | 33 | ||||
-rw-r--r-- | AssertionChecker/Runtime.php | 46 |
2 files changed, 37 insertions, 42 deletions
diff --git a/AssertionChecker/AssertionChecker.php b/AssertionChecker/AssertionChecker.php index 10e2305..414f0b5 100644 --- a/AssertionChecker/AssertionChecker.php +++ b/AssertionChecker/AssertionChecker.php @@ -141,11 +141,42 @@ abstract class AssertionChecker { /** * Generate data. + * Isotropic random generation of data from the @requires clause. * * @access public + * @param \Hoa\Praspel\Model\Specification $specification Specification. * @return array */ - abstract public function generateData ( ); + public static function generateData ( \Hoa\Praspel\Model\Specification $specification ) { + + $data = array(); + $behavior = $specification; + + 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(true === $behavior->clauseExists('default')) + $behavior = $behavior->getClause('default'); + } + else + $behavior = $behaviors->getNth($i); + + } while(true); + + return $data; + } /** * Set specification. diff --git a/AssertionChecker/Runtime.php b/AssertionChecker/Runtime.php index e0b8265..71f1414 100644 --- a/AssertionChecker/Runtime.php +++ b/AssertionChecker/Runtime.php @@ -145,8 +145,11 @@ class Runtime extends AssertionChecker { // Prepare data. if(null === $data = $this->getData()) - if(true === $this->canGenerateData()) - $data = $this->generateData(); + if(true === $this->canGenerateData()) { + + $data = static::generateData($specification); + $this->setData($data); + } else throw new \Hoa\Praspel\Exception\AssertionChecker( 'No data were given. The System Under Test %s needs data ' . @@ -651,45 +654,6 @@ class Runtime extends AssertionChecker { return $verdict; } - - /** - * Isotropic random generation of data from the @requires clause. - * - * @access public - * @return array - */ - public function generateData ( ) { - - $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(true === $behavior->clauseExists('default')) - $behavior = $behavior->getClause('default'); - } - else - $behavior = $behaviors->getNth($i); - - } while(true); - - $this->setData($data); - - return $data; - } } } |