| Total Complexity | 5 |
| Total Lines | 27 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 10 | class ChanceStrategyTest extends TestCase |
||
| 11 | { |
||
| 12 | public function testChanceStrategyUseChance(): void |
||
| 13 | { |
||
| 14 | $strategy = new ChanceStrategy(0.5); |
||
| 15 | |||
| 16 | $results = []; |
||
| 17 | |||
| 18 | for ($i = 0; $i < 10; $i++) { |
||
| 19 | $results[] = $strategy->generate('some_name', fn() => true); |
||
| 20 | } |
||
| 21 | |||
| 22 | $count = 0; |
||
| 23 | foreach ($results as $result) { |
||
| 24 | if ($result === true) { |
||
| 25 | $count++; |
||
| 26 | } |
||
| 27 | } |
||
| 28 | |||
| 29 | self::assertTrue($count < 10); |
||
| 30 | } |
||
| 31 | |||
| 32 | public function testChanceStrategyWithInvalidWeight(): void |
||
| 33 | { |
||
| 34 | $this->expectException(\InvalidArgumentException::class); |
||
| 35 | |||
| 36 | new ChanceStrategy(1.3); |
||
| 37 | } |
||
| 38 | } |