1--TEST-- 2Random: Randomizer: getFloat(): Parameters are correctly validated 3--FILE-- 4<?php 5 6use Random\IntervalBoundary; 7use Random\Randomizer; 8 9function randomizer(): Randomizer 10{ 11 return new Randomizer(); 12} 13 14foreach ([ 15 IntervalBoundary::ClosedClosed, 16 IntervalBoundary::ClosedOpen, 17 IntervalBoundary::OpenClosed, 18 IntervalBoundary::OpenOpen, 19] as $boundary) { 20 echo $boundary->name, PHP_EOL; 21 22 try { 23 var_dump(randomizer()->getFloat(NAN, 0.0, $boundary)); 24 } catch (ValueError $e) { 25 echo $e->getMessage(), PHP_EOL; 26 } 27 28 try { 29 var_dump(randomizer()->getFloat(INF, 0.0, $boundary)); 30 } catch (ValueError $e) { 31 echo $e->getMessage(), PHP_EOL; 32 } 33 34 try { 35 var_dump(randomizer()->getFloat(-INF, 0.0, $boundary)); 36 } catch (ValueError $e) { 37 echo $e->getMessage(), PHP_EOL; 38 } 39 40 try { 41 var_dump(randomizer()->getFloat(0.0, NAN, $boundary)); 42 } catch (ValueError $e) { 43 echo $e->getMessage(), PHP_EOL; 44 } 45 46 try { 47 var_dump(randomizer()->getFloat(0.0, INF, $boundary)); 48 } catch (ValueError $e) { 49 echo $e->getMessage(), PHP_EOL; 50 } 51 52 try { 53 var_dump(randomizer()->getFloat(0.0, -INF, $boundary)); 54 } catch (ValueError $e) { 55 echo $e->getMessage(), PHP_EOL; 56 } 57 58 try { 59 var_dump(randomizer()->getFloat(0.0, -0.1, $boundary)); 60 } catch (ValueError $e) { 61 echo $e->getMessage(), PHP_EOL; 62 } 63 64 try { 65 var_dump(randomizer()->getFloat(0.0, 0.0, $boundary)); 66 } catch (ValueError $e) { 67 echo $e->getMessage(), PHP_EOL; 68 } 69 70 try { 71 // Both values round to the same float. 72 var_dump(randomizer()->getFloat(100_000_000_000_000_000.0, 100_000_000_000_000_000.1, $boundary)); 73 } catch (ValueError $e) { 74 echo $e->getMessage(), PHP_EOL; 75 } 76 77 try { 78 // There is no float between the two parameters, thus making the OpenOpen interval empty. 79 var_dump(randomizer()->getFloat(1.0, 1 + PHP_FLOAT_EPSILON, $boundary)); 80 } catch (ValueError $e) { 81 echo $e->getMessage(), PHP_EOL; 82 } 83} 84 85?> 86--EXPECTF-- 87ClosedClosed 88Random\Randomizer::getFloat(): Argument #1 ($min) must be finite 89Random\Randomizer::getFloat(): Argument #1 ($min) must be finite 90Random\Randomizer::getFloat(): Argument #1 ($min) must be finite 91Random\Randomizer::getFloat(): Argument #2 ($max) must be finite 92Random\Randomizer::getFloat(): Argument #2 ($max) must be finite 93Random\Randomizer::getFloat(): Argument #2 ($max) must be finite 94Random\Randomizer::getFloat(): Argument #2 ($max) must be greater than or equal to argument #1 ($min) 95float(0) 96float(1.0E+17) 97float(%f) 98ClosedOpen 99Random\Randomizer::getFloat(): Argument #1 ($min) must be finite 100Random\Randomizer::getFloat(): Argument #1 ($min) must be finite 101Random\Randomizer::getFloat(): Argument #1 ($min) must be finite 102Random\Randomizer::getFloat(): Argument #2 ($max) must be finite 103Random\Randomizer::getFloat(): Argument #2 ($max) must be finite 104Random\Randomizer::getFloat(): Argument #2 ($max) must be finite 105Random\Randomizer::getFloat(): Argument #2 ($max) must be greater than argument #1 ($min) 106Random\Randomizer::getFloat(): Argument #2 ($max) must be greater than argument #1 ($min) 107Random\Randomizer::getFloat(): Argument #2 ($max) must be greater than argument #1 ($min) 108float(1) 109OpenClosed 110Random\Randomizer::getFloat(): Argument #1 ($min) must be finite 111Random\Randomizer::getFloat(): Argument #1 ($min) must be finite 112Random\Randomizer::getFloat(): Argument #1 ($min) must be finite 113Random\Randomizer::getFloat(): Argument #2 ($max) must be finite 114Random\Randomizer::getFloat(): Argument #2 ($max) must be finite 115Random\Randomizer::getFloat(): Argument #2 ($max) must be finite 116Random\Randomizer::getFloat(): Argument #2 ($max) must be greater than argument #1 ($min) 117Random\Randomizer::getFloat(): Argument #2 ($max) must be greater than argument #1 ($min) 118Random\Randomizer::getFloat(): Argument #2 ($max) must be greater than argument #1 ($min) 119float(1.0000000000000002) 120OpenOpen 121Random\Randomizer::getFloat(): Argument #1 ($min) must be finite 122Random\Randomizer::getFloat(): Argument #1 ($min) must be finite 123Random\Randomizer::getFloat(): Argument #1 ($min) must be finite 124Random\Randomizer::getFloat(): Argument #2 ($max) must be finite 125Random\Randomizer::getFloat(): Argument #2 ($max) must be finite 126Random\Randomizer::getFloat(): Argument #2 ($max) must be finite 127Random\Randomizer::getFloat(): Argument #2 ($max) must be greater than argument #1 ($min) 128Random\Randomizer::getFloat(): Argument #2 ($max) must be greater than argument #1 ($min) 129Random\Randomizer::getFloat(): Argument #2 ($max) must be greater than argument #1 ($min) 130The given interval is empty, there are no floats between argument #1 ($min) and argument #2 ($max). 131