From bf34723ad2afa830360cbd9a4ae83e969b8e0606 Mon Sep 17 00:00:00 2001 From: Niels Braczek Date: Tue, 21 Jul 2020 13:17:26 +0200 Subject: [PATCH] Style cleanup --- .gitignore | 1 - src/GreenCape/AllPairs/PairHash.php | 42 +-- src/GreenCape/AllPairs/Parameter.php | 300 +++++++++--------- src/GreenCape/AllPairs/Reader.php | 18 +- src/GreenCape/AllPairs/Reader/FileReader.php | 8 +- .../AllPairs/Reader/StringReader.php | 248 ++++++++------- src/GreenCape/AllPairs/Strategy.php | 14 +- src/GreenCape/AllPairs/Strategy/Default.php | 218 ------------- .../AllPairs/Strategy/DefaultStrategy.php | 201 ++++++++++++ src/GreenCape/AllPairs/Strategy/Qict.php | 289 ----------------- .../AllPairs/Strategy/QictStrategy.php | 261 +++++++++++++++ src/GreenCape/AllPairs/Writer.php | 2 +- .../AllPairs/Writer/ConsoleWriter.php | 24 +- .../AllPairs/Writer/VardumpWriter.php | 13 +- src/GreenCape/Combinator.php | 205 ++++++------ src/allpairs.php | 41 ++- src/autoload.php | 30 ++ tests/data/joomla.txt | 5 + 18 files changed, 952 insertions(+), 968 deletions(-) delete mode 100644 src/GreenCape/AllPairs/Strategy/Default.php create mode 100644 src/GreenCape/AllPairs/Strategy/DefaultStrategy.php delete mode 100644 src/GreenCape/AllPairs/Strategy/Qict.php create mode 100644 src/GreenCape/AllPairs/Strategy/QictStrategy.php create mode 100644 src/autoload.php create mode 100644 tests/data/joomla.txt diff --git a/.gitignore b/.gitignore index 1c6e3f3..5b8b084 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ -autoload.php vendor/ original/ diff --git a/src/GreenCape/AllPairs/PairHash.php b/src/GreenCape/AllPairs/PairHash.php index dabbb1f..8d75810 100644 --- a/src/GreenCape/AllPairs/PairHash.php +++ b/src/GreenCape/AllPairs/PairHash.php @@ -2,30 +2,30 @@ namespace GreenCape\AllPairs; +use OutOfBoundsException; + class PairHash { - private $data = array(); + private $data = array(); - public function set($i, $j, $value) - { - if (!isset($this->data[min($i, $j)])) - { - $this->data[min($i, $j)] = array(); - } - $this->data[min($i, $j)][max($i, $j)] = $value; - } + public function set($i, $j, $value) + { + if (!isset($this->data[min($i, $j)])) { + $this->data[min($i, $j)] = array(); + } + $this->data[min($i, $j)][max($i, $j)] = $value; + } - public function get($i, $j) - { - if (!isset($this->data[min($i, $j)])) - { - throw new \OutOfBoundsException(); - } - if (!isset($this->data[min($i, $j)][max($i, $j)])) - { - throw new \OutOfBoundsException(); - } + public function get($i, $j) + { + if (!isset($this->data[min($i, $j)])) { + throw new OutOfBoundsException("No value for [$i,$j]"); + } + + if (!isset($this->data[min($i, $j)][max($i, $j)])) { + throw new OutOfBoundsException("No value for [$i,$j]"); + } - return $this->data[min($i, $j)][max($i, $j)]; - } + return $this->data[min($i, $j)][max($i, $j)]; + } } diff --git a/src/GreenCape/AllPairs/Parameter.php b/src/GreenCape/AllPairs/Parameter.php index af9d99b..d16c77b 100644 --- a/src/GreenCape/AllPairs/Parameter.php +++ b/src/GreenCape/AllPairs/Parameter.php @@ -2,153 +2,157 @@ namespace GreenCape\AllPairs; -class Parameter implements \ArrayAccess, \Countable, \Iterator +use ArrayAccess; +use Countable; +use Iterator; + +class Parameter implements ArrayAccess, Countable, Iterator { - private $label; - - private $values; - - private $current = 0; - - public function __construct(array $values, $label = null) - { - if (is_null($label)) - { - $label = uniqid(); - } - $this->label = $label; - $this->values = array_values($values); - } - - public function getLabel() - { - return $this->label; - } - - public function getValues() - { - return $this->values; - } - - /* - * ArrayAccess Interface - */ - - /** - * Whether a offset exists - * - * @param mixed $offset An offset to check for. - * - * @return boolean true on success or false on failure. - */ - public function offsetExists($offset) - { - return (array_key_exists($offset, $this->values)); - } - - /** - * Offset to retrieve - * - * @param mixed $offset The offset to retrieve. - * - * @return mixed Can return all value types. - */ - public function offsetGet($offset) - { - return $this->values[$offset]; - } - - /** - * Offset to set - * - * @param mixed $offset The offset to assign the value to. - * @param mixed $value The value to set. - * - * @return void - */ - public function offsetSet($offset, $value) - { - $this->values[$offset] = $value; - } - - /** - * Offset to unset - * - * @param mixed $offset The offset to unset. - * - * @return void - */ - public function offsetUnset($offset) - { - unset($this->values[$offset]); - } - - /* - * Countable Interface - */ - - /** - * Count elements of an object - * - * @return int The custom count as an integer. - */ - public function count() - { - return count($this->values); - } - - /* - * Iterator Interface - */ - - /** - * Return the current element - * - * @return mixed Can return any type. - */ - public function current() - { - return $this->values[$this->current]; - } - - /** - * Move forward to next element - * - * @return void - */ - public function next() - { - $this->current++; - } - - /** - * Return the key of the current element - * - * @return int - */ - public function key() - { - return $this->current; - } - - /** - * Checks if current position is valid - * - * @return boolean The return value will be casted to boolean and then evaluated. - * Returns true on success or false on failure. - */ - public function valid() - { - return isset($this->values[$this->current]); - } - - /** - * Rewind the Iterator to the first element - * - * @return void - */ - public function rewind() - { - $this->current = 0; - } + private $label; + + private $values; + + private $current = 0; + + public function __construct(array $values, $label = null) + { + if (is_null($label)) { + $label = uniqid('', true); + } + + $this->label = $label; + $this->values = array_values($values); + } + + public function getLabel() + { + return $this->label; + } + + public function getValues() + { + return $this->values; + } + + /* + * ArrayAccess Interface + */ + + /** + * Whether a offset exists + * + * @param mixed $offset An offset to check for. + * + * @return boolean true on success or false on failure. + */ + public function offsetExists($offset) + { + return (array_key_exists($offset, $this->values)); + } + + /** + * Offset to retrieve + * + * @param mixed $offset The offset to retrieve. + * + * @return mixed Can return all value types. + */ + public function offsetGet($offset) + { + return $this->values[$offset]; + } + + /** + * Offset to set + * + * @param mixed $offset The offset to assign the value to. + * @param mixed $value The value to set. + * + * @return void + */ + public function offsetSet($offset, $value) + { + $this->values[$offset] = $value; + } + + /** + * Offset to unset + * + * @param mixed $offset The offset to unset. + * + * @return void + */ + public function offsetUnset($offset) + { + unset($this->values[$offset]); + } + + /* + * Countable Interface + */ + + /** + * Count elements of an object + * + * @return int The custom count as an integer. + */ + public function count() + { + return count($this->values); + } + + /* + * Iterator Interface + */ + + /** + * Return the current element + * + * @return mixed Can return any type. + */ + public function current() + { + return $this->values[$this->current]; + } + + /** + * Move forward to next element + * + * @return void + */ + public function next() + { + $this->current++; + } + + /** + * Return the key of the current element + * + * @return int + */ + public function key() + { + return $this->current; + } + + /** + * Checks if current position is valid + * + * @return boolean The return value will be casted to boolean and then evaluated. + * Returns true on success or false on failure. + */ + public function valid() + { + return isset($this->values[$this->current]); + } + + /** + * Rewind the Iterator to the first element + * + * @return void + */ + public function rewind() + { + $this->current = 0; + } } diff --git a/src/GreenCape/AllPairs/Reader.php b/src/GreenCape/AllPairs/Reader.php index 4cf968f..f58b0ce 100644 --- a/src/GreenCape/AllPairs/Reader.php +++ b/src/GreenCape/AllPairs/Reader.php @@ -4,15 +4,15 @@ interface Reader { - /** - * @param string $labelDelimiter - * @param string $valueDelimiter - * - * @return Parameter[] - */ - public function getParameters(); + /** + * @param string $labelDelimiter + * @param string $valueDelimiter + * + * @return Parameter[] + */ + public function getParameters($labelDelimiter = ':', $valueDelimiter = ','); - public function getSubModules(); + public function getSubModules(); - public function getConstraints(); + public function getConstraints(); } diff --git a/src/GreenCape/AllPairs/Reader/FileReader.php b/src/GreenCape/AllPairs/Reader/FileReader.php index c5ab68c..407b476 100644 --- a/src/GreenCape/AllPairs/Reader/FileReader.php +++ b/src/GreenCape/AllPairs/Reader/FileReader.php @@ -4,8 +4,8 @@ class FileReader extends StringReader { - public function __construct($file) - { - parent::__construct(file_get_contents($file)); - } + public function __construct($file) + { + parent::__construct(file_get_contents($file)); + } } diff --git a/src/GreenCape/AllPairs/Reader/StringReader.php b/src/GreenCape/AllPairs/Reader/StringReader.php index 564fe08..add9190 100644 --- a/src/GreenCape/AllPairs/Reader/StringReader.php +++ b/src/GreenCape/AllPairs/Reader/StringReader.php @@ -2,127 +2,133 @@ namespace GreenCape\AllPairs; +use RuntimeException; + class StringReader implements Reader { - private $fileContent = array(); - private $parameters = array(); - private $subModules = array(); - private $constraints = array(); - - public function __construct($content) - { - $this->parse($content); - } - - /** - * @param string $labelDelimiter - * @param string $valueDelimiter - * - * @return Parameter[] - */ - public function getParameters($labelDelimiter = ':', $valueDelimiter = ',') - { - return $this->parameters; - } - - public function getSubModules() - { - return $this->subModules; - } - - public function getConstraints() - { - return $this->constraints; - } - - private function parse($content) - { - $labelDelimiter = preg_quote(':'); - $valueDelimiter = preg_quote(','); - - $OPT_SPACE = '\s*'; - $EOL = $OPT_SPACE . '(?:[\r\n]+|$)'; - $COLON = $OPT_SPACE . $labelDelimiter . $OPT_SPACE; - $COMMA = $OPT_SPACE . $valueDelimiter . $OPT_SPACE; - $WORD = '[^' . $labelDelimiter . $valueDelimiter . ']+?'; - $WORDS = '(' . $WORD . '(?:' . $COMMA . $WORD . ')*)'; - $COMMENT = '#' . $OPT_SPACE . '(.*)' . $EOL; - $LABEL = '(' . $WORD . ')' . $COLON; - - $PARAMETER = $LABEL . $WORDS; - $SUBMODULE = '\{' . $OPT_SPACE . $WORDS . $OPT_SPACE . '\}' . $OPT_SPACE . '@' . $OPT_SPACE . '(\d+)'; - - $CONDITION = 'IF\s*(.*?)\s*THEN\s*(.*?)\s*(?:ELSE\s*(.*?)\s*)?;'; - - $this->fileContent = preg_split($this->pattern($EOL), $content); - - $stage = 0; $buffer = ''; - foreach ($this->fileContent as $lineNo => $line) - { - if (!empty($buffer)) - { - $line = $buffer . ' ' . $line; - $buffer = ''; - } - if (preg_match($this->pattern($COMMENT), $line, $match)) - { - $line = str_replace(array_shift($match), '', $line); - } - $line = trim($line); - if (empty($line)) - { - continue; - } - if ($stage == 0 && preg_match($this->pattern($PARAMETER . $EOL), $line, $match)) - { - array_shift($match); - $label = array_shift($match); - $values = preg_split($this->pattern($COMMA), array_shift($match)); - $this->parameters[] = new Parameter($values, $label); - - continue; - } - if (($stage == 0 || $stage == 1) && preg_match($this->pattern($SUBMODULE), $line, $match)) - { - array_shift($match); - $values = preg_split($this->pattern($COMMA), array_shift($match)); - $order = array_shift($match); - $this->subModules[] = array( - 'order' => $order, - 'parameters' => $values - ); - $stage = 1; - - continue; - } - if (preg_match($this->pattern($CONDITION, 'i'), $line, $match)) - { - array_shift($match); - $condition = array_shift($match); - $then = array_shift($match); - $else = array_shift($match); - $this->constraints = array( - 'if' => $condition, - 'then' => $then, - 'else' => $else - ); - $stage = 2; - - continue; - } - if (preg_match($this->pattern('IF\s+\[', 'i'), $line)) - { - $buffer = $line; - - $stage = 2; - continue; - } - print("\n\nUnknown syntax in line {$lineNo}: »{$line}«\n\n"); - } - } - - private function pattern($pattern, $modifier = '') - { - return '~' . str_replace('~', '\~', $pattern) . '~' . $modifier; - } + private $parameters = array(); + private $subModules = array(); + private $constraints = array(); + + public function __construct($content) + { + $this->parse($content); + } + + /** + * @param string $labelDelimiter + * @param string $valueDelimiter + * + * @return Parameter[] + */ + public function getParameters($labelDelimiter = ':', $valueDelimiter = ',') + { + return $this->parameters; + } + + public function getSubModules() + { + return $this->subModules; + } + + public function getConstraints() + { + return $this->constraints; + } + + /** + * @param $content + */ + private function parse($content) + { + $labelDelimiter = preg_quote(':', '~'); + $valueDelimiter = preg_quote(',', '~'); + + $OPT_SPACE = '\s*'; + $EOL = $OPT_SPACE . '(?:[\r\n]+|$)'; + $COLON = $OPT_SPACE . $labelDelimiter . $OPT_SPACE; + $COMMA = $OPT_SPACE . $valueDelimiter . $OPT_SPACE; + $WORD = '[^' . $labelDelimiter . $valueDelimiter . ']+?'; + $WORDS = '(' . $WORD . '(?:' . $COMMA . $WORD . ')*)'; + $COMMENT = '#' . $OPT_SPACE . '(.*)' . $EOL; + $LABEL = '(' . $WORD . ')' . $COLON; + + $PARAMETER = $LABEL . $WORDS; + $SUBMODULE = '\{' . $OPT_SPACE . $WORDS . $OPT_SPACE . '\}' . $OPT_SPACE . '@' . $OPT_SPACE . '(\d+)'; + + $CONDITION = 'IF\s*(.*?)\s*THEN\s*(.*?)\s*(?:ELSE\s*(.*?)\s*)?;'; + + $fileContent = preg_split($this->pattern($EOL), $content); + + $stage = 0; + $buffer = ''; + + foreach ($fileContent as $lineNo => $line) { + if (!empty($buffer)) { + $line = $buffer . ' ' . $line; + $buffer = ''; + } + + if (preg_match($this->pattern($COMMENT), $line, $match)) { + $line = str_replace(array_shift($match), '', $line); + } + + $line = trim($line); + + if (empty($line)) { + continue; + } + + if ($stage === 0 && preg_match($this->pattern($PARAMETER . $EOL), $line, $match)) { + array_shift($match); + $label = array_shift($match); + $values = preg_split($this->pattern($COMMA), array_shift($match)); + $this->parameters[] = new Parameter($values, $label); + + continue; + } + + if (($stage === 0 || $stage === 1) && preg_match($this->pattern($SUBMODULE), $line, $match)) { + array_shift($match); + $values = preg_split($this->pattern($COMMA), array_shift($match)); + $order = array_shift($match); + $this->subModules[] = array( + 'order' => $order, + 'parameters' => $values, + ); + $stage = 1; + + continue; + } + + if (preg_match($this->pattern($CONDITION, 'i'), $line, $match)) { + array_shift($match); + $condition = array_shift($match); + $then = array_shift($match); + $else = array_shift($match); + $this->constraints = array( + 'if' => $condition, + 'then' => $then, + 'else' => $else, + ); + $stage = 2; + + continue; + } + + if (preg_match($this->pattern('IF\s+\[', 'i'), $line)) { + $buffer = $line; + + $stage = 2; + continue; + } + + throw new RuntimeException("Unknown syntax in line {$lineNo}: »{$line}«"); + } + } + + private function pattern($pattern, $modifier = '') + { + return '~' . str_replace('~', '\~', $pattern) . '~' . $modifier; + } } diff --git a/src/GreenCape/AllPairs/Strategy.php b/src/GreenCape/AllPairs/Strategy.php index 7c99414..69a116c 100644 --- a/src/GreenCape/AllPairs/Strategy.php +++ b/src/GreenCape/AllPairs/Strategy.php @@ -4,11 +4,11 @@ interface Strategy { - /** - * @param Parameter[] $parameterList - * @param int $order - * - * @return array - */ - public function combine($parameterList, $order = 2); + /** + * @param Parameter[] $parameterList + * @param int $order + * + * @return array + */ + public function combine($parameterList, $order = 2); } diff --git a/src/GreenCape/AllPairs/Strategy/Default.php b/src/GreenCape/AllPairs/Strategy/Default.php deleted file mode 100644 index 0c2c94a..0000000 --- a/src/GreenCape/AllPairs/Strategy/Default.php +++ /dev/null @@ -1,218 +0,0 @@ -generateTestSets($parameterList); - } - - /** - * @param Parameter[] $parameterList - * - * @return array - */ - private function generateTestSets($parameterList) - { - $this->tokenizeParameterList($parameterList); - - foreach ($this->tokenizedParameterList as $parameterPosition1 => $parameter1) - { - foreach ($this->tokenizedParameterList as $parameterPosition2 => $parameter2) - { - if ($parameterPosition2 <= $parameterPosition1) - { - continue; - } - foreach ($parameter1 as $value1) - { - foreach ($parameter2 as $value2) - { - $this->createPair($value1, $value2); - } - } - } - } - - $testSets = array(); - foreach ($this->tokenizedParameterList[$this->ordering[0]] as $value1) - { - foreach ($this->tokenizedParameterList[$this->ordering[1]] as $value2) - { - $testSet = array_fill(0, count($this->tokenizedParameterList), null); - $testSet[$this->ordering[0]] = $value1; - $testSet[$this->ordering[1]] = $value2; - - $testSets[] = $this->completeTestset($testSet); - } - } - - foreach ($this->tokenizedParameterList as $parameterPosition1 => $parameter1) - { - foreach ($this->tokenizedParameterList as $parameterPosition2 => $parameter2) - { - if ($parameterPosition2 <= $parameterPosition1) - { - continue; - } - foreach ($parameter1 as $value1) - { - foreach ($parameter2 as $value2) - { - $hash = $this->hash(array($value1, $value2)); - $useCount = $this->tuples[$hash]['useCount']; - if ($useCount == 0) - { - $testSet = array_fill(0, count($this->tokenizedParameterList), null); - $testSet[$this->token[$value1]['parameter']] = $value1; - $testSet[$this->token[$value2]['parameter']] = $value2; - $testSets[] = $this->completeTestset($testSet); - } - } - } - } - } - - /* - usort($testSets, function($a, $b) { - for ($i = 0; $i < count($a); $i++) - { - if ($a[$i] != $b[$i]) - { - return strcmp($a[$i], $b[$i]); - } - } - return 0; - }); - */ - - $result = array(); - foreach ($testSets as $set) - { - $parameters = array(); - for ($j = 0; $j < count($set); ++$j) - { - $parameters[$this->label[$j]] = $this->token[$set[$j]]['value']; - } - $result[] = $parameters; - } - - return $result; - } - - private function hash(array $a) - { - sort($a); - - return '{' . implode(', ', $a) . '}'; - } - - /** - * @param $testSet - * - * @return array - */ - private function completeTestset($testSet) - { - for ($position = 0; $position < count($this->ordering); $position++) - { - if (!is_null($testSet[$this->ordering[$position]])) - { - continue; - } - $threshold = PHP_INT_MAX; - $bestValue = null; - foreach ($this->tokenizedParameterList[$this->ordering[$position]] as $value) - { - $pairScore = 0; - for ($i = 0; $i < $position; $i++) - { - $pairScore += $this->tuples[$this->hash(array( - $testSet[$this->ordering[$i]], - $value - ))]['useCount']; - } - $score = $pairScore; - if ($score < $threshold) - { - $threshold = $score; - $bestValue = $value; - } - } - $testSet[$this->ordering[$position]] = $bestValue; - } - $this->updateUseCount($testSet); - - return $testSet; - } - - /** - * @param $testSet - * - * @return int - */ - private function updateUseCount($testSet) - { - for ($i = 0; $i < count($testSet) - 1; $i++) - { - for ($j = $i + 1; $j < count($testSet); $j++) - { - $this->tuples[$this->hash(array($testSet[$i], $testSet[$j]))]['useCount']++; - } - } - } - - /** - * @param $parameterList - */ - private function tokenizeParameterList($parameterList) - { - $tokenKey = 0; - $ordering = array(); - $this->tokenizedParameterList = array(); - foreach ($parameterList as $parameterPosition => $parameter) - { - $this->label[$parameterPosition] = $parameter->getLabel(); - $ordering[$parameterPosition] = count($parameter); - foreach ($parameter as $valuePosition => $value) - { - $this->token[$tokenKey] = array( - 'value' => $value, - 'parameter' => $parameterPosition - ); - - $this->tokenizedParameterList[$parameterPosition][$valuePosition] = $tokenKey; - $tokenKey++; - } - } - arsort($ordering); - $this->ordering = array_keys($ordering); - } - - /** - * @param $value1 - * @param $value2 - */ - private function createPair($value1, $value2) - { - $pair = array($value1, $value2); - $this->tuples[$this->hash($pair)] = array( - 'value' => $pair, - 'useCount' => 0 - ); - } -} diff --git a/src/GreenCape/AllPairs/Strategy/DefaultStrategy.php b/src/GreenCape/AllPairs/Strategy/DefaultStrategy.php new file mode 100644 index 0000000..414ff1a --- /dev/null +++ b/src/GreenCape/AllPairs/Strategy/DefaultStrategy.php @@ -0,0 +1,201 @@ +generateTestSets($parameterList); + } + + /** + * @param Parameter[] $parameterList + * + * @return array + */ + private function generateTestSets($parameterList) + { + $this->tokenizeParameterList($parameterList); + + foreach ($this->tokenizedParameterList as $parameterPosition1 => $parameter1) { + foreach ($this->tokenizedParameterList as $parameterPosition2 => $parameter2) { + if ($parameterPosition2 <= $parameterPosition1) { + continue; + } + + foreach ($parameter1 as $value1) { + foreach ($parameter2 as $value2) { + $this->createPair($value1, $value2); + } + } + } + } + + $testSets = array(); + + foreach ($this->tokenizedParameterList[$this->ordering[0]] as $value1) { + foreach ($this->tokenizedParameterList[$this->ordering[1]] as $value2) { + $testSet = array_fill(0, count($this->tokenizedParameterList), null); + $testSet[$this->ordering[0]] = $value1; + $testSet[$this->ordering[1]] = $value2; + + $testSets[] = $this->completeTestset($testSet); + } + } + + foreach ($this->tokenizedParameterList as $parameterPosition1 => $parameter1) { + foreach ($this->tokenizedParameterList as $parameterPosition2 => $parameter2) { + if ($parameterPosition2 <= $parameterPosition1) { + continue; + } + + foreach ($parameter1 as $value1) { + foreach ($parameter2 as $value2) { + $hash = $this->hash(array($value1, $value2)); + $useCount = $this->tuples[$hash]['useCount']; + + if ($useCount === 0) { + $testSet = array_fill(0, + count($this->tokenizedParameterList), + null); + $testSet[$this->token[$value1]['parameter']] = $value1; + $testSet[$this->token[$value2]['parameter']] = $value2; + $testSets[] = $this->completeTestset($testSet); + } + } + } + } + } + + /* + usort($testSets, function($a, $b) { + for ($i = 0; $i < count($a); $i++) + { + if ($a[$i] != $b[$i]) + { + return strcmp($a[$i], $b[$i]); + } + } + return 0; + }); + */ + + $result = array(); + foreach ($testSets as $set) { + $parameters = array(); + for ($j = 0, $jMax = count($set); $j < $jMax; ++$j) { + $parameters[$this->label[$j]] = $this->token[$set[$j]]['value']; + } + $result[] = $parameters; + } + + return $result; + } + + private function hash(array $a) + { + sort($a); + + return '{' . implode(', ', $a) . '}'; + } + + /** + * @param $testSet + * + * @return array + */ + private function completeTestset($testSet) + { + foreach ($this->ordering as $position => $positionValue) { + if (!is_null($testSet[$positionValue])) { + continue; + } + $threshold = PHP_INT_MAX; + $bestValue = null; + foreach ($this->tokenizedParameterList[$positionValue] as $value) { + $pairScore = 0; + for ($i = 0; $i < $position; $i++) { + $pairScore += $this->tuples[$this->hash(array( + $testSet[$this->ordering[$i]], + $value, + ))]['useCount']; + } + $score = $pairScore; + if ($score < $threshold) { + $threshold = $score; + $bestValue = $value; + } + } + $testSet[$positionValue] = $bestValue; + } + $this->updateUseCount($testSet); + + return $testSet; + } + + /** + * @param $testSet + */ + private function updateUseCount($testSet) + { + for ($i = 0; $i < count($testSet) - 1; $i++) { + for ($j = $i + 1, $jMax = count($testSet); $j < $jMax; $j++) { + $this->tuples[$this->hash(array($testSet[$i], $testSet[$j]))]['useCount']++; + } + } + } + + /** + * @param $parameterList + */ + private function tokenizeParameterList($parameterList) + { + $tokenKey = 0; + $ordering = array(); + $this->tokenizedParameterList = array(); + + foreach ($parameterList as $parameterPosition => $parameter) { + $this->label[$parameterPosition] = $parameter->getLabel(); + $ordering[$parameterPosition] = count($parameter); + + foreach ($parameter as $valuePosition => $value) { + $this->token[$tokenKey] = array( + 'value' => $value, + 'parameter' => $parameterPosition, + ); + + $this->tokenizedParameterList[$parameterPosition][$valuePosition] = $tokenKey; + $tokenKey++; + } + } + + arsort($ordering); + $this->ordering = array_keys($ordering); + } + + /** + * @param $value1 + * @param $value2 + */ + private function createPair($value1, $value2) + { + $pair = array($value1, $value2); + $this->tuples[$this->hash($pair)] = array( + 'value' => $pair, + 'useCount' => 0, + ); + } +} diff --git a/src/GreenCape/AllPairs/Strategy/Qict.php b/src/GreenCape/AllPairs/Strategy/Qict.php deleted file mode 100644 index 90b4a0d..0000000 --- a/src/GreenCape/AllPairs/Strategy/Qict.php +++ /dev/null @@ -1,289 +0,0 @@ -getLabel(); - $legalValues[] = $values; - } - - // Process the legalValues array to populate the allPairsDisplay & unusedPairs & unusedPairsSearch collections - $currPair = 0; - for ($i = 0; $i <= count($legalValues) - 2; ++$i) - { - for ($j = $i + 1; $j <= count($legalValues) - 1; ++$j) - { - $firstRow = $legalValues[$i]; - $secondRow = $legalValues[$j]; - for ($x = 0; $x < count($firstRow); ++$x) - { - for ($y = 0; $y < count($secondRow); ++$y) - { - $allPairsDisplay[$currPair][0] = $firstRow[$x]; // Pair first value - $allPairsDisplay[$currPair][1] = $secondRow[$y]; // Pair second value - - $aPair = array( - $firstRow[$x], - $secondRow[$y] - ); - $unusedPairs[] = $aPair; - - $unusedPairsSearch[$this->hash($firstRow[$x], $secondRow[$y])] = 1; - - ++$currPair; - } - } - } - } - - // Process legalValues to populate parameterPositions array - $k = 0; // points into parameterPositions - for ($i = 0; $i < count($legalValues); ++$i) - { - $curr = $legalValues[$i]; - for ($j = 0; $j < count($curr); ++$j) - { - $parameterPositions[$k++] = $i; - } - } - - // Process allPairsDisplay to determine unusedCounts array - for ($i = 0; $i < count($allPairsDisplay); ++$i) - { - @$unusedCounts[$allPairsDisplay[$i][0]]++; - @$unusedCounts[$allPairsDisplay[$i][1]]++; - } - - while (count($unusedPairs) > 0) - { - $candidateSets = array(); // holds candidate testSets - - for ($candidate = 0; $candidate < $poolSize; ++$candidate) - { - $testSet = array(); // make an empty candidate testSet - - // Pick "best" unusedPair -- the pair which has the sum of the most unused values - $bestWeight = 0; - $indexOfBestPair = 0; - for ($i = 0; $i < count($unusedPairs); ++$i) - { - $curr = $unusedPairs[$i]; - $weight = $unusedCounts[$curr[0]] + $unusedCounts[$curr[1]]; - if ($weight > $bestWeight) - { - $bestWeight = $weight; - $indexOfBestPair = $i; - } - } - - $best = $unusedPairs[$indexOfBestPair]; - - $firstPos = $parameterPositions[$best[0]]; // position of first value from best unused pair - $secondPos = $parameterPositions[$best[1]]; - - // Generate a random order to fill parameter positions - $ordering = array(); - for ($i = 0; $i < $numberParameters; ++$i) - { - $ordering[$i] = $i; - } - - // Put firstPos at ordering[0] && secondPos at ordering[1] - $ordering[0] = $firstPos; - $ordering[$firstPos] = 0; - - $t = $ordering[1]; - $ordering[1] = $secondPos; - $ordering[$secondPos] = $t; - - // Shuffle ordering[2] thru ordering[last] - for ($i = 2; $i < count($ordering); $i++) - { - // Knuth shuffle. start at i=2 because want first two slots left alone - $j = rand($i, $numberParameters - 1); - $temp = $ordering[$j]; - $ordering[$j] = $ordering[$i]; - $ordering[$i] = $temp; - } - - // Place two parameter values from best unused pair into candidate testSet - $testSet[$firstPos] = $best[0]; - $testSet[$secondPos] = $best[1]; - - // For remaining parameter positions in candidate testSet, try each possible legal value, picking the one which captures the most unused pairs . . . - for ($i = 2; $i < $numberParameters; ++$i) - { // start at 2 because first two parameter have been placed - $currPos = $ordering[$i]; - $possibleValues = $legalValues[$currPos]; - - $highestCount = 0; // highest of these counts - $bestJ = 0; // index of the possible value which yields the highestCount - for ($j = 0; $j < count($possibleValues); ++$j) - { // examine pairs created by each possible value and each parameter value already there - $currentCount = 0; // count the unusedPairs grabbed by adding a possible value - for ($p = 0; $p < $i; ++$p) - { // parameters already placed - $candidatePair = array( - $possibleValues[$j], - $testSet[$ordering[$p]] - ); - - if ($unusedPairsSearch[$this->hash($candidatePair[0], $candidatePair[1])] == 1) - { - ++$currentCount; - } - } - if ($currentCount > $highestCount) - { - $highestCount = $currentCount; - $bestJ = $j; - } - } - - // Place the value which captured the most pairs - $testSet[$currPos] = $possibleValues[$bestJ]; - } - - // Add candidate testSet to candidateSets array - $candidateSets[$candidate] = $testSet; - } - - // Iterate through candidateSets to determine the best candidate - $indexOfBestCandidate = rand(0, count($candidateSets) - 1); // pick a random index as best - $mostPairsCaptured = $this->numberPairsCaptured($candidateSets[$indexOfBestCandidate], $unusedPairsSearch); - - for ($i = 0; $i < count($candidateSets); ++$i) - { - $pairsCaptured = $this->numberPairsCaptured($candidateSets[$i], $unusedPairsSearch); - if ($pairsCaptured > $mostPairsCaptured) - { - $mostPairsCaptured = $pairsCaptured; - $indexOfBestCandidate = $i; - } - } - - // Add the best candidate to the main testSets List - $bestTestSet = $candidateSets[$indexOfBestCandidate]; - $testSets[] = $bestTestSet; - - // Now perform all updates - for ($i = 0; $i <= $numberParameters - 2; ++$i) - { - for ($j = $i + 1; $j <= $numberParameters - 1; ++$j) - { - $v1 = $bestTestSet[$i]; // value 1 of newly added pair - $v2 = $bestTestSet[$j]; // value 2 of newly added pair - - --$unusedCounts[$v1]; - --$unusedCounts[$v2]; - - $unusedPairsSearch[$this->hash($v1, $v2)] = 0; - - for ($p = 0; $p < count($unusedPairs); ++$p) - { - $curr = $unusedPairs[$p]; - - if ($curr[0] == $v1 && $curr[1] == $v2) - { - unset($unusedPairs[$p]); - $unusedPairs = array_values($unusedPairs); - } - } - } - } - } - - $result = array(); - foreach ($testSets as $set) - { - $parameters = array(); - for ($j = 0; $j < count($set); ++$j) - { - $parameters[$labels[$j]] = $parameterValues[$set[$j]]; - } - $result[] = $parameters; - } - - return $result; - } - - private function numberPairsCaptured($ts, $unusedPairsSearch) // number of unused pairs captured by testSet ts - { - $ans = 0; - for ($i = 0; $i <= count($ts) - 2; ++$i) - { - for ($j = $i + 1; $j <= count($ts) - 1; ++$j) - { - if ($unusedPairsSearch[$this->hash($ts[$i], $ts[$j])] == 1) - { - ++$ans; - } - } - } - - return $ans; - } - - private function hash($a, $b) - { - $values = array($a, $b); - sort($values); - - return '{' . implode(', ', $values) . '}'; - } -} diff --git a/src/GreenCape/AllPairs/Strategy/QictStrategy.php b/src/GreenCape/AllPairs/Strategy/QictStrategy.php new file mode 100644 index 0000000..9c769c2 --- /dev/null +++ b/src/GreenCape/AllPairs/Strategy/QictStrategy.php @@ -0,0 +1,261 @@ +getLabel(); + $legalValues[] = $values; + } + + // Process the legalValues array to populate the allPairsDisplay & unusedPairs & unusedPairsSearch collections + $currPair = 0; + + for ($i = 0; $i <= count($legalValues) - 2; ++$i) { + for ($j = $i + 1; $j <= count($legalValues) - 1; ++$j) { + $firstRow = $legalValues[$i]; + $secondRow = $legalValues[$j]; + + foreach ($firstRow as $x => $xValue) { + foreach ($secondRow as $y => $yValue) { + $allPairsDisplay[$currPair][0] = $xValue; // Pair first value + $allPairsDisplay[$currPair][1] = $yValue; // Pair second value + + $aPair = array( + $firstRow[$x], + $secondRow[$y], + ); + $unusedPairs[] = $aPair; + + $unusedPairsSearch[$this->hash($xValue, $yValue)] = 1; + + ++$currPair; + } + } + } + } + + // Process legalValues to populate parameterPositions array + $k = 0; // points into parameterPositions + foreach ($legalValues as $i => $iValue) { + $curr = $iValue; + for ($j = 0, $jMax = count($curr); $j < $jMax; ++$j) { + $parameterPositions[$k++] = $i; + } + } + + // Process allPairsDisplay to determine unusedCounts array + foreach ($allPairsDisplay as $iValue) { + @$unusedCounts[$iValue[0]]++; + @$unusedCounts[$iValue[1]]++; + } + + while (count($unusedPairs) > 0) { + $candidateSets = array(); // holds candidate testSets + + for ($candidate = 0; $candidate < $poolSize; ++$candidate) { + $testSet = array(); // make an empty candidate testSet + + // Pick "best" unusedPair -- the pair which has the sum of the most unused values + $bestWeight = 0; + $indexOfBestPair = 0; + foreach ($unusedPairs as $i => $curr) { + $weight = $unusedCounts[$curr[0]] + $unusedCounts[$curr[1]]; + if ($weight > $bestWeight) { + $bestWeight = $weight; + $indexOfBestPair = $i; + } + } + + $best = $unusedPairs[$indexOfBestPair]; + + $firstPos = $parameterPositions[$best[0]]; // position of first value from best unused pair + $secondPos = $parameterPositions[$best[1]]; + + // Generate a random order to fill parameter positions + $ordering = array(); + for ($i = 0; $i < $numberParameters; ++$i) { + $ordering[$i] = $i; + } + + // Put firstPos at ordering[0] && secondPos at ordering[1] + $ordering[0] = $firstPos; + $ordering[$firstPos] = 0; + + $t = $ordering[1]; + $ordering[1] = $secondPos; + $ordering[$secondPos] = $t; + + // Shuffle ordering[2] thru ordering[last] + for ($i = 2, $iMax = count($ordering); $i < $iMax; $i++) { + // Knuth shuffle. start at i=2 because want first two slots left alone + $j = mt_rand($i, $numberParameters - 1); + $temp = $ordering[$j]; + $ordering[$j] = $ordering[$i]; + $ordering[$i] = $temp; + } + + // Place two parameter values from best unused pair into candidate testSet + $testSet[$firstPos] = $best[0]; + $testSet[$secondPos] = $best[1]; + + // For remaining parameter positions in candidate testSet, try each possible legal value, picking the one which captures the most unused pairs . . . + for ($i = 2; $i < $numberParameters; ++$i) { // start at 2 because first two parameter have been placed + $currPos = $ordering[$i]; + $possibleValues = $legalValues[$currPos]; + + $highestCount = 0; // highest of these counts + $bestJ = 0; // index of the possible value which yields the highestCount + + foreach ($possibleValues as $j => $jValue) { // examine pairs created by each possible value and each parameter value already there + $currentCount = 0; // count the unusedPairs grabbed by adding a possible value + + for ($p = 0; $p < $i; ++$p) { // parameters already placed + $candidatePair = array( + $possibleValues[$j], + $testSet[$ordering[$p]], + ); + + if ($unusedPairsSearch[$this->hash($candidatePair[0], $candidatePair[1])] === 1) { + ++$currentCount; + } + } + + if ($currentCount > $highestCount) { + $highestCount = $currentCount; + $bestJ = $j; + } + } + + // Place the value which captured the most pairs + $testSet[$currPos] = $possibleValues[$bestJ]; + } + + // Add candidate testSet to candidateSets array + $candidateSets[$candidate] = $testSet; + } + + // Iterate through candidateSets to determine the best candidate + $indexOfBestCandidate = mt_rand(0, count($candidateSets) - 1); // pick a random index as best + $mostPairsCaptured = $this->numberPairsCaptured($candidateSets[$indexOfBestCandidate], + $unusedPairsSearch); + + foreach ($candidateSets as $i => $iValue) { + $pairsCaptured = $this->numberPairsCaptured($iValue, $unusedPairsSearch); + + if ($pairsCaptured > $mostPairsCaptured) { + $mostPairsCaptured = $pairsCaptured; + $indexOfBestCandidate = $i; + } + } + + // Add the best candidate to the main testSets List + $bestTestSet = $candidateSets[$indexOfBestCandidate]; + $testSets[] = $bestTestSet; + + // Now perform all updates + for ($i = 0; $i <= $numberParameters - 2; ++$i) { + for ($j = $i + 1; $j <= $numberParameters - 1; ++$j) { + $v1 = $bestTestSet[$i]; // value 1 of newly added pair + $v2 = $bestTestSet[$j]; // value 2 of newly added pair + + --$unusedCounts[$v1]; + --$unusedCounts[$v2]; + + $unusedPairsSearch[$this->hash($v1, $v2)] = 0; + + foreach ($unusedPairs as $p => $pValue) { + $curr = $pValue; + + if ($curr[0] === $v1 && $curr[1] === $v2) { + unset($unusedPairs[$p]); + $unusedPairs = array_values($unusedPairs); + } + } + } + } + } + + $result = array(); + foreach ($testSets as $set) { + $parameters = array(); + for ($j = 0, $jMax = count($set); $j < $jMax; ++$j) { + $parameters[$labels[$j]] = $parameterValues[$set[$j]]; + } + $result[] = $parameters; + } + + return $result; + } + + private function numberPairsCaptured($ts, $unusedPairsSearch) // number of unused pairs captured by testSet ts + { + $ans = 0; + for ($i = 0; $i <= count($ts) - 2; ++$i) { + for ($j = $i + 1; $j <= count($ts) - 1; ++$j) { + if ($unusedPairsSearch[$this->hash($ts[$i], $ts[$j])] === 1) { + ++$ans; + } + } + } + + return $ans; + } + + private function hash($a, $b) + { + $values = array($a, $b); + sort($values); + + return '{' . implode(', ', $values) . '}'; + } +} diff --git a/src/GreenCape/AllPairs/Writer.php b/src/GreenCape/AllPairs/Writer.php index 56fd190..f92ac00 100644 --- a/src/GreenCape/AllPairs/Writer.php +++ b/src/GreenCape/AllPairs/Writer.php @@ -4,5 +4,5 @@ interface Writer { - public function write($result); + public function write($result); } diff --git a/src/GreenCape/AllPairs/Writer/ConsoleWriter.php b/src/GreenCape/AllPairs/Writer/ConsoleWriter.php index be40a68..befdfdd 100644 --- a/src/GreenCape/AllPairs/Writer/ConsoleWriter.php +++ b/src/GreenCape/AllPairs/Writer/ConsoleWriter.php @@ -2,19 +2,19 @@ namespace GreenCape\AllPairs; -class ConsoleWriter implements Writer +class ConsoleWriter implements Writer { - protected $fieldSeparator = "\t"; - protected $lineSeparator = "\n"; + protected $fieldSeparator = "\t"; + protected $lineSeparator = "\n"; - public function write($result) - { - print(implode($this->fieldSeparator, array_keys($result[0])) . $this->lineSeparator); - foreach ((array) $result as $set) - { - print(implode($this->fieldSeparator, (array) $set) . $this->lineSeparator); - } + public function write($result) + { + print(implode($this->fieldSeparator, array_keys($result[0])) . $this->lineSeparator); - return $result; - } + foreach ((array) $result as $set) { + print(implode($this->fieldSeparator, (array) $set) . $this->lineSeparator); + } + + return $result; + } } diff --git a/src/GreenCape/AllPairs/Writer/VardumpWriter.php b/src/GreenCape/AllPairs/Writer/VardumpWriter.php index c6828d5..fc11180 100644 --- a/src/GreenCape/AllPairs/Writer/VardumpWriter.php +++ b/src/GreenCape/AllPairs/Writer/VardumpWriter.php @@ -2,12 +2,13 @@ namespace GreenCape\AllPairs; -class VardumpWriter implements Writer +class VardumpWriter implements Writer { - public function write($result) - { - print_r($result); + public function write($result) + { + /** @noinspection ForgottenDebugOutputInspection */ + print_r($result); - return $result; - } + return $result; + } } diff --git a/src/GreenCape/Combinator.php b/src/GreenCape/Combinator.php index d0be31e..64d93f8 100644 --- a/src/GreenCape/Combinator.php +++ b/src/GreenCape/Combinator.php @@ -4,113 +4,100 @@ class Combinator { - /** @var Reader */ - private $reader; - - /** @var Writer */ - private $writer; - - /** @var Strategy */ - private $strategy; - - public function __construct(Strategy $strategy, Reader $reader, Writer $writer = null) - { - $this->strategy = $strategy; - $this->reader = $reader; - $this->writer = $writer; - } - - public function combine() - { - $parameters = $this->reader->getParameters(); - $subModules = $this->reader->getSubModules(); - $moduleParameters = array(); - $moduleId = array(); - - // Compute subsets - $subSets = array(); - foreach ($subModules as $moduleIndex => $module) - { - $moduleLabel = uniqid('Module'); - $moduleId[$moduleLabel] = $moduleIndex; - $subParameters = array(); - foreach ($parameters as $parameterIndex => $parameter) - { - if (in_array($parameter->getLabel(), $module['parameters'])) - { - $subParameters[] = $parameter; - $moduleParameters[$moduleIndex][] = $parameter; - unset($parameters[$parameterIndex]); - } - } - $subSet = $this->strategy->combine($subParameters, $module['order']); - $subSets[$moduleIndex] = $subSet; - $parameters[] = new Parameter(array_keys($subSet), $moduleLabel); - } - - // Generate testsets - $testSets = $this->strategy->combine(array_values($parameters), 2); - - if (!empty($moduleId)) - { - // Resolve subsets - $resolvedSets = array(); - foreach ($testSets as $set) - { - $resolved = array(); - foreach ($set as $label => $value) - { - if (isset($moduleId[$label])) - { - $resolved += $subSets[$moduleId[$label]][$value]; - } - } - $resolvedSets[] = $resolved; - } - $testSets = $resolvedSets; - } - - // Reduce - $labels = array_keys($testSets[0]); - print("Labels: " . print_r($labels, true)); - - for ($i = 1; $i < count($testSets); ++$i) - { - $remove = true; - $debug = "Set $i: {" . implode(', ', $testSets[$i]) . "}:\n";; - for ($x = 0; $x < count($labels) - 1; ++$x) - { - for ($y = $x + 1; $y < count($labels); ++$y) - { - $found = false; - for ($j = 0; $j < $i; ++$j) - { - if (!isset($testSets[$j])) - { - continue; - } - if ($testSets[$i][$labels[$x]] == $testSets[$j][$labels[$x]] && $testSets[$i][$labels[$y]] == $testSets[$j][$labels[$y]]) - { - $debug .= "{" . $testSets[$i][$labels[$x]] . ", " . $testSets[$i][$labels[$y]] . "} found in set $j\n"; - $found = true; - break; - } - } - if (!$found) - { - $remove = false; - break 2; - } - } - } - if ($remove) - { - // All pairs were found, remove testSet - print($debug); - unset($testSets[$i]); - } - } - - return is_null($this->writer) ? $testSets : $this->writer->write($testSets); - } + /** @var Reader */ + private $reader; + + /** @var Writer */ + private $writer; + + /** @var Strategy */ + private $strategy; + + public function __construct(Strategy $strategy, Reader $reader, Writer $writer = null) + { + $this->strategy = $strategy; + $this->reader = $reader; + $this->writer = $writer; + } + + public function combine() + { + $parameters = $this->reader->getParameters(); + $subModules = $this->reader->getSubModules(); + $moduleId = array(); + + // Compute subsets + $subSets = array(); + + foreach ($subModules as $moduleIndex => $module) { + $moduleLabel = uniqid('Module', true); + $moduleId[$moduleLabel] = $moduleIndex; + $subParameters = array(); + + foreach ($parameters as $parameterIndex => $parameter) { + if (in_array($parameter->getLabel(), $module['parameters'], true)) { + $subParameters[] = $parameter; + unset($parameters[$parameterIndex]); + } + } + $subSet = $this->strategy->combine($subParameters, $module['order']); + $subSets[$moduleIndex] = $subSet; + $parameters[] = new Parameter(array_keys($subSet), $moduleLabel); + } + + // Generate testsets + $testSets = $this->strategy->combine(array_values($parameters), 2); + + if (!empty($moduleId)) { + // Resolve subsets + $resolvedSets = array(); + + foreach ($testSets as $set) { + $resolved = array(); + + foreach ($set as $label => $value) { + if (isset($moduleId[$label])) { + $resolved += $subSets[$moduleId[$label]][$value]; + } + } + + $resolvedSets[] = $resolved; + } + + $testSets = $resolvedSets; + } + + // Reduce + $labels = array_keys($testSets[0]); + print("Labels: " . print_r($labels, true)); + + for ($i = 1, $iMax = count($testSets); $i < $iMax; ++$i) { + $remove = true; + + for ($x = 0; $x < count($labels) - 1; ++$x) { + for ($y = $x + 1, $yMax = count($labels); $y < $yMax; ++$y) { + $found = false; + for ($j = 0; $j < $i; ++$j) { + if (!isset($testSets[$j])) { + continue; + } + if ($testSets[$i][$labels[$x]] === $testSets[$j][$labels[$x]] && $testSets[$i][$labels[$y]] === $testSets[$j][$labels[$y]]) { + $found = true; + break; + } + } + if (!$found) { + $remove = false; + break 2; + } + } + } + if ($remove) { + // All pairs were found, remove testSet + unset($testSets[$i]); + } + } + + return is_null($this->writer) ? $testSets : $this->writer->write($testSets); + } } diff --git a/src/allpairs.php b/src/allpairs.php index 0606f3b..d5ad0b2 100644 --- a/src/allpairs.php +++ b/src/allpairs.php @@ -3,30 +3,27 @@ require_once __DIR__ . '/autoload.php'; require_once __DIR__ . '/../vendor/autoload.php'; -$base = '..'; +$base = '..'; $files = array( - '/tests/data/server.txt', - '/original/testData.txt', - '/tests/data/prime.txt', - '/tests/data/volume.txt', - '/tests/data/hardware.txt', -# '/tests/data/big.txt', - '/tests/data/joomla.txt', + '/tests/data/server.txt', + '/original/testData.txt', + '/tests/data/prime.txt', + '/tests/data/volume.txt', + '/tests/data/hardware.txt', + '/tests/data/big.txt', + '/tests/data/joomla.txt', ); -foreach ($files as $file) -{ - print("\nBegin pair-wise test set generation for {$file}\n\n"); - $time = microtime(true); - $allPairs = new GreenCape\AllPairs\Combinator( - new GreenCape\AllPairs\QictStrategy(), - new GreenCape\AllPairs\FileReader($base . $file), - new GreenCape\AllPairs\ConsoleWriter() - ); - $result = $allPairs->combine(); - $time = microtime(true) - $time; +foreach ($files as $file) { + print("\nBegin pair-wise test set generation for {$file}\n\n"); + $time = microtime(true); + $allPairs = new GreenCape\AllPairs\Combinator(new GreenCape\AllPairs\DefaultStrategy(), + new GreenCape\AllPairs\FileReader($base . $file), + new GreenCape\AllPairs\ConsoleWriter()); + $result = $allPairs->combine(); + $time = microtime(true) - $time; - // Display results - print("\nGenerated " . count($result) . " test sets in {$time} seconds.\n"); - unset($allPairs, $result, $time); + // Display results + print("\nGenerated " . count($result) . " test sets in {$time} seconds.\n"); + unset($allPairs, $result, $time); } diff --git a/src/autoload.php b/src/autoload.php new file mode 100644 index 0000000..05f9e96 --- /dev/null +++ b/src/autoload.php @@ -0,0 +1,30 @@ + '/GreenCape/Combinator.php', + 'greencape\\allpairs\\consolewriter' => '/GreenCape/AllPairs/Writer/ConsoleWriter.php', + 'greencape\\allpairs\\defaultstrategy' => '/GreenCape/AllPairs/Strategy/DefaultStrategy.php', + 'greencape\\allpairs\\filereader' => '/GreenCape/AllPairs/Reader/FileReader.php', + 'greencape\\allpairs\\pairhash' => '/GreenCape/AllPairs/PairHash.php', + 'greencape\\allpairs\\parameter' => '/GreenCape/AllPairs/Parameter.php', + 'greencape\\allpairs\\qictstrategy' => '/GreenCape/AllPairs/Strategy/QictStrategy.php', + 'greencape\\allpairs\\reader' => '/GreenCape/AllPairs/Reader.php', + 'greencape\\allpairs\\strategy' => '/GreenCape/AllPairs/Strategy.php', + 'greencape\\allpairs\\stringreader' => '/GreenCape/AllPairs/Reader/StringReader.php', + 'greencape\\allpairs\\vardumpwriter' => '/GreenCape/AllPairs/Writer/VardumpWriter.php', + 'greencape\\allpairs\\writer' => '/GreenCape/AllPairs/Writer.php' + ); + } + $cn = strtolower($class); + if (isset($classes[$cn])) { + require __DIR__ . $classes[$cn]; + } + } +); +// @codeCoverageIgnoreEnd diff --git a/tests/data/joomla.txt b/tests/data/joomla.txt new file mode 100644 index 0000000..4c96835 --- /dev/null +++ b/tests/data/joomla.txt @@ -0,0 +1,5 @@ +Joomla: latest, staging +Webserver: Apache, Nginx +Database: MySQL, PostgreSQL, SQLite +PHP: 5.6, 7.0, 7.1 +