|
2 | 2 |
|
3 | 3 | use lang\IllegalArgumentException; |
4 | 4 | use math\{BigFloat, BigInt}; |
| 5 | +use unittest\{Expect, Test}; |
5 | 6 |
|
6 | 7 | class BigFloatTest extends \unittest\TestCase { |
7 | 8 |
|
8 | | - #[@test] |
| 9 | + #[Test] |
9 | 10 | public function floatFromInt() { |
10 | 11 | $this->assertEquals(new BigFloat(2.0), new BigFloat(new BigInt(2))); |
11 | 12 | } |
12 | 13 |
|
13 | | - #[@test] |
| 14 | + #[Test] |
14 | 15 | public function castableToString() { |
15 | 16 | $this->assertEquals('6100', (string)new BigFloat(6100.0)); |
16 | 17 | } |
17 | 18 |
|
18 | | - #[@test] |
| 19 | + #[Test] |
19 | 20 | public function castableToStringNegative() { |
20 | 21 | $this->assertEquals('-6100', (string)new BigFloat(-6100.0)); |
21 | 22 | } |
22 | 23 |
|
23 | | - #[@test] |
| 24 | + #[Test] |
24 | 25 | public function castableToStringHalf() { |
25 | 26 | $this->assertEquals('0.5', (string)new BigFloat(0.5)); |
26 | 27 | } |
27 | 28 |
|
28 | | - #[@test] |
| 29 | + #[Test] |
29 | 30 | public function intValue() { |
30 | 31 | $this->assertEquals(6100, (new BigFloat(6100.0))->intValue()); |
31 | 32 | } |
32 | 33 |
|
33 | | - #[@test] |
| 34 | + #[Test] |
34 | 35 | public function intValueNegative() { |
35 | 36 | $this->assertEquals(-6100, (new BigFloat(-6100.0))->intValue()); |
36 | 37 | } |
37 | 38 |
|
38 | | - #[@test] |
| 39 | + #[Test] |
39 | 40 | public function doubleValue() { |
40 | 41 | $this->assertEquals(6100.0, (new BigFloat(6100.0))->doubleValue()); |
41 | 42 | } |
42 | 43 |
|
43 | | - #[@test] |
| 44 | + #[Test] |
44 | 45 | public function doubleValueNegative() { |
45 | 46 | $this->assertEquals(-6100.0, (new BigFloat(-6100.0))->doubleValue()); |
46 | 47 | } |
47 | 48 |
|
48 | | - #[@test] |
| 49 | + #[Test] |
49 | 50 | public function addition() { |
50 | 51 | $this->assertEquals(new BigFloat(2.0), (new BigFloat(1.0))->add(new BigFloat(1.0))); |
51 | 52 | } |
52 | 53 |
|
53 | | - #[@test] |
| 54 | + #[Test] |
54 | 55 | public function additionOneNegative() { |
55 | 56 | $this->assertEquals(new BigFloat(0.0), (new BigFloat(-1.0))->add(new BigFloat(1.0))); |
56 | 57 | } |
57 | 58 |
|
58 | | - #[@test] |
| 59 | + #[Test] |
59 | 60 | public function additionBothNegative() { |
60 | 61 | $this->assertEquals(new BigFloat(-2), (new BigFloat(-1.0))->add(new BigFloat(-1.0))); |
61 | 62 | } |
62 | 63 |
|
63 | | - #[@test] |
| 64 | + #[Test] |
64 | 65 | public function additionLarge() { |
65 | 66 | $a= new BigFloat('3648686172031547129462783484965308369824430041997653001183827180347.1'); |
66 | 67 | $b= new BigFloat('1067825251034421530837885294271156039110655362253362224471523.9'); |
67 | 68 | $r= new BigFloat('3648687239856798163884314322850602640980469152653015254546051651871'); |
68 | 69 | $this->assertEquals($r, $a->add($b)); |
69 | 70 | } |
70 | 71 |
|
71 | | - #[@test] |
| 72 | + #[Test] |
72 | 73 | public function additionWithPrimitive() { |
73 | 74 | $this->assertEquals(new BigFloat(6100.0), (new BigFloat(1.0))->add(6099.0)); |
74 | 75 | } |
75 | 76 |
|
76 | | - #[@test] |
| 77 | + #[Test] |
77 | 78 | public function subtraction() { |
78 | 79 | $this->assertEquals(new BigFloat(0.0), (new BigFloat(1.0))->subtract(new BigFloat(1.0))); |
79 | 80 | } |
80 | 81 |
|
81 | | - #[@test] |
| 82 | + #[Test] |
82 | 83 | public function subtractionOneNegative() { |
83 | 84 | $this->assertEquals(new BigFloat(-2.0), (new BigFloat(-1.0))->subtract(new BigFloat(1.0))); |
84 | 85 | } |
85 | 86 |
|
86 | | - #[@test] |
| 87 | + #[Test] |
87 | 88 | public function subtractionBothNegative() { |
88 | 89 | $this->assertEquals(new BigFloat(0.0), (new BigFloat(-1.0))->subtract(new BigFloat(-1.0))); |
89 | 90 | } |
90 | 91 |
|
91 | | - #[@test] |
| 92 | + #[Test] |
92 | 93 | public function subtractionLarge() { |
93 | 94 | $a= new BigFloat('3648687239856798163884314322850602640980469152653015254546051651871'); |
94 | 95 | $b= new BigFloat('1067825251034421530837885294271156039110655362253362224471523.9'); |
95 | 96 | $r= new BigFloat('3648686172031547129462783484965308369824430041997653001183827180347.1'); |
96 | 97 | $this->assertEquals($r, $a->subtract($b)); |
97 | 98 | } |
98 | 99 |
|
99 | | - #[@test] |
| 100 | + #[Test] |
100 | 101 | public function subtractionWithPrimitive() { |
101 | 102 | $this->assertEquals(new BigFloat(-6100.0), (new BigFloat(-1.0))->subtract(6099.0)); |
102 | 103 | } |
103 | 104 |
|
104 | | - #[@test] |
| 105 | + #[Test] |
105 | 106 | public function multiplication() { |
106 | 107 | $this->assertEquals(new BigFloat(1.0), (new BigFloat(1.0))->multiply(new BigFloat(1.0))); |
107 | 108 | } |
108 | 109 |
|
109 | | - #[@test] |
| 110 | + #[Test] |
110 | 111 | public function multiplicationOneNegative() { |
111 | 112 | $this->assertEquals(new BigFloat(-1.0), (new BigFloat(-1.0))->multiply(new BigFloat(1.0))); |
112 | 113 | } |
113 | 114 |
|
114 | | - #[@test] |
| 115 | + #[Test] |
115 | 116 | public function multiplicationBothNegative() { |
116 | 117 | $this->assertEquals(new BigFloat(1.0), (new BigFloat(-1.0))->multiply(new BigFloat(-1.0))); |
117 | 118 | } |
118 | 119 |
|
119 | | - #[@test] |
| 120 | + #[Test] |
120 | 121 | public function multiplicationLarge() { |
121 | 122 | $a= new BigFloat('36486872398567981638843143228254546051651870.2'); |
122 | 123 | $b= new BigFloat('50602640980469152653015.1'); |
123 | 124 | $r= new BigFloat('1846332104484924953979623193074019910923757259978350589582121583840.02'); |
124 | 125 | $this->assertEquals($r, $a->multiply($b)); |
125 | 126 | } |
126 | 127 |
|
127 | | - #[@test] |
| 128 | + #[Test] |
128 | 129 | public function multiplicationWithPrimitive() { |
129 | 130 | $this->assertEquals(new BigFloat(6100.0), (new BigFloat(-1.0))->multiply(-6100.0)); |
130 | 131 | } |
131 | 132 |
|
132 | | - #[@test] |
| 133 | + #[Test] |
133 | 134 | public function division() { |
134 | 135 | $this->assertEquals(new BigFloat(2.0), (new BigFloat(4.0))->divide(new BigFloat(2.0))); |
135 | 136 | } |
136 | 137 |
|
137 | | - #[@test] |
| 138 | + #[Test] |
138 | 139 | public function divisionOneNegative() { |
139 | 140 | $this->assertEquals(new BigFloat(-2.0), (new BigFloat(-4.0))->divide(new BigFloat(2.0))); |
140 | 141 | } |
141 | 142 |
|
142 | | - #[@test] |
| 143 | + #[Test] |
143 | 144 | public function divisionBothNegative() { |
144 | 145 | $this->assertEquals(new BigFloat(2.0), (new BigFloat(-4.0))->divide(new BigFloat(-2.0))); |
145 | 146 | } |
146 | 147 |
|
147 | | - #[@test] |
| 148 | + #[Test] |
148 | 149 | public function divisionLarge() { |
149 | 150 | $a= new BigFloat('1846332104484924953979619544386780054125593365543499568033685888050.0'); |
150 | 151 | $b= new BigFloat('36486872398567981638843143228254546051651870.0'); |
151 | 152 | $r= new BigFloat('50602640980469152653015.0'); |
152 | 153 | $this->assertEquals($r, $a->divide($b)); |
153 | 154 | } |
154 | 155 |
|
155 | | - #[@test] |
| 156 | + #[Test] |
156 | 157 | public function divisionWithPrimitive() { |
157 | 158 | $this->assertEquals(new BigFloat(6100.0), (new BigFloat(37210000.0))->divide(6100.0)); |
158 | 159 | } |
159 | 160 |
|
160 | | - #[@test, @expect(IllegalArgumentException::class)] |
| 161 | + #[Test, Expect(IllegalArgumentException::class)] |
161 | 162 | public function divisionByZero() { |
162 | 163 | (new BigFloat(5.0))->divide(new BigFloat(0.0)); |
163 | 164 | } |
164 | 165 |
|
165 | | - #[@test] |
| 166 | + #[Test] |
166 | 167 | public function power() { |
167 | 168 | $this->assertEquals(new BigFloat(16.0), (new BigFloat(2.0))->power(new BigFloat(4.0))); |
168 | 169 | } |
169 | 170 |
|
170 | | - #[@test] |
| 171 | + #[Test] |
171 | 172 | public function powerNegativeOne() { |
172 | 173 | $this->assertEquals(new BigFloat('0.5'), (new BigFloat(2.0))->power(new BigFloat(-1.0))); |
173 | 174 | } |
174 | 175 |
|
175 | | - #[@test] |
| 176 | + #[Test] |
176 | 177 | public function powerOfZero() { |
177 | 178 | $this->assertEquals(new BigFloat(0.0), (new BigFloat(0.0))->power(new BigFloat(2.0))); |
178 | 179 | } |
179 | 180 |
|
180 | | - #[@test] |
| 181 | + #[Test] |
181 | 182 | public function powerOfZeroZero() { |
182 | 183 | $this->assertEquals(new BigFloat(1.0), (new BigFloat(0.0))->power(new BigFloat(0.0))); |
183 | 184 | } |
184 | 185 |
|
185 | | - #[@test] |
| 186 | + #[Test] |
186 | 187 | public function powerOfZeroNegative() { |
187 | 188 | $this->assertEquals(new BigFloat(0.0), (new BigFloat(0.0))->power(new BigFloat(-2))); |
188 | 189 | } |
189 | 190 |
|
190 | | - #[@test] |
| 191 | + #[Test] |
191 | 192 | public function powerOfNegativeNumberEven() { |
192 | 193 | $this->assertEquals(new BigFloat(4.0), (new BigFloat(-2.0))->power(new BigFloat(2.0))); |
193 | 194 | } |
194 | 195 |
|
195 | | - #[@test] |
| 196 | + #[Test] |
196 | 197 | public function powerOfNegativeNumberOdd() { |
197 | 198 | $this->assertEquals(new BigFloat(-8.0), (new BigFloat(-2.0))->power(new BigFloat(3.0))); |
198 | 199 | } |
199 | 200 |
|
200 | | - #[@test] |
| 201 | + #[Test] |
201 | 202 | public function powerOne() { |
202 | 203 | $this->assertEquals(new BigFloat(2.0), (new BigFloat(2.0))->power(new BigFloat(1.0))); |
203 | 204 | } |
204 | 205 |
|
205 | | - #[@test] |
| 206 | + #[Test] |
206 | 207 | public function powerZero() { |
207 | 208 | $this->assertEquals(new BigFloat(1.0), (new BigFloat(2.0))->power(new BigFloat(0.0))); |
208 | 209 | } |
209 | 210 |
|
210 | | - #[@test] |
| 211 | + #[Test] |
211 | 212 | public function powerWithPrimitive() { |
212 | 213 | $this->assertEquals(new BigFloat(4.0), (new BigFloat(2.0))->power(2.0)); |
213 | 214 | } |
214 | 215 |
|
215 | | - #[@test] |
| 216 | + #[Test] |
216 | 217 | public function ceil() { |
217 | 218 | $this->assertEquals(new BigFloat(5.0), (new BigFloat(4.5))->ceil()); |
218 | 219 | } |
219 | 220 |
|
220 | | - #[@test] |
| 221 | + #[Test] |
221 | 222 | public function ceilInt() { |
222 | 223 | $this->assertEquals(new BigFloat(4.0), (new BigFloat(4.0))->ceil()); |
223 | 224 | } |
224 | 225 |
|
225 | | - #[@test] |
| 226 | + #[Test] |
226 | 227 | public function ceilClose() { |
227 | 228 | $this->assertEquals(new BigFloat(10.0), (new BigFloat(9.999))->ceil()); |
228 | 229 | } |
229 | 230 |
|
230 | | - #[@test] |
| 231 | + #[Test] |
231 | 232 | public function ceilNegative() { |
232 | 233 | $this->assertEquals(new BigFloat(-4.0), (new BigFloat(-4.5))->ceil()); |
233 | 234 | } |
234 | 235 |
|
235 | | - #[@test] |
| 236 | + #[Test] |
236 | 237 | public function floor() { |
237 | 238 | $this->assertEquals(new BigFloat(4.0), (new BigFloat(4.5))->floor()); |
238 | 239 | } |
239 | 240 |
|
240 | | - #[@test] |
| 241 | + #[Test] |
241 | 242 | public function floorInt() { |
242 | 243 | $this->assertEquals(new BigFloat(4.0), (new BigFloat(4.0))->floor()); |
243 | 244 | } |
244 | 245 |
|
245 | | - #[@test] |
| 246 | + #[Test] |
246 | 247 | public function floorClose() { |
247 | 248 | $this->assertEquals(new BigFloat(9.0), (new BigFloat(9.999))->floor()); |
248 | 249 | } |
249 | 250 |
|
250 | | - #[@test] |
| 251 | + #[Test] |
251 | 252 | public function floorNegative() { |
252 | 253 | $this->assertEquals(new BigFloat(-5.0), (new BigFloat(-4.5))->floor()); |
253 | 254 | } |
254 | 255 |
|
255 | | - #[@test] |
| 256 | + #[Test] |
256 | 257 | public function roundWhole() { |
257 | 258 | $this->assertEquals(new BigFloat(4.0), (new BigFloat(4.0))->round()); |
258 | 259 | } |
259 | 260 |
|
260 | | - #[@test] |
| 261 | + #[Test] |
261 | 262 | public function round() { |
262 | 263 | $this->assertEquals(new BigFloat(4.0), (new BigFloat(4.4))->round()); |
263 | 264 | } |
264 | 265 |
|
265 | | - #[@test] |
| 266 | + #[Test] |
266 | 267 | public function roundNegative() { |
267 | 268 | $this->assertEquals(new BigFloat(-4.0), (new BigFloat(-4.4))->round()); |
268 | 269 | } |
269 | 270 |
|
270 | | - #[@test] |
| 271 | + #[Test] |
271 | 272 | public function roundHalf() { |
272 | 273 | $this->assertEquals(new BigFloat(5.0), (new BigFloat(4.5))->round()); |
273 | 274 | } |
274 | 275 |
|
275 | | - #[@test] |
| 276 | + #[Test] |
276 | 277 | public function roundNegativeHalf() { |
277 | 278 | $this->assertEquals(new BigFloat(-5.0), (new BigFloat(-4.5))->round()); |
278 | 279 | } |
279 | 280 |
|
280 | | - #[@test] |
| 281 | + #[Test] |
281 | 282 | public function roundAlmostHalf() { |
282 | 283 | $this->assertEquals(new BigFloat(4.0), (new BigFloat(4.499999))->round()); |
283 | 284 | } |
284 | 285 |
|
285 | | - #[@test] |
| 286 | + #[Test] |
286 | 287 | public function roundNegativeAlmostHalf() { |
287 | 288 | $this->assertEquals(new BigFloat(-4.0), (new BigFloat(-4.499999))->round()); |
288 | 289 | } |
289 | 290 |
|
290 | | - #[@test] |
| 291 | + #[Test] |
291 | 292 | public function roundEuroToDeutscheMarkExchangeRateToTwoDigits() { |
292 | 293 | $this->assertEquals(new BigFloat(1.96), (new BigFloat(1.95583))->round(2)); |
293 | 294 | } |
294 | 295 |
|
295 | | - #[@test] |
| 296 | + #[Test] |
296 | 297 | public function roundSample1() { |
297 | 298 | $this->assertEquals(new BigFloat(323.35), (new BigFloat(323.346))->round(2)); |
298 | 299 | } |
299 | 300 |
|
300 | | - #[@test] |
| 301 | + #[Test] |
301 | 302 | public function roundSample2() { |
302 | 303 | $this->assertEquals(new BigFloat(323.01), (new BigFloat(323.006))->round(2)); |
303 | 304 | } |
304 | 305 |
|
305 | | - #[@test] |
| 306 | + #[Test] |
306 | 307 | public function ceilLotsOfZeros() { |
307 | 308 | $this->assertEquals(new BigFloat(4.0), (new BigFloat('4.00000000000000000'))->ceil()); |
308 | 309 | } |
309 | 310 |
|
310 | | - #[@test] |
| 311 | + #[Test] |
311 | 312 | public function floorLotsOfZeros() { |
312 | 313 | $this->assertEquals(new BigFloat(4.0), (new BigFloat('4.00000000000000000'))->floor()); |
313 | 314 | } |
314 | 315 |
|
315 | | - #[@test] |
| 316 | + #[Test] |
316 | 317 | public function roundLotsOfZeros() { |
317 | 318 | $this->assertEquals(new BigFloat(4.0), (new BigFloat('4.00000000000000000'))->round()); |
318 | 319 | } |
319 | 320 |
|
320 | | - #[@test] |
| 321 | + #[Test] |
321 | 322 | public function positive_string_representation() { |
322 | 323 | $this->assertEquals('math.BigFloat(4)', (new BigFloat(4.0))->toString()); |
323 | 324 | } |
324 | 325 |
|
325 | | - #[@test] |
| 326 | + #[Test] |
326 | 327 | public function negative_string_representation() { |
327 | 328 | $this->assertEquals('math.BigFloat(-4)', (new BigFloat(-4.0))->toString()); |
328 | 329 | } |
|
0 commit comments