Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F4093393
FloatGeneratorTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
FloatGeneratorTest.php
View Options
<?php
namespace
Eris\Generator
;
use
Eris\PHPUnitDeprecationHelper
;
use
Eris\Random\RandomRange
;
use
Eris\Random\RandSource
;
class
FloatGeneratorTest
extends
\PHPUnit\Framework\TestCase
{
/**
* @var int
*/
private
$size
;
/**
* @var RandomRange
*/
private
$rand
;
protected
function
setUp
():
void
{
$this
->
size
=
300
;
$this
->
rand
=
new
RandomRange
(
new
RandSource
());
}
public
function
testPicksUniformelyPositiveAndNegativeFloatNumbers
():
void
{
$generator
=
new
FloatGenerator
();
$sum
=
0
;
$trials
=
500
;
for
(
$i
=
0
;
$i
<
$trials
;
$i
++)
{
$value
=
$generator
(
$this
->
size
,
$this
->
rand
);
PHPUnitDeprecationHelper
::
assertIsFloat
(
$value
->
unbox
());
$sum
+=
$value
->
unbox
();
}
$mean
=
$sum
/
$trials
;
// over a 300 size
$this
->
assertLessThan
(
10
,
abs
(
$mean
));
}
public
function
testShrinksLinearly
():
void
{
$generator
=
new
FloatGenerator
();
$this
->
assertSame
(
3.5
,
$generator
->
shrink
(
GeneratedValueSingle
::
fromJustValue
(
4.5
))->
unbox
());
$this
->
assertSame
(-
2.5
,
$generator
->
shrink
(
GeneratedValueSingle
::
fromJustValue
(-
3.5
))->
unbox
());
}
public
function
testWhenBothSignsArePossibleCannotShrinkBelowZero
():
void
{
$generator
=
new
FloatGenerator
();
$this
->
assertSame
(
0.0
,
$generator
->
shrink
(
GeneratedValueSingle
::
fromJustValue
(
0.0
))->
unbox
());
$this
->
assertSame
(
0.0
,
$generator
->
shrink
(
GeneratedValueSingle
::
fromJustValue
(
0.5
))->
unbox
());
$this
->
assertSame
(
0.0
,
$generator
->
shrink
(
GeneratedValueSingle
::
fromJustValue
(-
0.5
))->
unbox
());
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Aug 18 2026, 12:47 (4 w, 3 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
cf/dd/bce929d3dd524cd0a87fd9f8c650
Default Alt Text
FloatGeneratorTest.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment