Skip to content

Commit f5d969d

Browse files
author
MarkBaker
committed
Unit Tests for RANDARRAY()
1 parent 1b94e9a commit f5d969d

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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::assertSame($rows, count($result));
20+
self::assertSame($cols, count($result[0]));
21+
22+
$values = Functions::flattenArray($result);
23+
array_walk(
24+
$values,
25+
function ($value) use ($min, $max) {
26+
self::assertIsInt($value);
27+
self::assertTrue($value >= $min && $value <= $max);
28+
}
29+
);
30+
}
31+
32+
public function testRANDARRAYFloat(): void
33+
{
34+
$rows = 3;
35+
$cols = 2;
36+
$min = -2;
37+
$max = 2;
38+
39+
$result = MathTrig\Random::randArray($rows, $cols, $min, $max, false);
40+
self::assertIsArray($result);
41+
self::assertSame($rows, count($result));
42+
self::assertSame($cols, count($result[0]));
43+
44+
$values = Functions::flattenArray($result);
45+
array_walk(
46+
$values,
47+
function ($value) use ($min, $max) {
48+
self::assertIsFloat($value);
49+
self::assertTrue($value >= $min && $value <= $max);
50+
}
51+
);
52+
}
53+
54+
public function testRANDARRAYException(): void
55+
{
56+
$rows = 3;
57+
$cols = 2;
58+
$min = 2;
59+
$max = -2;
60+
61+
$result = MathTrig\Random::randArray($rows, $cols, $min, $max, false);
62+
self::assertSame(Functions::VALUE(), $result);
63+
}
64+
}

0 commit comments

Comments
 (0)