@@ -13,7 +13,7 @@ public function testInterface(): void
1313 {
1414 $ price = new Price (1234.56 , Currency::EUR , 'kg ' );
1515
16- $ this ->assertEquals ('1 234,56 €/kg ' , (string )$ price );
16+ $ this ->assertEquals ('1 234,56 €/kg ' , (string ) $ price );
1717
1818 $ this ->assertIsFloat ($ price ->amount );
1919 $ this ->assertEquals (1234.56 , $ price ->amount );
@@ -22,6 +22,56 @@ public function testInterface(): void
2222 $ this ->assertEquals (Currency::EUR , $ price ->currency );
2323
2424 $ this ->assertIsString ($ price ->unit );
25- $ this ->assertEquals ('kg ' , (string )$ price ->unit );
25+ $ this ->assertEquals ('kg ' , (string ) $ price ->unit );
26+ }
27+
28+ public function testAdd (): void
29+ {
30+ $ price1 = new Price (100 , Currency::EUR , 'Mwh ' );
31+ $ price2 = new Price (50 , Currency::EUR , 'Mwh ' );
32+
33+ $ result = $ price1 ->add ($ price2 );
34+
35+ $ this ->assertEquals (150 , $ result ->amount );
36+ $ this ->assertEquals (Currency::EUR , $ result ->currency );
37+ $ this ->assertEquals ('Mwh ' , $ result ->unit );
38+ }
39+
40+ public function testsubtract (): void
41+ {
42+ $ price1 = new Price (100 , Currency::EUR , 'Mwh ' );
43+ $ price2 = new Price (50 , Currency::EUR , 'Mwh ' );
44+
45+ $ result = $ price1 ->subtract ($ price2 );
46+
47+ $ this ->assertEquals (50 , $ result ->amount );
48+ $ this ->assertEquals (Currency::EUR , $ result ->currency );
49+ $ this ->assertEquals ('Mwh ' , $ result ->unit );
50+ }
51+
52+ public function testMultiply (): void
53+ {
54+ $ price = new Price (100 , Currency::EUR , 'Mwh ' );
55+
56+ $ result = $ price ->multiply (2 );
57+
58+ $ this ->assertEquals (200 , $ result ->amount );
59+ $ this ->assertEquals (Currency::EUR , $ result ->currency );
60+ $ this ->assertEquals ('Mwh ' , $ result ->unit );
61+ }
62+
63+ public function testApplyPercentage (): void
64+ {
65+ $ price = new Price (100 , Currency::EUR , 'Mwh ' );
66+
67+ $ result = $ price ->applyPercentage (10 );
68+ $ this ->assertEquals (110.00 , $ result ->amount );
69+ $ this ->assertEquals (Currency::EUR , $ result ->currency );
70+ $ this ->assertEquals ('Mwh ' , $ result ->unit );
71+
72+ $ result = $ price ->applyPercentage (-10 );
73+ $ this ->assertEquals (90.00 , $ result ->amount );
74+ $ this ->assertEquals (Currency::EUR , $ result ->currency );
75+ $ this ->assertEquals ('Mwh ' , $ result ->unit );
2676 }
2777}
0 commit comments