public function contains(GeneratedValue $set) { foreach ($set->input() as $element) { if (!$this->singleElementGenerator->contains($element)) { return false; } } return true; }
public function contains(GeneratedValue $set) { foreach ($set->input() as $element) { if (!in_array($element, $this->universe)) { return false; } } return true; }
private function mapToAssociativeArray(GeneratedValue $tuple) { return $tuple->map(function ($value) { $associativeArray = []; $keys = array_keys($this->generators); for ($i = 0; $i < count($value); $i++) { $key = $keys[$i]; $associativeArray[$key] = $value[$i]; } return $associativeArray; }, 'associative'); }
private function predicate(GeneratedValue $value) { if ($this->filter instanceof PHPUnit_Framework_Constraint) { try { $this->filter->evaluate($value->unbox()); return true; } catch (PHPUnit_Framework_ExpectationFailedException $e) { return false; } } if (is_callable($this->filter)) { return call_user_func($this->filter, $value->unbox()); } throw new LogicException("Specified filter does not seem to be of the correct type. Please pass a callable or a PHPUnit_Framework_Constraint instead of " . var_export($this->filter, true)); }
public function contains(GeneratedValue $tuple) { $input = $tuple->input(); if (!is_array($input)) { throw new \Exception("Input must be an array, not " . var_export($input, true)); } if (count($input) !== $this->numberOfGenerators) { return false; } for ($i = 0; $i < $this->numberOfGenerators; $i++) { if (!$this->generators[$i]->contains($input[$i])) { return false; } } return true; }
public function testTheLowerLimitIsTheFixedPointOfShrinking() { $generator = new DateGenerator($lowerLimit = new DateTime("2014-01-01T00:00:00"), new DateTime("2014-01-02T23:59:59")); $value = GeneratedValue::fromJustValue(new DateTime("2014-01-01T00:01:00"), 'date'); for ($i = 0; $i < 10; $i++) { $value = $generator->shrink($value); } $this->assertEquals($lowerLimit, $value->unbox()); }
private function shrinkInSize($sequence) { if (count($sequence->unbox()) === 0) { return $sequence; } $input = $sequence->input(); $indexOfElementToRemove = array_rand($input); unset($input[$indexOfElementToRemove]); $input = array_values($input); return GeneratedValue::fromValueAndInput(array_map(function ($element) { return $element->unbox(); }, $input), $input, 'sequence'); }
public function contains(GeneratedValue $element) { return $this->value === $element->input(); }
public function contains(GeneratedValue $value) { return is_string($value->unbox()) && (bool) preg_match("/{$this->expression}/", $value->unbox()); }
public function contains(GeneratedValue $value) { return in_array($value->unbox(), $this->list); }
public function contains(GeneratedValue $element) { $value = $element->unbox(); return $value instanceof DateTime && $value >= $this->lowerLimit && $value <= $this->upperLimit; }
public function contains(GeneratedValue $element) { return is_int($element->input()); }
public function contains(GeneratedValue $generatedValue) { $value = $generatedValue->unbox(); return is_string($value) && strlen($value) == 1 && ord($value) >= $this->lowerLimit && ord($value) <= $this->upperLimit; }
public function contains(GeneratedValue $value) { return $this->generator->contains($value->input()); }
public function contains(GeneratedValue $element) { return is_float($element->unbox()); }
public function contains(GeneratedValue $element) { return in_array($element->unbox(), $this->domain); }
public function testContainsAnEmptySet() { $this->assertTrue($this->generator->contains(GeneratedValue::fromJustValue([]))); }
public function contains(GeneratedValue $element) { return is_int($element->input()) && $element->input() >= $this->lowerLimit && $element->input() <= $this->upperLimit; }
private function packageGeneratedValue($outerGeneratorValue, $innerGeneratorValue) { return GeneratedValue::fromValueAndInput($outerGeneratorValue->unbox(), [$outerGeneratorValue, $innerGeneratorValue], 'bind'); }
public function contains(GeneratedValue $element) { $input = $element->input(); $originalGeneratorIndex = $input['generator']; return $this->generators[$originalGeneratorIndex]['generator']->contains($input['value']); }
public function __invoke(callable $assertion) { $sizes = Size::withTriangleGrowth($this->maxSize)->limit($this->iterations); try { $redTestException = null; $this->notifyListeners('startPropertyVerification'); for ($iteration = 0; $iteration < $this->iterations && !$this->terminationConditionsAreSatisfied(); $iteration++) { $generatedValues = []; $values = []; foreach ($this->generators as $name => $generator) { $value = $generator($sizes->at($iteration), $this->rand); if (!$value instanceof GeneratedValue) { throw new RuntimeException("The value returned by a generator should be an instance of GeneratedValue, but it is " . var_export($value, true)); } $generatedValues[] = $value; $values[] = $value->unbox(); } $generation = GeneratedValue::fromValueAndInput($values, $generatedValues, 'tuple'); $this->notifyListeners('newGeneration', $generation->unbox(), $iteration); if (!$this->antecedentsAreSatisfied($values)) { continue; } $this->ordinaryEvaluations++; Evaluation::of($assertion)->with($generation)->onFailure(function ($generatedValues, $exception) use($assertion) { $this->notifyListeners('failure', $generatedValues->unbox(), $exception); if (!$this->shrinkingEnabled) { throw $exception; } $shrinking = $this->shrinkerFactory->random($this->generators, $assertion); // MAYBE: put into ShrinkerFactory? $shrinking->addGoodShrinkCondition(function (GeneratedValue $generatedValues) { return $this->antecedentsAreSatisfied($generatedValues->unbox()); })->onAttempt(function (GeneratedValue $generatedValues) { $this->notifyListeners('shrinking', $generatedValues->unbox()); })->from($generatedValues, $exception); })->execute(); } } catch (Exception $e) { $redTestException = $e; $wrap = (bool) getenv('ERIS_ORIGINAL_INPUT'); if ($wrap) { $message = "Original input: " . var_export($values, true) . PHP_EOL . "Possibly shrinked input follows." . PHP_EOL; throw new RuntimeException($message, -1, $e); } else { throw $e; } } finally { $this->notifyListeners('endPropertyVerification', $this->ordinaryEvaluations, $this->iterations, $redTestException); } }