Completed
Push — master ( 414e56...4f6d4a )
by Adrien
09:01
created

ModeTest::testMODE()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
nc 1
nop 2
dl 0
loc 10
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace PhpOffice\PhpSpreadsheetTests\Calculation\Functions\Statistical;
4
5
use PhpOffice\PhpSpreadsheet\Spreadsheet;
6
use PHPUnit\Framework\TestCase;
7
8
class ModeTest extends TestCase
9
{
10
    /**
11
     * @dataProvider providerMODE
12
     *
13
     * @param mixed $expectedResult
14
     * @param string $str
15
     */
16
    public function testMODE($expectedResult, string $str): void
17
    {
18
        $workbook = new Spreadsheet();
19
        $sheet = $workbook->getActiveSheet();
20
21
        $row = 1;
22
        $sheet->setCellValue("B$row", "=MODE($str)");
23
        $sheet->setCellValue("C$row", "=MODE.SNGL($str)");
24
        self::assertEquals($expectedResult, $sheet->getCell("B$row")->getCalculatedValue());
25
        self::assertEquals($expectedResult, $sheet->getCell("C$row")->getCalculatedValue());
26
    }
27
28
    public function providerMODE(): array
29
    {
30
        return require 'tests/data/Calculation/Statistical/MODE.php';
31
    }
32
33
    public function testMODENoArgs(): void
34
    {
35
        $this->expectException(\PhpOffice\PhpSpreadsheet\Calculation\Exception::class);
36
37
        $workbook = new Spreadsheet();
38
        $sheet = $workbook->getActiveSheet();
39
40
        $sheet->setCellValue('B1', '=MODE()');
41
        self::assertEquals('#N/A', $sheet->getCell('B1')->getCalculatedValue());
42
    }
43
}
44