fromJustValue() public static method

Input will be copied from value.
public static fromJustValue ( T $value, string $generatorName = null ) : GeneratedValue
$value T
$generatorName string 'tuple'
return GeneratedValue
Ejemplo n.º 1
0
 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');
 }
Ejemplo n.º 2
0
 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');
 }
Ejemplo n.º 3
0
 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');
 }
Ejemplo n.º 4
0
 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');
 }
Ejemplo n.º 5
0
 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());
 }
Ejemplo n.º 6
0
 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');
 }
Ejemplo n.º 7
0
 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;
 }
Ejemplo n.º 8
0
 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');
 }
Ejemplo n.º 9
0
 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');
 }
Ejemplo n.º 10
0
 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');
 }
Ejemplo n.º 11
0
 public function __invoke($_size, $rand)
 {
     $booleanValues = [true, false];
     $randomIndex = $rand(0, count($booleanValues) - 1);
     return GeneratedValue::fromJustValue($booleanValues[$randomIndex], 'boolean');
 }
Ejemplo n.º 12
0
 public function shrink(GeneratedValue $element)
 {
     $codePoint = ord($element->unbox());
     $shrinkedValue = chr($this->shrinkingProgression->next(ord($element->unbox())));
     return GeneratedValue::fromJustValue($shrinkedValue, 'character');
 }
Ejemplo n.º 13
0
 public function __invoke($_size, $rand)
 {
     $index = $rand(0, count($this->domain) - 1);
     return GeneratedValue::fromJustValue($this->domain[$index], 'elements');
 }
Ejemplo n.º 14
0
 public function testContainsAnEmptySet()
 {
     $this->assertTrue($this->generator->contains(GeneratedValue::fromJustValue([])));
 }