File: NativeCalculatorTest.php

package info (click to toggle)
php-brick-math 0.12.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 948 kB
  • sloc: php: 8,290; xml: 108; makefile: 18
file content (82 lines) | stat: -rw-r--r-- 2,877 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php

declare(strict_types=1);

namespace Brick\Math\Tests\Internal\Calculator;

use Brick\Math\Internal\Calculator\NativeCalculator;
use Brick\Math\Tests\AbstractTestCase;
use PHPUnit\Framework\Attributes\DataProvider;

/**
 * Unit tests for class NativeCalculator.
 */
class NativeCalculatorTest extends AbstractTestCase
{
    #[DataProvider('providerAdd')]
    public function testAdd(string $a, string $b, string $expectedValue) : void
    {
        $nativeCalculator = new NativeCalculator();
        self::assertSame($expectedValue, $nativeCalculator->add($a, $b));
    }

    public static function providerAdd() : array
    {
        return [
            ['0', '1234567891234567889999999', '1234567891234567889999999'],
            ['1234567891234567889999999', '0', '1234567891234567889999999'],

            ['1234567891234567889999999', '-1234567891234567889999999', '0'],
            ['-1234567891234567889999999', '1234567891234567889999999', '0'],

            ['1234567891234567889999999', '1234567891234567889999999', '2469135782469135779999998'],
        ];
    }

    #[DataProvider('providerMul')]
    public function testMul(string $a, string $b, string $expectedValue) : void
    {
        $nativeCalculator = new NativeCalculator();
        self::assertSame($expectedValue, $nativeCalculator->mul($a, $b));
    }

    public static function providerMul() : array
    {
        return [
            ['0', '0', '0'],

            ['0', '1234567891234567889999999', '0'],
            ['1234567891234567889999999', '0', '0'],

            ['1', '1234567891234567889999999', '1234567891234567889999999'],
            ['1234567891234567889999999', '1', '1234567891234567889999999'],

            ['1234567891234567889999999', '-1234567891234567889999999', '-1524157878067367851562259605883269630864220000001'],
            ['-1234567891234567889999999', '1234567891234567889999999', '-1524157878067367851562259605883269630864220000001'],

            ['1234567891234567889999999', '1234567891234567889999999', '1524157878067367851562259605883269630864220000001'],
        ];
    }

    #[DataProvider('providerPow')]
    public function testPow(string $a, int $b, string $expectedValue) : void
    {
        $nativeCalculator = new NativeCalculator();
        self::assertSame($expectedValue, $nativeCalculator->pow($a, $b));
    }

    public static function providerPow() : array
    {
        return [
            ['123456789012345678901234567890', 0, '1'],

            ['1', 2, '1'],
            ['1234567891234567889999999', 1, '1234567891234567889999999'],

            ['1234567891234567889999999', -2, '1'],
            ['-1234567891234567889999999', 2, '1524157878067367851562259605883269630864220000001'],

            ['1234567891234567889999999', 3, '1881676377434183981909558127466713752376807174114547646517403703669999999'],
        ];
    }
}