Hoa central
Public Member Functions | List of all members
Hoa\Math\Test\Unit\Sampler\Random Class Reference
Inheritance diagram for Hoa\Math\Test\Unit\Sampler\Random:

Public Member Functions

 case_integer ()
 
 case_bounded_integer ()
 
 case_optional_bounds_integer ()
 
 case_excluded_integers ()
 
 case_uniformity_integer ()
 
 case_float ()
 
 case_bounded_float ()
 
 case_optional_bounds_float ()
 
 case_uniformity_float ()
 
- Public Member Functions inherited from Hoa\Test\Unit\Suite
 __construct ()
 
 getTestedClassName ()
 
 getTestedClassNamespace ()
 
 beforeTestMethod ($methodName)
 

Detailed Description

Class .

Test suite of the random sampler.

Definition at line 50 of file Random.php.

Member Function Documentation

Hoa\Math\Test\Unit\Sampler\Random::case_bounded_float ( )

Definition at line 150 of file Random.php.

151  {
152  $this
153  ->given($sampler = new CUT())
154  ->when($x = $sampler->getFloat(-5.5, 5.5))
155  ->then
156  ->float($x)
157  ->isGreaterThanOrEqualTo(-5.5)
158  ->isLessThanOrEqualTo(5.5)
159  ->when($y = $sampler->getFloat(4.2, 4.2))
160  ->float($y)
161  ->isIdenticalTo(4.2);
162  }
Hoa\Math\Test\Unit\Sampler\Random::case_bounded_integer ( )

Definition at line 61 of file Random.php.

62  {
63  $this
64  ->given($sampler = new CUT())
65  ->when($x = $sampler->getInteger(-5, 5))
66  ->then
67  ->integer($x)
68  ->isGreaterThanOrEqualTo(-5)
69  ->isLessThanOrEqualTo(5)
70  ->when($y = $sampler->getInteger(42, 42))
71  ->then
72  ->integer($y)
73  ->isIdenticalTo(42);
74  }
Hoa\Math\Test\Unit\Sampler\Random::case_excluded_integers ( )

Definition at line 89 of file Random.php.

90  {
91  $this
92  ->given(
93  $exclude = [],
94  $sampler = new CUT()
95  )
96  ->when($x = $sampler->getInteger(0, 2, $exclude))
97  ->then
98  ->integer($x)
99  ->isGreaterThanOrEqualTo(0)
100  ->isLessThanOrEqualTo(2)
101 
102  ->given($exclude[] = 2)
103  ->when($y = $sampler->getInteger(0, 2, $exclude))
104  ->then
105  ->integer($y)
106  ->isGreaterThanOrEqualTo(0)
107  ->isLessThanOrEqualTo(1)
108 
109  ->given($exclude[] = 0)
110  ->when($z = $sampler->getInteger(0, 2, $exclude))
111  ->then
112  ->integer($z)
113  ->isIdenticalTo(1);
114  }
Hoa\Math\Test\Unit\Sampler\Random::case_float ( )

Definition at line 141 of file Random.php.

142  {
143  $this
144  ->given($sampler = new CUT())
145  ->when($x = $sampler->getFloat())
146  ->then
147  ->float($x);
148  }
Hoa\Math\Test\Unit\Sampler\Random::case_integer ( )

Definition at line 52 of file Random.php.

53  {
54  $this
55  ->given($sampler = new CUT())
56  ->when($x = $sampler->getInteger())
57  ->then
58  ->integer($x);
59  }
Hoa\Math\Test\Unit\Sampler\Random::case_optional_bounds_float ( )

Definition at line 164 of file Random.php.

165  {
166  $this
167  ->given($sampler = new CUT([
168  'float.min' => 4.2,
169  'float.max' => 4.2
170  ]))
171  ->when($x = $sampler->getFloat())
172  ->then
173  ->float($x)
174  ->isIdenticalTo(4.2);
175  }
Hoa\Math\Test\Unit\Sampler\Random::case_optional_bounds_integer ( )

Definition at line 76 of file Random.php.

77  {
78  $this
79  ->given($sampler = new CUT([
80  'integer.min' => 42,
81  'integer.max' => 42
82  ]))
83  ->when($x = $sampler->getInteger())
84  ->then
85  ->integer($x)
86  ->isIdenticalTo(42);
87  }
Hoa\Math\Test\Unit\Sampler\Random::case_uniformity_float ( )

Definition at line 177 of file Random.php.

178  {
179  $this
180  ->given(
181  $max = $this->sample(
182  $this->realdom()->boundinteger(1 << 18, 1 << 20)
183  ),
184  $sum = 0,
185  $upper = 1 << 10,
186  $sampler = new CUT([
187  'float.min' => -$upper,
188  'float.max' => $upper
189  ])
190  )
191  ->when(function () use ($max, &$sum, &$sampler) {
192  for ($i = 0; $i < $max; ++$i) {
193  $sum += $sampler->getFloat();
194  }
195  })
196  ->then
197  ->float($sum / $max)
198  ->isGreaterThanOrEqualTo(-1.5)
199  ->isLessThanOrEqualTo(1.5);
200  }
Hoa\Math\Test\Unit\Sampler\Random::case_uniformity_integer ( )

Definition at line 116 of file Random.php.

117  {
118  $this
119  ->given(
120  $max = $this->sample(
121  $this->realdom()->boundinteger(1 << 18, 1 << 20)
122  ),
123  $sum = 0,
124  $upper = 1 << 10,
125  $sampler = new CUT([
126  'integer.min' => -$upper,
127  'integer.max' => $upper
128  ])
129  )
130  ->when(function () use ($max, &$sum, &$sampler) {
131  for ($i = 0; $i < $max; ++$i) {
132  $sum += $sampler->getInteger();
133  }
134  })
135  ->then
136  ->float($sum / $max)
137  ->isGreaterThanOrEqualTo(-1.5)
138  ->isLessThanOrEqualTo(1.5);
139  }

The documentation for this class was generated from the following file: