Skip to content

Commit d1cab0e

Browse files
committed
Convert unittests to PHP 8 attributes
1 parent c619eff commit d1cab0e

3 files changed

Lines changed: 154 additions & 147 deletions

File tree

src/test/php/math/unittest/BigFloatTest.class.php

Lines changed: 63 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -2,327 +2,328 @@
22

33
use lang\IllegalArgumentException;
44
use math\{BigFloat, BigInt};
5+
use unittest\{Expect, Test};
56

67
class BigFloatTest extends \unittest\TestCase {
78

8-
#[@test]
9+
#[Test]
910
public function floatFromInt() {
1011
$this->assertEquals(new BigFloat(2.0), new BigFloat(new BigInt(2)));
1112
}
1213

13-
#[@test]
14+
#[Test]
1415
public function castableToString() {
1516
$this->assertEquals('6100', (string)new BigFloat(6100.0));
1617
}
1718

18-
#[@test]
19+
#[Test]
1920
public function castableToStringNegative() {
2021
$this->assertEquals('-6100', (string)new BigFloat(-6100.0));
2122
}
2223

23-
#[@test]
24+
#[Test]
2425
public function castableToStringHalf() {
2526
$this->assertEquals('0.5', (string)new BigFloat(0.5));
2627
}
2728

28-
#[@test]
29+
#[Test]
2930
public function intValue() {
3031
$this->assertEquals(6100, (new BigFloat(6100.0))->intValue());
3132
}
3233

33-
#[@test]
34+
#[Test]
3435
public function intValueNegative() {
3536
$this->assertEquals(-6100, (new BigFloat(-6100.0))->intValue());
3637
}
3738

38-
#[@test]
39+
#[Test]
3940
public function doubleValue() {
4041
$this->assertEquals(6100.0, (new BigFloat(6100.0))->doubleValue());
4142
}
4243

43-
#[@test]
44+
#[Test]
4445
public function doubleValueNegative() {
4546
$this->assertEquals(-6100.0, (new BigFloat(-6100.0))->doubleValue());
4647
}
4748

48-
#[@test]
49+
#[Test]
4950
public function addition() {
5051
$this->assertEquals(new BigFloat(2.0), (new BigFloat(1.0))->add(new BigFloat(1.0)));
5152
}
5253

53-
#[@test]
54+
#[Test]
5455
public function additionOneNegative() {
5556
$this->assertEquals(new BigFloat(0.0), (new BigFloat(-1.0))->add(new BigFloat(1.0)));
5657
}
5758

58-
#[@test]
59+
#[Test]
5960
public function additionBothNegative() {
6061
$this->assertEquals(new BigFloat(-2), (new BigFloat(-1.0))->add(new BigFloat(-1.0)));
6162
}
6263

63-
#[@test]
64+
#[Test]
6465
public function additionLarge() {
6566
$a= new BigFloat('3648686172031547129462783484965308369824430041997653001183827180347.1');
6667
$b= new BigFloat('1067825251034421530837885294271156039110655362253362224471523.9');
6768
$r= new BigFloat('3648687239856798163884314322850602640980469152653015254546051651871');
6869
$this->assertEquals($r, $a->add($b));
6970
}
7071

71-
#[@test]
72+
#[Test]
7273
public function additionWithPrimitive() {
7374
$this->assertEquals(new BigFloat(6100.0), (new BigFloat(1.0))->add(6099.0));
7475
}
7576

76-
#[@test]
77+
#[Test]
7778
public function subtraction() {
7879
$this->assertEquals(new BigFloat(0.0), (new BigFloat(1.0))->subtract(new BigFloat(1.0)));
7980
}
8081

81-
#[@test]
82+
#[Test]
8283
public function subtractionOneNegative() {
8384
$this->assertEquals(new BigFloat(-2.0), (new BigFloat(-1.0))->subtract(new BigFloat(1.0)));
8485
}
8586

86-
#[@test]
87+
#[Test]
8788
public function subtractionBothNegative() {
8889
$this->assertEquals(new BigFloat(0.0), (new BigFloat(-1.0))->subtract(new BigFloat(-1.0)));
8990
}
9091

91-
#[@test]
92+
#[Test]
9293
public function subtractionLarge() {
9394
$a= new BigFloat('3648687239856798163884314322850602640980469152653015254546051651871');
9495
$b= new BigFloat('1067825251034421530837885294271156039110655362253362224471523.9');
9596
$r= new BigFloat('3648686172031547129462783484965308369824430041997653001183827180347.1');
9697
$this->assertEquals($r, $a->subtract($b));
9798
}
9899

99-
#[@test]
100+
#[Test]
100101
public function subtractionWithPrimitive() {
101102
$this->assertEquals(new BigFloat(-6100.0), (new BigFloat(-1.0))->subtract(6099.0));
102103
}
103104

104-
#[@test]
105+
#[Test]
105106
public function multiplication() {
106107
$this->assertEquals(new BigFloat(1.0), (new BigFloat(1.0))->multiply(new BigFloat(1.0)));
107108
}
108109

109-
#[@test]
110+
#[Test]
110111
public function multiplicationOneNegative() {
111112
$this->assertEquals(new BigFloat(-1.0), (new BigFloat(-1.0))->multiply(new BigFloat(1.0)));
112113
}
113114

114-
#[@test]
115+
#[Test]
115116
public function multiplicationBothNegative() {
116117
$this->assertEquals(new BigFloat(1.0), (new BigFloat(-1.0))->multiply(new BigFloat(-1.0)));
117118
}
118119

119-
#[@test]
120+
#[Test]
120121
public function multiplicationLarge() {
121122
$a= new BigFloat('36486872398567981638843143228254546051651870.2');
122123
$b= new BigFloat('50602640980469152653015.1');
123124
$r= new BigFloat('1846332104484924953979623193074019910923757259978350589582121583840.02');
124125
$this->assertEquals($r, $a->multiply($b));
125126
}
126127

127-
#[@test]
128+
#[Test]
128129
public function multiplicationWithPrimitive() {
129130
$this->assertEquals(new BigFloat(6100.0), (new BigFloat(-1.0))->multiply(-6100.0));
130131
}
131132

132-
#[@test]
133+
#[Test]
133134
public function division() {
134135
$this->assertEquals(new BigFloat(2.0), (new BigFloat(4.0))->divide(new BigFloat(2.0)));
135136
}
136137

137-
#[@test]
138+
#[Test]
138139
public function divisionOneNegative() {
139140
$this->assertEquals(new BigFloat(-2.0), (new BigFloat(-4.0))->divide(new BigFloat(2.0)));
140141
}
141142

142-
#[@test]
143+
#[Test]
143144
public function divisionBothNegative() {
144145
$this->assertEquals(new BigFloat(2.0), (new BigFloat(-4.0))->divide(new BigFloat(-2.0)));
145146
}
146147

147-
#[@test]
148+
#[Test]
148149
public function divisionLarge() {
149150
$a= new BigFloat('1846332104484924953979619544386780054125593365543499568033685888050.0');
150151
$b= new BigFloat('36486872398567981638843143228254546051651870.0');
151152
$r= new BigFloat('50602640980469152653015.0');
152153
$this->assertEquals($r, $a->divide($b));
153154
}
154155

155-
#[@test]
156+
#[Test]
156157
public function divisionWithPrimitive() {
157158
$this->assertEquals(new BigFloat(6100.0), (new BigFloat(37210000.0))->divide(6100.0));
158159
}
159160

160-
#[@test, @expect(IllegalArgumentException::class)]
161+
#[Test, Expect(IllegalArgumentException::class)]
161162
public function divisionByZero() {
162163
(new BigFloat(5.0))->divide(new BigFloat(0.0));
163164
}
164165

165-
#[@test]
166+
#[Test]
166167
public function power() {
167168
$this->assertEquals(new BigFloat(16.0), (new BigFloat(2.0))->power(new BigFloat(4.0)));
168169
}
169170

170-
#[@test]
171+
#[Test]
171172
public function powerNegativeOne() {
172173
$this->assertEquals(new BigFloat('0.5'), (new BigFloat(2.0))->power(new BigFloat(-1.0)));
173174
}
174175

175-
#[@test]
176+
#[Test]
176177
public function powerOfZero() {
177178
$this->assertEquals(new BigFloat(0.0), (new BigFloat(0.0))->power(new BigFloat(2.0)));
178179
}
179180

180-
#[@test]
181+
#[Test]
181182
public function powerOfZeroZero() {
182183
$this->assertEquals(new BigFloat(1.0), (new BigFloat(0.0))->power(new BigFloat(0.0)));
183184
}
184185

185-
#[@test]
186+
#[Test]
186187
public function powerOfZeroNegative() {
187188
$this->assertEquals(new BigFloat(0.0), (new BigFloat(0.0))->power(new BigFloat(-2)));
188189
}
189190

190-
#[@test]
191+
#[Test]
191192
public function powerOfNegativeNumberEven() {
192193
$this->assertEquals(new BigFloat(4.0), (new BigFloat(-2.0))->power(new BigFloat(2.0)));
193194
}
194195

195-
#[@test]
196+
#[Test]
196197
public function powerOfNegativeNumberOdd() {
197198
$this->assertEquals(new BigFloat(-8.0), (new BigFloat(-2.0))->power(new BigFloat(3.0)));
198199
}
199200

200-
#[@test]
201+
#[Test]
201202
public function powerOne() {
202203
$this->assertEquals(new BigFloat(2.0), (new BigFloat(2.0))->power(new BigFloat(1.0)));
203204
}
204205

205-
#[@test]
206+
#[Test]
206207
public function powerZero() {
207208
$this->assertEquals(new BigFloat(1.0), (new BigFloat(2.0))->power(new BigFloat(0.0)));
208209
}
209210

210-
#[@test]
211+
#[Test]
211212
public function powerWithPrimitive() {
212213
$this->assertEquals(new BigFloat(4.0), (new BigFloat(2.0))->power(2.0));
213214
}
214215

215-
#[@test]
216+
#[Test]
216217
public function ceil() {
217218
$this->assertEquals(new BigFloat(5.0), (new BigFloat(4.5))->ceil());
218219
}
219220

220-
#[@test]
221+
#[Test]
221222
public function ceilInt() {
222223
$this->assertEquals(new BigFloat(4.0), (new BigFloat(4.0))->ceil());
223224
}
224225

225-
#[@test]
226+
#[Test]
226227
public function ceilClose() {
227228
$this->assertEquals(new BigFloat(10.0), (new BigFloat(9.999))->ceil());
228229
}
229230

230-
#[@test]
231+
#[Test]
231232
public function ceilNegative() {
232233
$this->assertEquals(new BigFloat(-4.0), (new BigFloat(-4.5))->ceil());
233234
}
234235

235-
#[@test]
236+
#[Test]
236237
public function floor() {
237238
$this->assertEquals(new BigFloat(4.0), (new BigFloat(4.5))->floor());
238239
}
239240

240-
#[@test]
241+
#[Test]
241242
public function floorInt() {
242243
$this->assertEquals(new BigFloat(4.0), (new BigFloat(4.0))->floor());
243244
}
244245

245-
#[@test]
246+
#[Test]
246247
public function floorClose() {
247248
$this->assertEquals(new BigFloat(9.0), (new BigFloat(9.999))->floor());
248249
}
249250

250-
#[@test]
251+
#[Test]
251252
public function floorNegative() {
252253
$this->assertEquals(new BigFloat(-5.0), (new BigFloat(-4.5))->floor());
253254
}
254255

255-
#[@test]
256+
#[Test]
256257
public function roundWhole() {
257258
$this->assertEquals(new BigFloat(4.0), (new BigFloat(4.0))->round());
258259
}
259260

260-
#[@test]
261+
#[Test]
261262
public function round() {
262263
$this->assertEquals(new BigFloat(4.0), (new BigFloat(4.4))->round());
263264
}
264265

265-
#[@test]
266+
#[Test]
266267
public function roundNegative() {
267268
$this->assertEquals(new BigFloat(-4.0), (new BigFloat(-4.4))->round());
268269
}
269270

270-
#[@test]
271+
#[Test]
271272
public function roundHalf() {
272273
$this->assertEquals(new BigFloat(5.0), (new BigFloat(4.5))->round());
273274
}
274275

275-
#[@test]
276+
#[Test]
276277
public function roundNegativeHalf() {
277278
$this->assertEquals(new BigFloat(-5.0), (new BigFloat(-4.5))->round());
278279
}
279280

280-
#[@test]
281+
#[Test]
281282
public function roundAlmostHalf() {
282283
$this->assertEquals(new BigFloat(4.0), (new BigFloat(4.499999))->round());
283284
}
284285

285-
#[@test]
286+
#[Test]
286287
public function roundNegativeAlmostHalf() {
287288
$this->assertEquals(new BigFloat(-4.0), (new BigFloat(-4.499999))->round());
288289
}
289290

290-
#[@test]
291+
#[Test]
291292
public function roundEuroToDeutscheMarkExchangeRateToTwoDigits() {
292293
$this->assertEquals(new BigFloat(1.96), (new BigFloat(1.95583))->round(2));
293294
}
294295

295-
#[@test]
296+
#[Test]
296297
public function roundSample1() {
297298
$this->assertEquals(new BigFloat(323.35), (new BigFloat(323.346))->round(2));
298299
}
299300

300-
#[@test]
301+
#[Test]
301302
public function roundSample2() {
302303
$this->assertEquals(new BigFloat(323.01), (new BigFloat(323.006))->round(2));
303304
}
304305

305-
#[@test]
306+
#[Test]
306307
public function ceilLotsOfZeros() {
307308
$this->assertEquals(new BigFloat(4.0), (new BigFloat('4.00000000000000000'))->ceil());
308309
}
309310

310-
#[@test]
311+
#[Test]
311312
public function floorLotsOfZeros() {
312313
$this->assertEquals(new BigFloat(4.0), (new BigFloat('4.00000000000000000'))->floor());
313314
}
314315

315-
#[@test]
316+
#[Test]
316317
public function roundLotsOfZeros() {
317318
$this->assertEquals(new BigFloat(4.0), (new BigFloat('4.00000000000000000'))->round());
318319
}
319320

320-
#[@test]
321+
#[Test]
321322
public function positive_string_representation() {
322323
$this->assertEquals('math.BigFloat(4)', (new BigFloat(4.0))->toString());
323324
}
324325

325-
#[@test]
326+
#[Test]
326327
public function negative_string_representation() {
327328
$this->assertEquals('math.BigFloat(-4)', (new BigFloat(-4.0))->toString());
328329
}

0 commit comments

Comments
 (0)