public function shrink(GeneratedValue $set)
{
// TODO: extract duplication with Generator\SequenceGenerator
// to do so, implement __toString for every Generator (put it
// in the interface) and then Extract Class
// ContainmentCheck::of($this)->on($set);
// which will use $generator->__toString() in the error message
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->input()) === 0) {
return $set;
}
$input = $set->input();
// TODO: make deterministic
$indexOfElementToRemove = array_rand($input);
unset($input[$indexOfElementToRemove]);
$input = array_values($input);
return GeneratedValue::fromValueAndInput(array_map(function ($element) {
return $element->unbox();
}, $input), array_values($input), 'set');
}