@@ -40,8 +40,8 @@ public function testAdd(int $scale, mixed $value, mixed $other, array $expected)
4040
4141 /** @Then the result should have the correct scale and values */
4242 self ::assertSame ($ scale , $ actual ->getScale ());
43+ self ::assertSame ($ expected ['float ' ], $ actual ->toFloat ());
4344 self ::assertSame ($ expected ['string ' ], $ actual ->toString ());
44- self ::assertSame (floatval ($ expected ['float ' ]), $ actual ->toFloat ());
4545 }
4646
4747 #[DataProvider('providerForTestSubtract ' )]
@@ -56,8 +56,8 @@ public function testSubtract(int $scale, mixed $value, mixed $other, array $expe
5656
5757 /** @Then the result should have the correct scale and values */
5858 self ::assertSame ($ scale , $ actual ->getScale ());
59+ self ::assertSame ($ expected ['float ' ], $ actual ->toFloat ());
5960 self ::assertSame ($ expected ['string ' ], $ actual ->toString ());
60- self ::assertSame (floatval ($ expected ['float ' ]), $ actual ->toFloat ());
6161 }
6262
6363 #[DataProvider('providerForTestMultiply ' )]
@@ -72,8 +72,8 @@ public function testMultiply(int $scale, mixed $value, mixed $other, array $expe
7272
7373 /** @Then the result should have the correct scale and values */
7474 self ::assertSame ($ scale , $ actual ->getScale ());
75+ self ::assertSame ($ expected ['float ' ], $ actual ->toFloat ());
7576 self ::assertSame ($ expected ['string ' ], $ actual ->toString ());
76- self ::assertSame (floatval ($ expected ['float ' ]), $ actual ->toFloat ());
7777 }
7878
7979 #[DataProvider('providerForTestDivide ' )]
@@ -88,8 +88,8 @@ public function testDivide(int $scale, mixed $value, mixed $other, array $expect
8888
8989 /** @Then the result should have the correct scale and values */
9090 self ::assertSame ($ scale , $ actual ->getScale ());
91+ self ::assertSame ($ expected ['float ' ], $ actual ->toFloat ());
9192 self ::assertSame ($ expected ['string ' ], $ actual ->toString ());
92- self ::assertSame (floatval ($ expected ['float ' ]), $ actual ->toFloat ());
9393 }
9494
9595 #[DataProvider('providerForTestDivisionByZero ' )]
@@ -120,24 +120,23 @@ public function testWithRounding(RoundingMode $mode, int $scale, mixed $value, a
120120
121121 /** @Then the result should match the expected values */
122122 self ::assertSame ($ scale , $ actual ->getScale ());
123+ self ::assertSame ($ expected ['float ' ], $ actual ->toFloat ());
123124 self ::assertSame ($ expected ['string ' ], $ actual ->toString ());
124- self ::assertSame (floatval ($ expected ['float ' ]), $ actual ->toFloat ());
125125 }
126126
127127 #[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
129129 {
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 );
132132
133133 /** @When applying a new scale to the BigNumber */
134- $ actual = $ number ->withScale (scale: $ withScale );
134+ $ actual = $ number ->withScale (scale: $ scale );
135135
136136 /** @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 ());
139139 self ::assertSame ($ expected ['string ' ], $ actual ->toString ());
140- self ::assertSame (floatval ($ expected ['float ' ]), $ actual ->toFloat ());
141140 }
142141
143142 #[DataProvider('providerForTestIsZero ' )]
@@ -256,7 +255,7 @@ public static function providerForTestAdd(): array
256255 'scale ' => 0 ,
257256 'value ' => '1 ' ,
258257 'other ' => '1 ' ,
259- 'expected ' => ['float ' => 2 , 'string ' => '2 ' ]
258+ 'expected ' => ['float ' => 2.0 , 'string ' => '2 ' ]
260259 ],
261260 'Adding with scale ' => [
262261 'scale ' => 3 ,
@@ -268,7 +267,7 @@ public static function providerForTestAdd(): array
268267 'scale ' => 0 ,
269268 'value ' => '123 ' ,
270269 'other ' => '-999 ' ,
271- 'expected ' => ['float ' => -876 , 'string ' => '-876 ' ]
270+ 'expected ' => ['float ' => -876.0 , 'string ' => '-876 ' ]
272271 ],
273272 'Adding large numbers with decimal ' => [
274273 'scale ' => 4 ,
@@ -298,7 +297,7 @@ public static function providerForTestSubtract(): array
298297 'scale ' => 0 ,
299298 'value ' => '11 ' ,
300299 'other ' => '12 ' ,
301- 'expected ' => ['float ' => -1 , 'string ' => '-1 ' ]
300+ 'expected ' => ['float ' => -1.0 , 'string ' => '-1 ' ]
302301 ],
303302 'Subtraction with scale ' => [
304303 'scale ' => 4 ,
@@ -316,7 +315,7 @@ public static function providerForTestMultiply(): array
316315 'scale ' => 0 ,
317316 'value ' => '2 ' ,
318317 'other ' => '2 ' ,
319- 'expected ' => ['float ' => 4 , 'string ' => '4 ' ]
318+ 'expected ' => ['float ' => 4.0 , 'string ' => '4 ' ]
320319 ],
321320 'Multiplying negatives ' => [
322321 'scale ' => 4 ,
@@ -358,13 +357,13 @@ public static function providerForTestDivide(): array
358357 'scale ' => 0 ,
359358 'value ' => '0.00 ' ,
360359 'other ' => '8 ' ,
361- 'expected ' => ['float ' => 0 , 'string ' => '0 ' ]
360+ 'expected ' => ['float ' => 0.0 , 'string ' => '0 ' ]
362361 ],
363362 'Division resulting in negative ' => [
364363 'scale ' => 0 ,
365364 'value ' => '-7 ' ,
366365 'other ' => '0.2 ' ,
367- 'expected ' => ['float ' => -35 , 'string ' => '-35 ' ]
366+ 'expected ' => ['float ' => -35.0 , 'string ' => '-35 ' ]
368367 ]
369368 ];
370369 }
@@ -385,7 +384,7 @@ public static function providerForTestWithRounding(): array
385384 'mode ' => RoundingMode::HALF_UP ,
386385 'scale ' => 2 ,
387386 'value ' => 0.9950 ,
388- 'expected ' => ['float ' => 1 , 'string ' => '1 ' ]
387+ 'expected ' => ['float ' => 1.0 , 'string ' => '1 ' ]
389388 ],
390389 'Half odd rounding ' => [
391390 'mode ' => RoundingMode::HALF_ODD ,
@@ -403,73 +402,58 @@ public static function providerForTestWithRounding(): array
403402 'mode ' => RoundingMode::HALF_EVEN ,
404403 'scale ' => 2 ,
405404 'value ' => 0.9950 ,
406- 'expected ' => ['float ' => 1 , 'string ' => '1 ' ]
405+ 'expected ' => ['float ' => 1.0 , 'string ' => '1 ' ]
407406 ]
408407 ];
409408 }
410409
411410 public static function providerForTestWithScale (): array
412411 {
413412 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 ' ]
425417 ],
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 ' ]
431422 ],
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 ' ]
437427 ],
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 ' ]
443432 ],
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 ' ]
449437 ],
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 ' ]
455442 ],
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 ' ]
461447 ],
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 ' ]
467452 ],
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 ' ]
473457 ]
474458 ];
475459 }
0 commit comments