|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PHP\Math\VectorTest; |
|
4
|
|
|
|
|
5
|
|
|
use PHP\Math\Vector\Tuple; |
|
6
|
|
|
use PHPUnit_Framework_TestCase; |
|
7
|
|
|
|
|
8
|
|
|
class TupleTest extends PHPUnit_Framework_TestCase |
|
9
|
|
|
{ |
|
10
|
|
|
public function testConstructor() |
|
11
|
|
|
{ |
|
12
|
|
|
// Arrange |
|
13
|
|
|
// ... |
|
14
|
|
|
|
|
15
|
|
|
// Act |
|
16
|
|
|
$tuple = new Tuple(range(1, 5)); |
|
17
|
|
|
|
|
18
|
|
|
// Assert |
|
19
|
|
|
$this->assertEquals('[1.0000000000, 2.0000000000, 3.0000000000, 4.0000000000, 5.0000000000]', (string)$tuple); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testAdd() |
|
23
|
|
|
{ |
|
24
|
|
|
// Arrange |
|
25
|
|
|
$tuple = new Tuple(range(1, 5)); |
|
26
|
|
|
|
|
27
|
|
|
// Act |
|
28
|
|
|
$index = $tuple->addElement(6); |
|
29
|
|
|
|
|
30
|
|
|
// Assert |
|
31
|
|
|
$this->assertInternalType('integer', $index); |
|
32
|
|
|
$this->assertEquals(5, $index); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testGet() |
|
36
|
|
|
{ |
|
37
|
|
|
// Arrange |
|
38
|
|
|
$tuple = new Tuple(range(1, 5)); |
|
39
|
|
|
|
|
40
|
|
|
// Act |
|
41
|
|
|
$element = $tuple->getElement(1); |
|
42
|
|
|
|
|
43
|
|
|
// Assert |
|
44
|
|
|
$this->assertEquals('2', $element); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @expectedException InvalidArgumentException |
|
49
|
|
|
*/ |
|
50
|
|
|
public function testGetWithIndexTooBig() |
|
51
|
|
|
{ |
|
52
|
|
|
// Arrange |
|
53
|
|
|
$tuple = new Tuple(range(1, 5)); |
|
54
|
|
|
|
|
55
|
|
|
// Act |
|
56
|
|
|
$tuple->getElement(111); |
|
57
|
|
|
|
|
58
|
|
|
// Assert |
|
59
|
|
|
// ... |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @expectedException InvalidArgumentException |
|
64
|
|
|
*/ |
|
65
|
|
|
public function testGetWithIndexTooSmall() |
|
66
|
|
|
{ |
|
67
|
|
|
// Arrange |
|
68
|
|
|
$tuple = new Tuple(range(1, 5)); |
|
69
|
|
|
|
|
70
|
|
|
// Act |
|
71
|
|
|
$tuple->getElement(-111); |
|
72
|
|
|
|
|
73
|
|
|
// Assert |
|
74
|
|
|
// ... |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
public function testRemove() |
|
78
|
|
|
{ |
|
79
|
|
|
// Arrange |
|
80
|
|
|
$tuple = new Tuple(range(1, 5)); |
|
81
|
|
|
|
|
82
|
|
|
// Act |
|
83
|
|
|
$element = $tuple->removeElementIndex(0); |
|
84
|
|
|
|
|
85
|
|
|
// Assert |
|
86
|
|
|
$this->assertInstanceOf('PHP\Math\BigNumber\BigNumber', $element); |
|
87
|
|
|
$this->assertEquals(1, (string)$element); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function testRemoveInvalidIndex() |
|
91
|
|
|
{ |
|
92
|
|
|
// Arrange |
|
93
|
|
|
$tuple = new Tuple(range(1, 5)); |
|
94
|
|
|
|
|
95
|
|
|
// Act |
|
96
|
|
|
$element = $tuple->removeElementIndex(123); |
|
97
|
|
|
|
|
98
|
|
|
// Assert |
|
99
|
|
|
$this->assertNull($element); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function testRemoveElement() |
|
103
|
|
|
{ |
|
104
|
|
|
// Arrange |
|
105
|
|
|
$tuple = new Tuple(range(1, 5)); |
|
106
|
|
|
|
|
107
|
|
|
// Act |
|
108
|
|
|
$element = $tuple->removeElement(2); |
|
109
|
|
|
|
|
110
|
|
|
// Assert |
|
111
|
|
|
$this->assertTrue($element); |
|
112
|
|
|
} |
|
113
|
|
|
|
|
114
|
|
|
public function testRemoveElementInvalidElement() |
|
115
|
|
|
{ |
|
116
|
|
|
// Arrange |
|
117
|
|
|
$tuple = new Tuple(range(1, 5)); |
|
118
|
|
|
|
|
119
|
|
|
// Act |
|
120
|
|
|
$element = $tuple->removeElement(123); |
|
121
|
|
|
|
|
122
|
|
|
// Assert |
|
123
|
|
|
$this->assertFalse($element); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
public function testSet() |
|
127
|
|
|
{ |
|
128
|
|
|
// Arrange |
|
129
|
|
|
$tuple = new Tuple(range(1, 5)); |
|
130
|
|
|
|
|
131
|
|
|
// Act |
|
132
|
|
|
$tuple->setElement(1, 0); |
|
133
|
|
|
|
|
134
|
|
|
// Assert |
|
135
|
|
|
$this->assertEquals('0', $tuple->getElement(1)); |
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
public function testSetWithIndexTooBig() |
|
139
|
|
|
{ |
|
140
|
|
|
// Arrange |
|
141
|
|
|
$tuple = new Tuple(range(1, 5)); |
|
142
|
|
|
|
|
143
|
|
|
// Act |
|
144
|
|
|
$tuple->setElement(111, 0); |
|
145
|
|
|
|
|
146
|
|
|
// Assert |
|
147
|
|
|
$this->assertCount(112, $tuple); |
|
148
|
|
|
$this->assertEquals('0', $tuple->getElement(111)); |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
/** |
|
152
|
|
|
* @expectedException InvalidArgumentException |
|
153
|
|
|
*/ |
|
154
|
|
|
public function testSetWithIndexTooSmall() |
|
155
|
|
|
{ |
|
156
|
|
|
// Arrange |
|
157
|
|
|
$tuple = new Tuple(range(1, 5)); |
|
158
|
|
|
|
|
159
|
|
|
// Act |
|
160
|
|
|
$tuple->setElement(-111, 0); |
|
161
|
|
|
|
|
162
|
|
|
// Assert |
|
163
|
|
|
// ... |
|
164
|
|
|
} |
|
165
|
|
|
|
|
166
|
|
|
public function testGetSize() |
|
167
|
|
|
{ |
|
168
|
|
|
// Arrange |
|
169
|
|
|
$tuple = new Tuple(range(1, 5)); |
|
170
|
|
|
|
|
171
|
|
|
// Act |
|
172
|
|
|
$size = $tuple->getSize(); |
|
173
|
|
|
|
|
174
|
|
|
// Assert |
|
175
|
|
|
$this->assertEquals(5, $size); |
|
176
|
|
|
} |
|
177
|
|
|
|
|
178
|
|
|
public function testGetMaximumValue() |
|
179
|
|
|
{ |
|
180
|
|
|
// Arrange |
|
181
|
|
|
$tuple = new Tuple(range(1, 5)); |
|
182
|
|
|
|
|
183
|
|
|
// Act |
|
184
|
|
|
$size = $tuple->getMaximumValue(); |
|
185
|
|
|
|
|
186
|
|
|
// Assert |
|
187
|
|
|
$this->assertInstanceOf('PHP\Math\BigNumber\BigNumber', $size); |
|
188
|
|
|
$this->assertEquals('5', $size->getValue()); |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
public function testGetMinimumValue() |
|
192
|
|
|
{ |
|
193
|
|
|
// Arrange |
|
194
|
|
|
$tuple = new Tuple(range(1, 5)); |
|
195
|
|
|
|
|
196
|
|
|
// Act |
|
197
|
|
|
$size = $tuple->getMinimumValue(); |
|
198
|
|
|
|
|
199
|
|
|
// Assert |
|
200
|
|
|
$this->assertInstanceOf('PHP\Math\BigNumber\BigNumber', $size); |
|
201
|
|
|
$this->assertEquals('1', $size->getValue()); |
|
202
|
|
|
} |
|
203
|
|
|
} |
|
204
|
|
|
|