Passed
Branch master (c73d10)
by Stefan
02:51 queued 55s
created

UtilsMathTest::test_modSub()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 1
b 0
f 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace SKien\Test\PNServer;
5
6
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use SKien\PNServer\Utils\Math;
8
9
/**
10
 * @author Stefanius <[email protected]>
11
 * @copyright MIT License - see the LICENSE file for details
12
 */
13
class UtilsMathTest extends TestCase
14
{
15
    /**
16
     * @dataProvider cmpProvider
17
     */
18
    public function test_cmp(\GMP $a, \GMP $b, int $expected) : void
19
    {
20
        $this->assertEquals($expected, Math::cmp($a, $b));
21
    }
22
    
23
    public function cmpProvider() : array
24
    {
25
        return [
26
            [gmp_init(2), gmp_init(2), 0],
27
            [gmp_init(3), gmp_init(2), 1],
28
            [gmp_init(2), gmp_init(3), -1],
29
            [gmp_init(5), gmp_init(0), 1],
30
            [gmp_init(0), gmp_init(3), -1],
31
            [gmp_init(-2), gmp_init(2), -2],
32
            [gmp_init(2), gmp_init(-2), 2],
33
            [gmp_init(-5), gmp_init(2), -2],
34
            [gmp_init(5), gmp_init(-2), 2]
35
        ];
36
    }
37
    
38
    /**
39
     * @dataProvider equalsProvider
40
     */
41
    public function test_equals(\GMP $a, \GMP $b, bool $expected) : void
42
    {
43
        $this->assertEquals($expected, Math::equals($a, $b));
44
    }
45
    
46
    public function equalsProvider() : array
47
    {
48
        return [
49
            '2 == 2' => [gmp_init(2), gmp_init(2), true],
50
            '2 == 3' => [gmp_init(2), gmp_init(3), false],
51
            '2 == -2' => [gmp_init(2), gmp_init(-2), false]
52
        ];
53
    }
54
    
55
    public function test_mod() : void
56
    {
57
        $this->assertEquals((int)Math::mod(gmp_init(7), gmp_init(2)), 1);
0 ignored issues
show
Bug introduced by
It seems like gmp_init(2) can also be of type resource; however, parameter $modulus of SKien\PNServer\Utils\Math::mod() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
        $this->assertEquals((int)Math::mod(gmp_init(7), /** @scrutinizer ignore-type */ gmp_init(2)), 1);
Loading history...
Bug introduced by
It seems like gmp_init(7) can also be of type resource; however, parameter $number of SKien\PNServer\Utils\Math::mod() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

57
        $this->assertEquals((int)Math::mod(/** @scrutinizer ignore-type */ gmp_init(7), gmp_init(2)), 1);
Loading history...
58
    }
59
    
60
    public function test_add() : void
61
    {
62
        $this->assertEquals((int)Math::add(gmp_init(2), gmp_init(3)), 5);
0 ignored issues
show
Bug introduced by
It seems like gmp_init(2) can also be of type resource; however, parameter $augend of SKien\PNServer\Utils\Math::add() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

62
        $this->assertEquals((int)Math::add(/** @scrutinizer ignore-type */ gmp_init(2), gmp_init(3)), 5);
Loading history...
Bug introduced by
It seems like gmp_init(3) can also be of type resource; however, parameter $addend of SKien\PNServer\Utils\Math::add() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

62
        $this->assertEquals((int)Math::add(gmp_init(2), /** @scrutinizer ignore-type */ gmp_init(3)), 5);
Loading history...
63
    }
64
    
65
    public function test_sub() : void
66
    {
67
        $this->assertEquals((int)Math::sub(gmp_init(2), gmp_init(3)), -1);
0 ignored issues
show
Bug introduced by
It seems like gmp_init(2) can also be of type resource; however, parameter $minuend of SKien\PNServer\Utils\Math::sub() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
        $this->assertEquals((int)Math::sub(/** @scrutinizer ignore-type */ gmp_init(2), gmp_init(3)), -1);
Loading history...
Bug introduced by
It seems like gmp_init(3) can also be of type resource; however, parameter $subtrahend of SKien\PNServer\Utils\Math::sub() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

67
        $this->assertEquals((int)Math::sub(gmp_init(2), /** @scrutinizer ignore-type */ gmp_init(3)), -1);
Loading history...
68
    }
69
    
70
    /**
71
     * @dataProvider mulProvider
72
     */
73
    public function test_mul(\GMP $a, \GMP $b, int $expected) : void
74
    {
75
        $this->assertEquals($expected, (int)Math::mul($a, $b));
76
    }
77
    
78
    public function mulProvider() : array
79
    {
80
        return [
81
            [gmp_init(5), gmp_init(11), 55],
82
            [gmp_init(-5), gmp_init(-3), 15],
83
            [gmp_init(4), gmp_init(-15), -60],
84
            [gmp_init(-4), gmp_init(15), -60]
85
        ];
86
    }
87
    
88
    /**
89
     * @dataProvider powProvider
90
     */
91
    public function test_pow(\GMP $a, int $b, int $expected) : void
92
    {
93
        $this->assertEquals($expected, (int)Math::pow($a, $b));
94
    }
95
    
96
    public function powProvider() : array
97
    {
98
        return [
99
            [gmp_init(5), 2, 25],
100
            [gmp_init(-5), 2, 25],
101
            [gmp_init(2), 3, 8],
102
            [gmp_init(-2), 3, -8]
103
        ];
104
    }
105
    
106
    public function test_bitwiseAnd() : void
107
    {
108
        $this->assertEquals((int)Math::bitwiseAnd(gmp_init('110011', 2), gmp_init('011110', 2)), (int)gmp_init('010010', 2));
0 ignored issues
show
Bug introduced by
It seems like gmp_init('011110', 2) can also be of type resource; however, parameter $other of SKien\PNServer\Utils\Math::bitwiseAnd() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

108
        $this->assertEquals((int)Math::bitwiseAnd(gmp_init('110011', 2), /** @scrutinizer ignore-type */ gmp_init('011110', 2)), (int)gmp_init('010010', 2));
Loading history...
Bug introduced by
It seems like gmp_init('110011', 2) can also be of type resource; however, parameter $first of SKien\PNServer\Utils\Math::bitwiseAnd() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

108
        $this->assertEquals((int)Math::bitwiseAnd(/** @scrutinizer ignore-type */ gmp_init('110011', 2), gmp_init('011110', 2)), (int)gmp_init('010010', 2));
Loading history...
109
    }
110
    
111
    public function test_bitwiseXor() : void
112
    {
113
        $this->assertEquals((int)Math::bitwiseXor(gmp_init('110011', 2), gmp_init('011110', 2)), (int)gmp_init('101101', 2));
0 ignored issues
show
Bug introduced by
It seems like gmp_init('011110', 2) can also be of type resource; however, parameter $other of SKien\PNServer\Utils\Math::bitwiseXor() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

113
        $this->assertEquals((int)Math::bitwiseXor(gmp_init('110011', 2), /** @scrutinizer ignore-type */ gmp_init('011110', 2)), (int)gmp_init('101101', 2));
Loading history...
Bug introduced by
It seems like gmp_init('110011', 2) can also be of type resource; however, parameter $first of SKien\PNServer\Utils\Math::bitwiseXor() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

113
        $this->assertEquals((int)Math::bitwiseXor(/** @scrutinizer ignore-type */ gmp_init('110011', 2), gmp_init('011110', 2)), (int)gmp_init('101101', 2));
Loading history...
114
    }
115
    
116
    public function test_rightShift() : void
117
    {
118
        $this->assertEquals((int)Math::rightShift(gmp_init('110011', 2), 3), (int)gmp_init('110', 2));
0 ignored issues
show
Bug introduced by
It seems like gmp_init('110011', 2) can also be of type resource; however, parameter $number of SKien\PNServer\Utils\Math::rightShift() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

118
        $this->assertEquals((int)Math::rightShift(/** @scrutinizer ignore-type */ gmp_init('110011', 2), 3), (int)gmp_init('110', 2));
Loading history...
119
    }
120
    
121
    public function test_toString() : void
122
    {
123
        $this->assertEquals(Math::toString(gmp_init('100', 16)), '256');
0 ignored issues
show
Bug introduced by
It seems like gmp_init('100', 16) can also be of type resource; however, parameter $value of SKien\PNServer\Utils\Math::toString() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

123
        $this->assertEquals(Math::toString(/** @scrutinizer ignore-type */ gmp_init('100', 16)), '256');
Loading history...
124
    }
125
    
126
    public function test_baseConvert() : void
127
    {
128
        $this->assertEquals(Math::baseConvert('0x1B', 16, 2), '11011');
129
    }
130
    
131
    public function test_inverseMod() : void
132
    {
133
        $this->assertEquals(9, (int)Math::inverseMod(gmp_init(5), gmp_init(11)));
0 ignored issues
show
Bug introduced by
It seems like gmp_init(11) can also be of type resource; however, parameter $m of SKien\PNServer\Utils\Math::inverseMod() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

133
        $this->assertEquals(9, (int)Math::inverseMod(gmp_init(5), /** @scrutinizer ignore-type */ gmp_init(11)));
Loading history...
Bug introduced by
It seems like gmp_init(5) can also be of type resource; however, parameter $a of SKien\PNServer\Utils\Math::inverseMod() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

133
        $this->assertEquals(9, (int)Math::inverseMod(/** @scrutinizer ignore-type */ gmp_init(5), gmp_init(11)));
Loading history...
134
        $this->assertEquals(11, (int)Math::inverseMod(gmp_init(-4), gmp_init(15)));
135
        $this->assertFalse(Math::inverseMod(gmp_init(5), gmp_init(10)));
136
    }
137
    
138
    public function test_modSub() : void
139
    {
140
        $this->assertEquals((int)Math::modSub(gmp_init(12), gmp_init(4), gmp_init(5)), 3);
0 ignored issues
show
Bug introduced by
It seems like gmp_init(12) can also be of type resource; however, parameter $minuend of SKien\PNServer\Utils\Math::modSub() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

140
        $this->assertEquals((int)Math::modSub(/** @scrutinizer ignore-type */ gmp_init(12), gmp_init(4), gmp_init(5)), 3);
Loading history...
Bug introduced by
It seems like gmp_init(4) can also be of type resource; however, parameter $subtrahend of SKien\PNServer\Utils\Math::modSub() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

140
        $this->assertEquals((int)Math::modSub(gmp_init(12), /** @scrutinizer ignore-type */ gmp_init(4), gmp_init(5)), 3);
Loading history...
Bug introduced by
It seems like gmp_init(5) can also be of type resource; however, parameter $modulus of SKien\PNServer\Utils\Math::modSub() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

140
        $this->assertEquals((int)Math::modSub(gmp_init(12), gmp_init(4), /** @scrutinizer ignore-type */ gmp_init(5)), 3);
Loading history...
141
    }
142
    
143
    public function test_modMul() : void
144
    {
145
        $this->assertEquals((int)Math::modMul(gmp_init(3), gmp_init(4), gmp_init(5)), 2);
0 ignored issues
show
Bug introduced by
It seems like gmp_init(4) can also be of type resource; however, parameter $muliplicand of SKien\PNServer\Utils\Math::modMul() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

145
        $this->assertEquals((int)Math::modMul(gmp_init(3), /** @scrutinizer ignore-type */ gmp_init(4), gmp_init(5)), 2);
Loading history...
Bug introduced by
It seems like gmp_init(3) can also be of type resource; however, parameter $multiplier of SKien\PNServer\Utils\Math::modMul() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

145
        $this->assertEquals((int)Math::modMul(/** @scrutinizer ignore-type */ gmp_init(3), gmp_init(4), gmp_init(5)), 2);
Loading history...
Bug introduced by
It seems like gmp_init(5) can also be of type resource; however, parameter $modulus of SKien\PNServer\Utils\Math::modMul() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

145
        $this->assertEquals((int)Math::modMul(gmp_init(3), gmp_init(4), /** @scrutinizer ignore-type */ gmp_init(5)), 2);
Loading history...
146
    }
147
    
148
    public function test_modDiv() : void
149
    {
150
        $this->assertEquals((int)Math::modDiv(gmp_init(12), gmp_init(2), gmp_init(5)), 36);
0 ignored issues
show
Bug introduced by
It seems like gmp_init(5) can also be of type resource; however, parameter $modulus of SKien\PNServer\Utils\Math::modDiv() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

150
        $this->assertEquals((int)Math::modDiv(gmp_init(12), gmp_init(2), /** @scrutinizer ignore-type */ gmp_init(5)), 36);
Loading history...
Bug introduced by
It seems like gmp_init(12) can also be of type resource; however, parameter $dividend of SKien\PNServer\Utils\Math::modDiv() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

150
        $this->assertEquals((int)Math::modDiv(/** @scrutinizer ignore-type */ gmp_init(12), gmp_init(2), gmp_init(5)), 36);
Loading history...
Bug introduced by
It seems like gmp_init(2) can also be of type resource; however, parameter $divisor of SKien\PNServer\Utils\Math::modDiv() does only seem to accept GMP, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

150
        $this->assertEquals((int)Math::modDiv(gmp_init(12), /** @scrutinizer ignore-type */ gmp_init(2), gmp_init(5)), 36);
Loading history...
151
    }
152
}
153
154