Completed
Push — master ( 558809...774145 )
by Дмитрий
03:36
created

DivTest::testDivResultDouble()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 8
c 0
b 0
f 0
nc 1
nop 3
dl 0
loc 13
rs 9.4285
1
<?php
2
3
namespace Tests\PHPSA\Expression\AssignOp;
4
5
use PhpParser\Node;
6
use PHPSA\CompiledExpression;
7
use PHPSA\Compiler\Expression;
8
9
class DivTest extends \Tests\PHPSA\TestCase
10
{
11
    /**
12
     * Data provider for {var} /= {expr} with result type = int
13
     *
14
     * @return array
15
     */
16
    public function testDivResultIntDataProvider()
17
    {
18
        return array(
19
            array(2, 2, 1),
20
            array(true, 1, 1),
21
            array(3, true, 3),
22
            array(true, true, 1),
23
            array(2, 1, 2),
24
            array(-1, 1, -1),
25
            array(false, -3, 0),
26
            array(false, 1, 0),
27
            array(0, 1, 0),
28
            array(false, true, 0),
29
        );
30
    }
31
32
    /**
33
     * Tests {var} /= {expr} with result type = int
34
     *
35
     * @dataProvider testDivResultIntDataProvider
36
     */
37
    public function testDivResultInt($a, $b, $c)
38
    {
39
40
        $baseExpression = new Node\Expr\AssignOp\Div(
41
            $this->newScalarExpr($a),
42
            $this->newScalarExpr($b)
43
        );
44
        $compiledExpression = $this->compileExpression($baseExpression);
45
46
        $this->assertInstanceOfCompiledExpression($compiledExpression);
47
        $this->assertSame(CompiledExpression::INTEGER, $compiledExpression->getType());
48
        $this->assertSame($c, $compiledExpression->getValue());
49
    }
50
51
    /**
52
     * Data provider for {var} /= {expr} with result type = double
53
     *
54
     * @return array
55
     */
56
    public function testDivResultDoubleDataProvider()
57
    {
58
        return array(
59
            array(2, 0.5, 4.0),
60
            array(1.5, 0.5, 3.0),
61
            array(true, 2, 0.5),
62
            array(false, -5.5, 0.0),
63
            array(1.5, true, 1.5),
64
            array(-1.5, 1, -1.5),
65
        );
66
    }
67
68
    /**
69
     * Tests {var} /= {expr} with result type = double
70
     *
71
     * @dataProvider testDivResultDoubleDataProvider
72
     */
73
    public function testDivResultDouble($a, $b, $c)
74
    {
75
76
        $baseExpression = new Node\Expr\AssignOp\Div(
77
            $this->newScalarExpr($a),
78
            $this->newScalarExpr($b)
79
        );
80
        $compiledExpression = $this->compileExpression($baseExpression);
81
82
        $this->assertInstanceOfCompiledExpression($compiledExpression);
83
        $this->assertSame(CompiledExpression::DOUBLE, $compiledExpression->getType());
84
        $this->assertSame($c, $compiledExpression->getValue());
85
    }
86
87
    /**
88
     * Tests {var-type::UNKNOWN} /= {right-expr}
89
     */
90
    public function testFirstUnexpectedType()
91
    {
92
        $baseExpression = new Node\Expr\AssignOp\Div(
93
            $this->newFakeScalarExpr(),
94
            $this->newScalarExpr(1)
95
        );
96
        $compiledExpression = $this->compileExpression($baseExpression);
97
98
        $this->assertInstanceOfCompiledExpression($compiledExpression);
99
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
100
        $this->assertSame(null, $compiledExpression->getValue());
101
    }
102
103
    /**
104
     * Tests {var} /= {right-expr::UNKNOWN}
105
     */
106
    public function testSecondUnexpectedType()
107
    {
108
        $baseExpression = new Node\Expr\AssignOp\Div(
109
            $this->newScalarExpr(1),
110
            $this->newFakeScalarExpr()
111
        );
112
        $compiledExpression = $this->compileExpression($baseExpression);
113
114
        $this->assertInstanceOfCompiledExpression($compiledExpression);
115
        $this->assertSame(CompiledExpression::UNKNOWN, $compiledExpression->getType());
116
        $this->assertSame(null, $compiledExpression->getValue());
117
    }
118
}
119