@@ -40,8 +40,8 @@ public function testAdd(int $scale, mixed $value, mixed $other, array $expected)
40
40
41
41
/** @Then the result should have the correct scale and values */
42
42
self ::assertSame ($ scale , $ actual ->getScale ());
43
+ self ::assertSame ($ expected ['float ' ], $ actual ->toFloat ());
43
44
self ::assertSame ($ expected ['string ' ], $ actual ->toString ());
44
- self ::assertSame (floatval ($ expected ['float ' ]), $ actual ->toFloat ());
45
45
}
46
46
47
47
#[DataProvider('providerForTestSubtract ' )]
@@ -56,8 +56,8 @@ public function testSubtract(int $scale, mixed $value, mixed $other, array $expe
56
56
57
57
/** @Then the result should have the correct scale and values */
58
58
self ::assertSame ($ scale , $ actual ->getScale ());
59
+ self ::assertSame ($ expected ['float ' ], $ actual ->toFloat ());
59
60
self ::assertSame ($ expected ['string ' ], $ actual ->toString ());
60
- self ::assertSame (floatval ($ expected ['float ' ]), $ actual ->toFloat ());
61
61
}
62
62
63
63
#[DataProvider('providerForTestMultiply ' )]
@@ -72,8 +72,8 @@ public function testMultiply(int $scale, mixed $value, mixed $other, array $expe
72
72
73
73
/** @Then the result should have the correct scale and values */
74
74
self ::assertSame ($ scale , $ actual ->getScale ());
75
+ self ::assertSame ($ expected ['float ' ], $ actual ->toFloat ());
75
76
self ::assertSame ($ expected ['string ' ], $ actual ->toString ());
76
- self ::assertSame (floatval ($ expected ['float ' ]), $ actual ->toFloat ());
77
77
}
78
78
79
79
#[DataProvider('providerForTestDivide ' )]
@@ -88,8 +88,8 @@ public function testDivide(int $scale, mixed $value, mixed $other, array $expect
88
88
89
89
/** @Then the result should have the correct scale and values */
90
90
self ::assertSame ($ scale , $ actual ->getScale ());
91
+ self ::assertSame ($ expected ['float ' ], $ actual ->toFloat ());
91
92
self ::assertSame ($ expected ['string ' ], $ actual ->toString ());
92
- self ::assertSame (floatval ($ expected ['float ' ]), $ actual ->toFloat ());
93
93
}
94
94
95
95
#[DataProvider('providerForTestDivisionByZero ' )]
@@ -120,24 +120,23 @@ public function testWithRounding(RoundingMode $mode, int $scale, mixed $value, a
120
120
121
121
/** @Then the result should match the expected values */
122
122
self ::assertSame ($ scale , $ actual ->getScale ());
123
+ self ::assertSame ($ expected ['float ' ], $ actual ->toFloat ());
123
124
self ::assertSame ($ expected ['string ' ], $ actual ->toString ());
124
- self ::assertSame (floatval ($ expected ['float ' ]), $ actual ->toFloat ());
125
125
}
126
126
127
127
#[DataProvider('providerForTestWithScale ' )]
128
- public function testWithScale (mixed $ value , int $ scale , int $ withScale , array $ expected ): void
128
+ public function testWithScale (mixed $ value , int $ scale , array $ expected ): void
129
129
{
130
- /** @Given a BigNumber instance to be scaled */
131
- $ number = LargeNumber::fromFloat (value: $ value, scale: $ scale );
130
+ /** @Given a BigNumber instance */
131
+ $ number = LargeNumber::fromFloat (value: $ value );
132
132
133
133
/** @When applying a new scale to the BigNumber */
134
- $ actual = $ number ->withScale (scale: $ withScale );
134
+ $ actual = $ number ->withScale (scale: $ scale );
135
135
136
136
/** @Then the result should have the correct adjusted scale and values */
137
- self ::assertSame ($ scale , $ number ->getScale ());
138
- self ::assertSame ($ withScale , $ actual ->getScale ());
137
+ self ::assertSame ($ scale , $ actual ->getScale ());
138
+ self ::assertSame ($ expected [ ' float ' ] , $ actual ->toFloat ());
139
139
self ::assertSame ($ expected ['string ' ], $ actual ->toString ());
140
- self ::assertSame (floatval ($ expected ['float ' ]), $ actual ->toFloat ());
141
140
}
142
141
143
142
#[DataProvider('providerForTestIsZero ' )]
@@ -256,7 +255,7 @@ public static function providerForTestAdd(): array
256
255
'scale ' => 0 ,
257
256
'value ' => '1 ' ,
258
257
'other ' => '1 ' ,
259
- 'expected ' => ['float ' => 2 , 'string ' => '2 ' ]
258
+ 'expected ' => ['float ' => 2.0 , 'string ' => '2 ' ]
260
259
],
261
260
'Adding with scale ' => [
262
261
'scale ' => 3 ,
@@ -268,7 +267,7 @@ public static function providerForTestAdd(): array
268
267
'scale ' => 0 ,
269
268
'value ' => '123 ' ,
270
269
'other ' => '-999 ' ,
271
- 'expected ' => ['float ' => -876 , 'string ' => '-876 ' ]
270
+ 'expected ' => ['float ' => -876.0 , 'string ' => '-876 ' ]
272
271
],
273
272
'Adding large numbers with decimal ' => [
274
273
'scale ' => 4 ,
@@ -298,7 +297,7 @@ public static function providerForTestSubtract(): array
298
297
'scale ' => 0 ,
299
298
'value ' => '11 ' ,
300
299
'other ' => '12 ' ,
301
- 'expected ' => ['float ' => -1 , 'string ' => '-1 ' ]
300
+ 'expected ' => ['float ' => -1.0 , 'string ' => '-1 ' ]
302
301
],
303
302
'Subtraction with scale ' => [
304
303
'scale ' => 4 ,
@@ -316,7 +315,7 @@ public static function providerForTestMultiply(): array
316
315
'scale ' => 0 ,
317
316
'value ' => '2 ' ,
318
317
'other ' => '2 ' ,
319
- 'expected ' => ['float ' => 4 , 'string ' => '4 ' ]
318
+ 'expected ' => ['float ' => 4.0 , 'string ' => '4 ' ]
320
319
],
321
320
'Multiplying negatives ' => [
322
321
'scale ' => 4 ,
@@ -358,13 +357,13 @@ public static function providerForTestDivide(): array
358
357
'scale ' => 0 ,
359
358
'value ' => '0.00 ' ,
360
359
'other ' => '8 ' ,
361
- 'expected ' => ['float ' => 0 , 'string ' => '0 ' ]
360
+ 'expected ' => ['float ' => 0.0 , 'string ' => '0 ' ]
362
361
],
363
362
'Division resulting in negative ' => [
364
363
'scale ' => 0 ,
365
364
'value ' => '-7 ' ,
366
365
'other ' => '0.2 ' ,
367
- 'expected ' => ['float ' => -35 , 'string ' => '-35 ' ]
366
+ 'expected ' => ['float ' => -35.0 , 'string ' => '-35 ' ]
368
367
]
369
368
];
370
369
}
@@ -385,7 +384,7 @@ public static function providerForTestWithRounding(): array
385
384
'mode ' => RoundingMode::HALF_UP ,
386
385
'scale ' => 2 ,
387
386
'value ' => 0.9950 ,
388
- 'expected ' => ['float ' => 1 , 'string ' => '1 ' ]
387
+ 'expected ' => ['float ' => 1.0 , 'string ' => '1 ' ]
389
388
],
390
389
'Half odd rounding ' => [
391
390
'mode ' => RoundingMode::HALF_ODD ,
@@ -403,73 +402,58 @@ public static function providerForTestWithRounding(): array
403
402
'mode ' => RoundingMode::HALF_EVEN ,
404
403
'scale ' => 2 ,
405
404
'value ' => 0.9950 ,
406
- 'expected ' => ['float ' => 1 , 'string ' => '1 ' ]
405
+ 'expected ' => ['float ' => 1.0 , 'string ' => '1 ' ]
407
406
]
408
407
];
409
408
}
410
409
411
410
public static function providerForTestWithScale (): array
412
411
{
413
412
return [
414
- 'Scaling zero ' => [
415
- 'value ' => 0 ,
416
- 'scale ' => 2 ,
417
- 'withScale ' => 2 ,
418
- 'expected ' => ['float ' => 0.00 , 'string ' => '0.00 ' ]
419
- ],
420
- 'Scaling zero with one decimal ' => [
421
- 'value ' => 0.0 ,
422
- 'scale ' => 2 ,
423
- 'withScale ' => 2 ,
424
- 'expected ' => ['float ' => 0.00 , 'string ' => '0.00 ' ]
413
+ 'Zero scale with no decimals ' => [
414
+ 'value ' => 0 ,
415
+ 'scale ' => 0 ,
416
+ 'expected ' => ['float ' => 0.0 , 'string ' => '0 ' ]
425
417
],
426
- 'Scaling zero with two decimals ' => [
427
- 'value ' => 0.00 ,
428
- 'scale ' => 3 ,
429
- 'withScale ' => 3 ,
430
- 'expected ' => ['float ' => 0.000 , 'string ' => '0.000 ' ]
418
+ 'Zero scale with one decimal place ' => [
419
+ 'value ' => 0 ,
420
+ 'scale ' => 1 ,
421
+ 'expected ' => ['float ' => 0.0 , 'string ' => '0.0 ' ]
431
422
],
432
- 'Scaling zero with three decimals ' => [
433
- 'value ' => 0.000 ,
434
- 'scale ' => 1 ,
435
- 'withScale ' => 1 ,
436
- 'expected ' => ['float ' => 0.0 , 'string ' => '0.0 ' ]
423
+ 'Zero scale with two decimal places ' => [
424
+ 'value ' => 0 ,
425
+ 'scale ' => 2 ,
426
+ 'expected ' => ['float ' => 0.00 , 'string ' => '0.00 ' ]
437
427
],
438
- 'Scaling with integer ' => [
439
- 'value ' => 5 ,
440
- 'scale ' => 2 ,
441
- 'withScale ' => 2 ,
442
- 'expected ' => ['float ' => 5.00 , 'string ' => '5.00 ' ]
428
+ 'Zero scale with three decimal places ' => [
429
+ 'value ' => 0 ,
430
+ 'scale ' => 3 ,
431
+ 'expected ' => ['float ' => 0.000 , 'string ' => '0.000 ' ]
443
432
],
444
- 'Scaling with decimal and reducing precision ' => [
445
- 'value ' => 123.4567 ,
446
- 'scale ' => 2 ,
447
- 'withScale ' => 2 ,
448
- 'expected ' => ['float ' => 123.45 , 'string ' => '123.45 ' ]
433
+ 'Negative large value rounded to one decimal ' => [
434
+ 'value ' => -553.99999 ,
435
+ 'scale ' => 1 ,
436
+ 'expected ' => ['float ' => -553.9 , 'string ' => '-553.9 ' ]
449
437
],
450
- 'Scaling large negative number ' => [
451
- 'value ' => -553.99999 ,
452
- 'scale ' => 5 ,
453
- 'withScale ' => 1 ,
454
- 'expected ' => ['float ' => -553.9 , 'string ' => '-553.9 ' ]
438
+ 'Large positive number rounded to two decimals ' => [
439
+ 'value ' => 999999.999 ,
440
+ 'scale ' => 2 ,
441
+ 'expected ' => ['float ' => 999999.99 , 'string ' => '999999.99 ' ]
455
442
],
456
- 'Scaling with precision reduction ' => [
457
- 'value ' => 10.5555 ,
458
- 'scale ' => 4 ,
459
- 'withScale ' => 3 ,
460
- 'expected ' => ['float ' => 10.555 , 'string ' => '10.555 ' ]
443
+ 'Small negative value rounded to four decimals ' => [
444
+ 'value ' => -0.12345 ,
445
+ 'scale ' => 4 ,
446
+ 'expected ' => ['float ' => -0.1234 , 'string ' => '-0.1234 ' ]
461
447
],
462
- 'Scaling large positive number ' => [
463
- 'value ' => 999999.999 ,
464
- 'scale ' => 2 ,
465
- 'withScale ' => 2 ,
466
- 'expected ' => ['float ' => 999999.99 , 'string ' => '999999.99 ' ]
448
+ 'Decimal value with precision reduction to two ' => [
449
+ 'value ' => 123.4567 ,
450
+ 'scale ' => 2 ,
451
+ 'expected ' => ['float ' => 123.45 , 'string ' => '123.45 ' ]
467
452
],
468
- 'Scaling with small negative number ' => [
469
- 'value ' => -0.12345 ,
470
- 'scale ' => 4 ,
471
- 'withScale ' => 4 ,
472
- 'expected ' => ['float ' => -0.1234 , 'string ' => '-0.1234 ' ]
453
+ 'Positive value with precision reduction to three ' => [
454
+ 'value ' => 10.5555 ,
455
+ 'scale ' => 3 ,
456
+ 'expected ' => ['float ' => 10.555 , 'string ' => '10.555 ' ]
473
457
]
474
458
];
475
459
}
0 commit comments