Completed
Pull Request — master (#304)
by Enrico
03:09
created

PowTest::testSecondUnexpectedType()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
namespace Tests\PHPSA\Compiler\Expression\AssignOp;
4
5
use PhpParser\Node;
6
use PHPSA\CompiledExpression;
7
use PHPSA\Compiler\Expression;
8
use Tests\PHPSA\Compiler\Expression\AbstractBinaryOp;
9
10
class PowTest extends AbstractBinaryOp
11
{
12
    /**
13
     * Data provider for {var} **= {expr} with result type = int
14
     *
15
     * @return array
16
     */
17
    public function powResultIntDataProvider()
18
    {
19
        return [
20
            [2, 2, 4],
21
            [true, 2, 1],
22
            [3, true, 3],
23
            [true, true, 1],
24
            [2, 0, 1],
25
            [false, 3, 0],
26
            [2, false, 1],
27
            [false, false, 1],
28
            [0, 0, 1],
29
            [0, 3, 0],
30
            [true, false, 1],
31
        ];
32
    }
33
34
    /**
35
     * Tests {var} **= {expr} with result type = int
36
     *
37
     * @dataProvider powResultIntDataProvider
38
     */
39
    public function testPowResultInt($a, $b, $c)
40
    {
41
42
        $baseExpression = new Node\Expr\AssignOp\Pow(
43
            $this->newScalarExpr($a),
44
            $this->newScalarExpr($b)
45
        );
46
        $compiledExpression = $this->compileExpression($baseExpression);
47
48
        $this->assertInstanceOfCompiledExpression($compiledExpression);
49
        $this->assertSame(CompiledExpression::INTEGER, $compiledExpression->getType());
50
        $this->assertSame($c, $compiledExpression->getValue());
51
    }
52
53
    /**
54
     * Data provider for {var} **= {expr} with result type = double
55
     *
56
     * @return array
57
     */
58
    public function powResultDoubleDataProvider()
59
    {
60
        return [
61
            [2, -2, 0.25],
62
            [1.5, 2, 2.25],
63
            [1, 1.5, 1.0],
64
            [100, 2.5, 100000.0],
65
            [true, 1.5, 1.0],
66
            [false, 1.5, 0.0],
67
            [1.5, false, 1.0],
68
            [1.5, true, 1.5],
69
        ];
70
    }
71
72
    /**
73
     * Tests {var} **= {expr} with result type = double
74
     *
75
     * @dataProvider powResultDoubleDataProvider
76
     */
77
    public function testPowResultDouble($a, $b, $c)
78
    {
79
80
        $baseExpression = new Node\Expr\AssignOp\Pow(
81
            $this->newScalarExpr($a),
82
            $this->newScalarExpr($b)
83
        );
84
        $compiledExpression = $this->compileExpression($baseExpression);
85
86
        $this->assertInstanceOfCompiledExpression($compiledExpression);
87
        $this->assertSame(CompiledExpression::DOUBLE, $compiledExpression->getType());
88
        $this->assertSame($c, $compiledExpression->getValue());
89
    }
90
91
    /**
92
     * @param Node\Scalar $a
93
     * @param Node\Scalar $b
94
     * @return Node\Expr\AssignOp\Pow
95
     */
96
    protected function buildExpression($a, $b)
97
    {
98
        return new Node\Expr\AssignOp\Pow($a, $b);
99
    }
100
}
101