|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\MathTrig; |
| 4 | + |
| 5 | +use PhpOffice\PhpSpreadsheet\Calculation\Functions; |
| 6 | +use PhpOffice\PhpSpreadsheet\Calculation\MathTrig; |
| 7 | + |
| 8 | +class RandArrayTest extends AllSetupTeardown |
| 9 | +{ |
| 10 | + public function testRANDARRAYInteger(): void |
| 11 | + { |
| 12 | + $rows = 3; |
| 13 | + $cols = 2; |
| 14 | + $min = -5; |
| 15 | + $max = 5; |
| 16 | + |
| 17 | + $result = MathTrig\Random::randArray($rows, $cols, $min, $max, true); |
| 18 | + self::assertIsArray($result); |
| 19 | + self::assertCount($rows, $result); |
| 20 | + self::assertIsArray($result[0]); |
| 21 | + self::assertCount($cols, $result[0]); |
| 22 | + |
| 23 | + $values = Functions::flattenArray($result); |
| 24 | + array_walk( |
| 25 | + $values, |
| 26 | + function ($value) use ($min, $max): void { |
| 27 | + self::assertIsInt($value); |
| 28 | + self::assertTrue($value >= $min && $value <= $max); |
| 29 | + } |
| 30 | + ); |
| 31 | + } |
| 32 | + |
| 33 | + public function testRANDARRAYFloat(): void |
| 34 | + { |
| 35 | + $rows = 3; |
| 36 | + $cols = 2; |
| 37 | + $min = -2; |
| 38 | + $max = 2; |
| 39 | + |
| 40 | + $result = MathTrig\Random::randArray($rows, $cols, $min, $max, false); |
| 41 | + self::assertIsArray($result); |
| 42 | + self::assertCount($rows, $result); |
| 43 | + self::assertIsArray($result[0]); |
| 44 | + self::assertCount($cols, $result[0]); |
| 45 | + |
| 46 | + $values = Functions::flattenArray($result); |
| 47 | + array_walk( |
| 48 | + $values, |
| 49 | + function ($value) use ($min, $max): void { |
| 50 | + self::assertIsFloat($value); |
| 51 | + self::assertTrue($value >= $min && $value <= $max); |
| 52 | + } |
| 53 | + ); |
| 54 | + } |
| 55 | + |
| 56 | + public function testRANDARRAYException(): void |
| 57 | + { |
| 58 | + $rows = 3; |
| 59 | + $cols = 2; |
| 60 | + $min = 2; |
| 61 | + $max = -2; |
| 62 | + |
| 63 | + $result = MathTrig\Random::randArray($rows, $cols, $min, $max, false); |
| 64 | + self::assertSame(Functions::VALUE(), $result); |
| 65 | + } |
| 66 | +} |
0 commit comments