VectorTest   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 189
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 14
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 189
rs 10

14 Methods

Rating   Name   Duplication   Size   Complexity  
A testAdd() 0 12 1
A testAddInvalid() 0 12 1
A testConjugate() 0 11 1
A testDotProduct() 0 13 1
A testDotProductWithInvalidSizeVector() 0 12 1
A testGetLength() 0 12 1
A testGetLengthSquared() 0 12 1
A testGetMagnitude() 0 12 1
A testNegate() 0 11 1
A testNormalize() 0 11 1
A testReverse() 0 11 1
A testScale() 0 11 1
A testSubtract() 0 12 1
A testSubtractInvalid() 0 12 1
1
<?php
2
3
namespace PHP\Math\VectorTest;
4
5
use PHP\Math\Vector\Vector;
6
use PHPUnit_Framework_TestCase;
7
8
class VectorTest extends PHPUnit_Framework_TestCase
9
{
10
    public function testAdd()
11
    {
12
        // Arrange
13
        $vector1 = new Vector(array(1, 2, 3));
14
        $vector2 = new Vector(array(1, 2, 3));
15
16
        // Act
17
        $vector1->add($vector2);
18
19
        // Assert
20
        $this->assertEquals('[2.0000000000, 4.0000000000, 6.0000000000]', (string)$vector1);
21
    }
22
23
    /**
24
     * @expectedException InvalidArgumentException
25
     */
26
    public function testAddInvalid()
27
    {
28
        // Arrange
29
        $vector1 = new Vector(array(1, 2, 3));
30
        $vector2 = new Vector(array(1, 2, 3, 4));
31
32
        // Act
33
        $vector1->add($vector2);
34
35
        // Assert
36
        // ...
37
    }
38
39
    public function testConjugate()
40
    {
41
        // Arrange
42
        $vector = new Vector(array(1, 2, 3));
43
44
        // Act
45
        $vector->conjugate();
46
47
        // Assert
48
        $this->assertEquals('[-1.0000000000, -2.0000000000, -3.0000000000]', (string)$vector);
49
    }
50
51
    public function testDotProduct()
52
    {
53
        // Arrange
54
        $vector1 = new Vector(array(4, 5, 6));
55
        $vector2 = new Vector(array(4, 5, 6));
56
57
        // Act
58
        $dotProduct = $vector1->dotProduct($vector2);
59
60
        // Assert
61
        $this->assertInstanceOf('PHP\Math\BigNumber\BigNumber', $dotProduct);
62
        $this->assertEquals('77.0000000000', $dotProduct);
63
    }
64
65
    /**
66
     * @expectedException InvalidArgumentException
67
     */
68
    public function testDotProductWithInvalidSizeVector()
69
    {
70
        // Arrange
71
        $vector1 = new Vector(array(4, 5, 6));
72
        $vector2 = new Vector(array(4, 5, 6, 7));
73
74
        // Act
75
        $vector1->dotProduct($vector2);
76
77
        // Assert
78
        // ...
79
    }
80
81
    public function testGetLength()
82
    {
83
        // Arrange
84
        $vector = new Vector(array(3));
85
86
        // Act
87
        $result = $vector->getLength();
88
89
        // Assert
90
        $this->assertInstanceOf('PHP\Math\BigNumber\BigNumber', $result);
91
        $this->assertEquals('3.0', $result);
92
    }
93
94
    public function testGetLengthSquared()
95
    {
96
        // Arrange
97
        $vector = new Vector(array(3));
98
99
        // Act
100
        $result = $vector->getLengthSquared();
101
102
        // Assert
103
        $this->assertInstanceOf('PHP\Math\BigNumber\BigNumber', $result);
104
        $this->assertEquals('9.0', $result);
105
    }
106
107
    public function testGetMagnitude()
108
    {
109
        // Arrange
110
        $vector = new Vector(array(3));
111
112
        // Act
113
        $result = $vector->getMagnitude();
114
115
        // Assert
116
        $this->assertInstanceOf('PHP\Math\BigNumber\BigNumber', $result);
117
        $this->assertEquals('3.0', $result);
118
    }
119
120
    public function testNegate()
121
    {
122
        // Arrange
123
        $vector = new Vector(array(1, 2, 3));
124
125
        // Act
126
        $vector->negate();
127
128
        // Assert
129
        $this->assertEquals('[-1.0000000000, -2.0000000000, -3.0000000000]', (string)$vector);
130
    }
131
132
    public function testNormalize()
133
    {
134
        // Arrange
135
        $vector = new Vector(array(3));
136
137
        // Act
138
        $vector->normalize();
139
140
        // Assert
141
        $this->assertEquals('1.0', (string)$vector->getLength());
142
    }
143
144
    public function testReverse()
145
    {
146
        // Arrange
147
        $vector = new Vector(array(1, 2, 3));
148
149
        // Act
150
        $vector->reverse();
151
152
        // Assert
153
        $this->assertEquals('[-1.0000000000, -2.0000000000, -3.0000000000]', (string)$vector);
154
    }
155
156
    public function testScale()
157
    {
158
        // Arrange
159
        $vector = new Vector(array(4, 5, 6));
160
161
        // Act
162
        $vector->scale(2);
163
164
        // Assert
165
        $this->assertEquals('[8.0000000000, 10.0000000000, 12.0000000000]', (string)$vector);
166
    }
167
168
    public function testSubtract()
169
    {
170
        // Arrange
171
        $vector1 = new Vector(array(1, 2, 3));
172
        $vector2 = new Vector(array(1, 2, 3));
173
174
        // Act
175
        $vector1->subtract($vector2);
176
177
        // Assert
178
        $this->assertEquals('[0.0000000000, 0.0000000000, 0.0000000000]', (string)$vector1);
179
    }
180
181
    /**
182
     * @expectedException InvalidArgumentException
183
     */
184
    public function testSubtractInvalid()
185
    {
186
        // Arrange
187
        $vector1 = new Vector(array(1, 2, 3));
188
        $vector2 = new Vector(array(1, 2, 3, 4));
189
190
        // Act
191
        $vector1->subtract($vector2);
192
193
        // Assert
194
        // ...
195
    }
196
}
197