given($sampler = new CUT()) ->when($x = $sampler->getInteger()) ->then ->integer($x); } public function case_bounded_integer() { $this ->given($sampler = new CUT()) ->when($x = $sampler->getInteger(-5, 5)) ->then ->integer($x) ->isGreaterThanOrEqualTo(-5) ->isLessThanOrEqualTo(5) ->when($y = $sampler->getInteger(42, 42)) ->then ->integer($y) ->isIdenticalTo(42); } public function case_optional_bounds_integer() { $this ->given($sampler = new CUT([ 'integer.min' => 42, 'integer.max' => 42 ])) ->when($x = $sampler->getInteger()) ->then ->integer($x) ->isIdenticalTo(42); } public function case_excluded_integers() { $this ->given( $exclude = [], $sampler = new CUT() ) ->when($x = $sampler->getInteger(0, 2, $exclude)) ->then ->integer($x) ->isGreaterThanOrEqualTo(0) ->isLessThanOrEqualTo(2) ->given($exclude[] = 2) ->when($y = $sampler->getInteger(0, 2, $exclude)) ->then ->integer($y) ->isGreaterThanOrEqualTo(0) ->isLessThanOrEqualTo(1) ->given($exclude[] = 0) ->when($z = $sampler->getInteger(0, 2, $exclude)) ->then ->integer($z) ->isIdenticalTo(1); } public function case_uniformity_integer() { $this ->given( $max = $this->sample( $this->realdom()->boundinteger(1 << 18, 1 << 20) ), $sum = 0, $upper = 1 << 10, $sampler = new CUT([ 'integer.min' => -$upper, 'integer.max' => $upper ]) ) ->when(function () use ($max, &$sum, &$sampler) { for ($i = 0; $i < $max; ++$i) { $sum += $sampler->getInteger(); } }) ->then ->float($sum / $max) ->isGreaterThanOrEqualTo(-1.5) ->isLessThanOrEqualTo(1.5); } public function case_float() { $this ->given($sampler = new CUT()) ->when($x = $sampler->getFloat()) ->then ->float($x); } public function case_bounded_float() { $this ->given($sampler = new CUT()) ->when($x = $sampler->getFloat(-5.5, 5.5)) ->then ->float($x) ->isGreaterThanOrEqualTo(-5.5) ->isLessThanOrEqualTo(5.5) ->when($y = $sampler->getFloat(4.2, 4.2)) ->float($y) ->isIdenticalTo(4.2); } public function case_optional_bounds_float() { $this ->given($sampler = new CUT([ 'float.min' => 4.2, 'float.max' => 4.2 ])) ->when($x = $sampler->getFloat()) ->then ->float($x) ->isIdenticalTo(4.2); } public function case_uniformity_float() { $this ->given( $max = $this->sample( $this->realdom()->boundinteger(1 << 18, 1 << 20) ), $sum = 0, $upper = 1 << 10, $sampler = new CUT([ 'float.min' => -$upper, 'float.max' => $upper ]) ) ->when(function () use ($max, &$sum, &$sampler) { for ($i = 0; $i < $max; ++$i) { $sum += $sampler->getFloat(); } }) ->then ->float($sum / $max) ->isGreaterThanOrEqualTo(-1.5) ->isLessThanOrEqualTo(1.5); } }