Input will be copied from value.
public static fromJustValue ( T $value, string $generatorName = null ) : |
||
$value | T | |
$generatorName | string | 'tuple' |
return |
public function shrink(GeneratedValue $element) { $this->ensureIsInDomain($element); $timeOffset = $element->unbox()->getTimestamp() - $this->lowerLimit->getTimestamp(); $halvedOffset = floor($timeOffset / 2); return GeneratedValue::fromJustValue($this->fromOffset($halvedOffset), 'date'); }
public function shrink(GeneratedValue $element) { if (!$this->contains($element)) { throw new DomainException($element . ' does not belong to the domain of the constant value ' . $this->value . '.'); } return GeneratedValue::fromJustValue($this->value, 'constant'); }
public function __invoke($_size, $rand) { $lexer = new Lexer($this->expression); $gen = new SimpleRandom($rand()); $result = null; $parser = new Parser($lexer, new Scope(), new Scope()); $parser->parse()->getResult()->generate($result, $gen); return GeneratedValue::fromJustValue($result, 'regex'); }
public function shrink(GeneratedValue $value) { $candidateNames = $this->filterDataSet($this->lengthSlightlyLessThan(strlen($value->unbox()))); if (!$candidateNames) { return $value; } $distances = $this->distancesBy($value->unbox(), $candidateNames); return GeneratedValue::fromJustValue($this->minimumDistanceName($distances), 'names'); }
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()); }
public function shrink(GeneratedValue $element) { if (!$this->contains($element)) { throw new DomainException('Cannot shrink ' . $element . ' because it does not belong ' . 'to the domain of the Strings.'); } if ($element->unbox() === '') { return $element; } return GeneratedValue::fromJustValue(substr($element->unbox(), 0, -1), 'string'); }
public function shrink(GeneratedValue $element) { $this->checkValueToShrink($element); if ($element->input() > $this->shrinkTarget) { return GeneratedValue::fromJustValue($element->input() - 1); } if ($element->input() < $this->shrinkTarget) { return GeneratedValue::fromJustValue($element->input() + 1); } return $element; }
public function shrink(GeneratedValue $element) { $this->checkValueToShrink($element); $element = $element->input(); if ($element > 0) { return GeneratedValue::fromJustValue($element - 1, 'integer'); } if ($element < 0) { return GeneratedValue::fromJustValue($element + 1, 'integer'); } return GeneratedValue::fromJustValue($element, 'integer'); }
public function shrink(GeneratedValue $element) { $value = $element->unbox(); if (!$this->contains($element)) { throw new DomainException('Cannot shrink ' . $value . ' because it does not belong ' . 'to the domain of Floats'); } if ($value < 0.0) { return GeneratedValue::fromJustValue(min($value + 1.0, 0.0), 'float'); } if ($value > 0.0) { return GeneratedValue::fromJustValue(max($value - 1.0, 0.0), 'float'); } return GeneratedValue::fromJustValue(0.0, 'float'); }
public function shrink(GeneratedValue $set) { // TODO: see SetGenerator::shrink() if (!$this->contains($set)) { throw new DomainException('Cannot shrink {' . var_export($set, true) . '} because ' . 'it does not belong to the domain of this set'); } if (count($set->unbox()) === 0) { return $set; } $input = $set->input(); // TODO: make deterministic by returning an array of GeneratedValues $indexOfElementToRemove = array_rand($input); unset($input[$indexOfElementToRemove]); return GeneratedValue::fromJustValue(array_values($input), 'subset'); }
public function __invoke($_size, $rand) { $booleanValues = [true, false]; $randomIndex = $rand(0, count($booleanValues) - 1); return GeneratedValue::fromJustValue($booleanValues[$randomIndex], 'boolean'); }
public function shrink(GeneratedValue $element) { $codePoint = ord($element->unbox()); $shrinkedValue = chr($this->shrinkingProgression->next(ord($element->unbox()))); return GeneratedValue::fromJustValue($shrinkedValue, 'character'); }
public function __invoke($_size, $rand) { $index = $rand(0, count($this->domain) - 1); return GeneratedValue::fromJustValue($this->domain[$index], 'elements'); }
public function testContainsAnEmptySet() { $this->assertTrue($this->generator->contains(GeneratedValue::fromJustValue([]))); }