From 6b175c4a424c092d7cbc00a2da438220cfc22873 Mon Sep 17 00:00:00 2001 From: Mike Stupalov Date: Thu, 2 Nov 2023 12:14:11 +0300 Subject: [PATCH] Fixed UnitTests. --- CHANGELOG.md | 4 +-- tests/PhysicalQuantity/AccelerationTest.php | 4 +-- tests/PhysicalQuantity/AreaTest.php | 4 +-- tests/PhysicalQuantity/EnergyTest.php | 4 +-- tests/PhysicalQuantity/LengthTest.php | 6 ++--- tests/PhysicalQuantity/MassTest.php | 16 ++++++------ tests/PhysicalQuantity/PowerTest.php | 4 +-- tests/PhysicalQuantity/StorageTest.php | 17 +++++++------ tests/PhysicalQuantity/TemperatureTest.php | 28 ++++++++++----------- tests/PhysicalQuantity/VelocityTest.php | 8 +++--- tests/PhysicalQuantity/VolumeFlowTest.php | 23 +++++++++-------- tests/PhysicalQuantity/VolumeTest.php | 20 +++++++-------- 12 files changed, 70 insertions(+), 68 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 540e019..9ea690e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,7 @@ -## v2.2.1 (xxx) +## v2.2.1 (November 2nd, 2023) - Drop support of php < 7.4 -## v2.2.0 (Feb 17th, 2021) +## v2.2.0 (February 17th, 2021) - Added support for php 8.0 - Added option power factor for Si factor, ie for square (2) and cubic (3) - Added new Physical Quantity volume flow with commonly used units diff --git a/tests/PhysicalQuantity/AccelerationTest.php b/tests/PhysicalQuantity/AccelerationTest.php index 5732ef2..76bf800 100644 --- a/tests/PhysicalQuantity/AccelerationTest.php +++ b/tests/PhysicalQuantity/AccelerationTest.php @@ -21,13 +21,13 @@ protected function instantiateTestQuantity(): PhysicalQuantityInterface return new Acceleration(1, 'm/s^2'); } - public function testToKiloMeterPerSecond() + public function testToKiloMeterPerSecond(): void { $value = new Acceleration(1000, 'm/s^2'); $this->assertEquals(1, $value->toUnit('km/s^2')); } - public function testToMilliMeterPerSecond() + public function testToMilliMeterPerSecond(): void { $value = new Acceleration(1, 'm/s^2'); $this->assertEquals(1000, $value->toUnit('mm/s^2')); diff --git a/tests/PhysicalQuantity/AreaTest.php b/tests/PhysicalQuantity/AreaTest.php index 260245b..9d8f3dc 100644 --- a/tests/PhysicalQuantity/AreaTest.php +++ b/tests/PhysicalQuantity/AreaTest.php @@ -199,7 +199,7 @@ public function testToDecare(): void $this->assertEquals(1, $area->toUnit('decare')); } - public function testToDecimeterSquare() + public function testToDecimeterSquare(): void { $area = new Area(1, 'm^2'); $this->assertEquals(100, $area->toUnit('dm^2')); @@ -207,7 +207,7 @@ public function testToDecimeterSquare() $this->assertEquals(10000, $area->toUnit('dm^2')); } - public function testToMillimeterSquare() + public function testToMillimeterSquare(): void { $area = new Area(1, 'm^2'); $this->assertEquals(1e6, $area->toUnit('mm^2')); diff --git a/tests/PhysicalQuantity/EnergyTest.php b/tests/PhysicalQuantity/EnergyTest.php index 1a46534..bbbba7f 100644 --- a/tests/PhysicalQuantity/EnergyTest.php +++ b/tests/PhysicalQuantity/EnergyTest.php @@ -102,13 +102,13 @@ public function testToJoule(): void $this->assertEquals(3600, $quantity->toUnit('joule')); } - public function testToMegaCal() + public function testToMegaCal(): void { $quantity = new Energy(1, 'kWh'); $this->assertEquals(0.8604206500956023, $quantity->toUnit('Mcal')); } - public function testToMegaElectronvolt() + public function testToMegaElectronvolt(): void { $quantity = new Energy(1, 'kWh'); $this->assertEquals(2.2469432853179728e19, $quantity->toUnit('MeV')); diff --git a/tests/PhysicalQuantity/LengthTest.php b/tests/PhysicalQuantity/LengthTest.php index db4dd61..5901248 100644 --- a/tests/PhysicalQuantity/LengthTest.php +++ b/tests/PhysicalQuantity/LengthTest.php @@ -245,19 +245,19 @@ public function testToAstronomicalUnit(): void $this->assertEquals(1.0026880683402668, $quantity->toUnit('AU')); } - public function testToLightYear() + public function testToLightYear(): void { $quantity = new Length(150000000000000, 'km'); $this->assertEquals(15.855012510369232, $quantity->toUnit('ly')); } - public function testToParSec() + public function testToParSec(): void { $quantity = new Length(150000000000000, 'km'); $this->assertEquals(4.861168934166548, $quantity->toUnit('pc')); } - public function testToMilliParSec() + public function testToMilliParSec(): void { $quantity = new Length(150000000000000, 'km'); $this->assertEquals(4861.168934166548, $quantity->toUnit('mpc')); diff --git a/tests/PhysicalQuantity/MassTest.php b/tests/PhysicalQuantity/MassTest.php index 8126f41..9387ecf 100644 --- a/tests/PhysicalQuantity/MassTest.php +++ b/tests/PhysicalQuantity/MassTest.php @@ -131,27 +131,27 @@ public function testToStones(): void $this->assertEquals(1, $quantity->toUnit('st')); } - public function testToHundredweight() + public function testToHundredweight(): void { $quantity = new Mass(5, 'kg'); - $this->assertEquals(0.098420653, $quantity->toUnit('cwt'), '', 0.00000001); + $this->assertEqualsWithDelta(0.098420653, $quantity->toUnit('cwt'), '', 0.00000001); } - public function testToUSshortTon() + public function testToUSshortTon(): void { $quantity = new Mass(5, 'kg'); - $this->assertEquals(0.0055115566, $quantity->toUnit('ust'), '', 0.000000001); + $this->assertEqualsWithDelta(0.0055115566, $quantity->toUnit('ust'), '', 0.000000001); } - public function testToUSlongTon() + public function testToUSlongTon(): void { $quantity = new Mass(5, 'kg'); - $this->assertEquals(0.0049210326, $quantity->toUnit('ukt'), '', 0.000000001); + $this->assertEqualsWithDelta(0.0049210326, $quantity->toUnit('ukt'), '', 0.000000001); } - public function testToPicul() + public function testToPicul(): void { $quantity = new Mass(5, 'kg'); - $this->assertEquals(0.08267335, $quantity->toUnit('picul'), '', 0.00000001); + $this->assertEqualsWithDelta(0.08267335, $quantity->toUnit('picul'), '', 0.00000001); } } diff --git a/tests/PhysicalQuantity/PowerTest.php b/tests/PhysicalQuantity/PowerTest.php index 3a52a1a..455fd5d 100644 --- a/tests/PhysicalQuantity/PowerTest.php +++ b/tests/PhysicalQuantity/PowerTest.php @@ -51,7 +51,7 @@ public function testToWatt(): void $this->assertEquals(1000, $quantity->toUnit('W')); } - public function testToDecibelsMilliWatt() + public function testToDecibelsMilliWatt(): void { $quantity = new Power(0.01, 'mW'); $this->assertEquals(-20, $quantity->toUnit('dBm')); @@ -61,7 +61,7 @@ public function testToDecibelsMilliWatt() $this->assertEquals(70, $quantity->toUnit('dBm')); } - public function testFromDecibelsMilliWatt() + public function testFromDecibelsMilliWatt(): void { $quantity = new Power(-20, 'dBm'); $this->assertEquals(0.00001, $quantity->toUnit('W')); diff --git a/tests/PhysicalQuantity/StorageTest.php b/tests/PhysicalQuantity/StorageTest.php index da1c574..9c55558 100644 --- a/tests/PhysicalQuantity/StorageTest.php +++ b/tests/PhysicalQuantity/StorageTest.php @@ -3,46 +3,47 @@ namespace PhpUnitsOfMeasureTest\PhysicalQuantity; use PhpUnitsOfMeasure\PhysicalQuantity\Storage; +use PhpUnitsOfMeasure\PhysicalQuantityInterface; class StorageTest extends AbstractPhysicalQuantityTestCase { - protected function instantiateTestQuantity() + protected function instantiateTestQuantity(): PhysicalQuantityInterface { return new Storage(1, 'byte'); } - public function testByteToByte() + public function testByteToByte(): void { $this->assertEquals(1, (new Storage(1, 'byte'))->toUnit('B')); } - public function testByteToBit() + public function testByteToBit(): void { $this->assertEquals(40, (new Storage(5, 'byte'))->toUnit('bit')); } - public function testBitToByte() + public function testBitToByte(): void { $this->assertEquals(1.25, (new Storage(10, 'b'))->toUnit('B')); } - public function testMegabyteToByte() + public function testMegabyteToByte(): void { $this->assertEquals(1048576, (new Storage(1, 'MB'))->toUnit('B')); } - public function testGigabyteToByte() + public function testGigabyteToByte(): void { $this->assertEquals(1073741824, (new Storage(1, 'gigabyte'))->toUnit('byte')); } - public function testTerabyteToByte() + public function testTerabyteToByte(): void { $this->assertEquals(1099511627776, (new Storage(1, 'TB'))->toUnit('byte')); } - public function testPetabyteToByte() + public function testPetabyteToByte(): void { $this->assertEquals(3377699720527872, (new Storage(3, 'PB'))->toUnit('byte')); } diff --git a/tests/PhysicalQuantity/TemperatureTest.php b/tests/PhysicalQuantity/TemperatureTest.php index f8a65cf..7d9c49a 100644 --- a/tests/PhysicalQuantity/TemperatureTest.php +++ b/tests/PhysicalQuantity/TemperatureTest.php @@ -85,44 +85,44 @@ protected function instantiateTestQuantity(): PhysicalQuantityInterface return new Temperature(1, 'K'); } - public function testToCelsius() + public function testToCelsius(): void { $value = new Temperature(313.15, 'K'); - $this->assertEquals(40, $value->toUnit('C'), '', 0.000001); + $this->assertEqualsWithDelta(40, $value->toUnit('C'), '', 0.000001); } - public function testToFahrenheit() + public function testToFahrenheit(): void { $value = new Temperature(313.15, 'K'); - $this->assertEquals(104, $value->toUnit('F'), '', 0.000001); + $this->assertEqualsWithDelta(104, $value->toUnit('F'), '', 0.000001); } - public function testToRankine() + public function testToRankine(): void { $value = new Temperature(313.15, 'K'); - $this->assertEquals(563.67, $value->toUnit('Ra'), '', 0.000001); + $this->assertEqualsWithDelta(563.67, $value->toUnit('Ra'), '', 0.000001); } - public function testToDelisle() + public function testToDelisle(): void { $value = new Temperature(313.15, 'K'); - $this->assertEquals(90, $value->toUnit('D'), '', 0.000001); + $this->assertEqualsWithDelta(90, $value->toUnit('D'), '', 0.000001); } - public function testToNewton() + public function testToNewton(): void { $value = new Temperature(313.15, 'K'); - $this->assertEquals(13.2, $value->toUnit('N'), '', 0.000001); + $this->assertEqualsWithDelta(13.2, $value->toUnit('N'), '', 0.000001); } - public function testToReaumur() + public function testToReaumur(): void { $value = new Temperature(313.15, 'K'); - $this->assertEquals(32, $value->toUnit('Re'), '', 0.000001); + $this->assertEqualsWithDelta(32, $value->toUnit('Re'), '', 0.000001); } - public function testToRomer() + public function testToRomer(): void { $value = new Temperature(313.15, 'K'); - $this->assertEquals(28.5, $value->toUnit('Ro'), '', 0.000001); + $this->assertEqualsWithDelta(28.5, $value->toUnit('Ro'), '', 0.000001); } } diff --git a/tests/PhysicalQuantity/VelocityTest.php b/tests/PhysicalQuantity/VelocityTest.php index ffaa9bc..30df26b 100644 --- a/tests/PhysicalQuantity/VelocityTest.php +++ b/tests/PhysicalQuantity/VelocityTest.php @@ -38,7 +38,7 @@ protected function instantiateTestQuantity(): PhysicalQuantityInterface public function testToKilometersPerHour(): void { $speed = new Velocity(1, 'km/h'); - $this->assertEquals(0.277778, $speed->toUnit('m/s'), '', 0.000001); + $this->assertEqualsWithDelta(0.277778, $speed->toUnit('m/s'), '', 0.000001); } public function testToFeetPerSecond(): void @@ -50,7 +50,7 @@ public function testToFeetPerSecond(): void public function testToKmPerHour(): void { $speed = new Velocity(2, 'mph'); - $this->assertEquals(3.218688, $speed->toUnit('km/h'), '', 0.000001); + $this->assertEqualsWithDelta(3.218688, $speed->toUnit('km/h'), '', 0.000001); } public function testToKnot(): void @@ -59,9 +59,9 @@ public function testToKnot(): void $this->assertEquals(3.8876923435786983, $speed->toUnit('knot')); } - public function testToMach() + public function testToMach(): void { $speed = new Velocity(1000, 'm/s'); - $this->assertEquals(2.906977, $speed->toUnit('mach'), '', 0.000001); + $this->assertEqualsWithDelta(2.906977, $speed->toUnit('mach'), '', 0.000001); } } diff --git a/tests/PhysicalQuantity/VolumeFlowTest.php b/tests/PhysicalQuantity/VolumeFlowTest.php index 1f02ba9..34f28f0 100644 --- a/tests/PhysicalQuantity/VolumeFlowTest.php +++ b/tests/PhysicalQuantity/VolumeFlowTest.php @@ -3,10 +3,11 @@ namespace PhpUnitsOfMeasureTest\PhysicalQuantity; use PhpUnitsOfMeasure\PhysicalQuantity\VolumeFlow; +use PhpUnitsOfMeasure\PhysicalQuantityInterface; class VolumeFlowTest extends AbstractPhysicalQuantityTestCase { - protected $supportedUnitsWithAliases = [ + protected array $supportedUnitsWithAliases = [ 'm^3/s', 'm³/s', 'cubic meter per second', @@ -331,12 +332,12 @@ class VolumeFlowTest extends AbstractPhysicalQuantityTestCase 'us gal/d' ]; - protected function instantiateTestQuantity() + protected function instantiateTestQuantity(): PhysicalQuantityInterface { return new VolumeFlow(1, 'm^3/s'); } - public function testToCubicDecimeterSecond() + public function testToCubicDecimeterSecond(): void { $area = new VolumeFlow(1, 'm^3/s'); /* @@ -353,15 +354,15 @@ public function testToCubicDecimeterSecond() } - public function testToCubicMillimeterSecond() + public function testToCubicMillimeterSecond(): void { $area = new VolumeFlow(1, 'm^3/s'); - $this->assertEquals(1e9, $area->toUnit('mm^3/s'), '', 0.000001); + $this->assertEqualsWithDelta(1e9, $area->toUnit('mm^3/s'), '', 0.000001); $area = new VolumeFlow(100, 'm^3/s'); $this->assertEquals(1e11, $area->toUnit('mm^3/s')); } - public function testToLitresSecond() + public function testToLitresSecond(): void { $area = new VolumeFlow(1, 'm^3/s'); $this->assertEquals(1000, $area->toUnit('l/s')); @@ -369,7 +370,7 @@ public function testToLitresSecond() $this->assertEquals(100000, $area->toUnit('l/s')); } - public function testToMilliLitresSecond() + public function testToMilliLitresSecond(): void { $area = new VolumeFlow(1, 'l/s'); $this->assertEquals(1000, $area->toUnit('ml/s')); @@ -377,7 +378,7 @@ public function testToMilliLitresSecond() $this->assertEquals(100000, $area->toUnit('ml/s')); } - public function testToHectoLitresSecond() + public function testToHectoLitresSecond(): void { $area = new VolumeFlow(1, 'l/s'); $this->assertEquals(0.01, $area->toUnit('hl/s')); @@ -385,7 +386,7 @@ public function testToHectoLitresSecond() $this->assertEquals(1, $area->toUnit('hl/s')); } - public function testToKiloLitresSecond() + public function testToKiloLitresSecond(): void { $area = new VolumeFlow(1, 'l/s'); $this->assertEquals(0.001, $area->toUnit('kl/s')); @@ -396,8 +397,8 @@ public function testToKiloLitresSecond() public function testToCFM() { $area = new VolumeFlow(1, 'CMM'); - $this->assertEquals(35.314667, $area->toUnit('CFM'), '', 0.000001); + $this->assertEqualsWithDelta(35.314667, $area->toUnit('CFM'), '', 0.000001); $area = new VolumeFlow(100, 'm^3/s'); - $this->assertEquals(211888.000328, $area->toUnit('CFM'), '', 0.000001); + $this->assertEqualsWithDelta(211888.000328, $area->toUnit('CFM'), '', 0.000001); } } diff --git a/tests/PhysicalQuantity/VolumeTest.php b/tests/PhysicalQuantity/VolumeTest.php index 4be4708..c247a8c 100644 --- a/tests/PhysicalQuantity/VolumeTest.php +++ b/tests/PhysicalQuantity/VolumeTest.php @@ -90,7 +90,7 @@ protected function instantiateTestQuantity(): PhysicalQuantityInterface return new Volume(1, 'm^3'); } - public function testToCubicDecimeter() + public function testToCubicDecimeter(): void { $area = new Volume(1, 'm^3'); $this->assertEquals(1000, $area->toUnit('dm^3')); @@ -98,15 +98,15 @@ public function testToCubicDecimeter() $this->assertEquals(100000, $area->toUnit('dm^3')); } - public function testToCubicMillimeter() + public function testToCubicMillimeter(): void { $area = new Volume(1, 'm^3'); - $this->assertEquals(1e9, $area->toUnit('mm^3'), '', 0.000001); + $this->assertEqualsWithDelta(1e9, $area->toUnit('mm^3'), '', 0.000001); $area = new Volume(100, 'm^3'); $this->assertEquals(1e11, $area->toUnit('mm^3')); } - public function testToLitres() + public function testToLitres(): void { $area = new Volume(1, 'm^3'); $this->assertEquals(1000, $area->toUnit('l')); @@ -114,7 +114,7 @@ public function testToLitres() $this->assertEquals(100000, $area->toUnit('l')); } - public function testToMilliLitres() + public function testToMilliLitres(): void { $area = new Volume(1, 'l'); $this->assertEquals(1000, $area->toUnit('ml')); @@ -122,7 +122,7 @@ public function testToMilliLitres() $this->assertEquals(100000, $area->toUnit('ml')); } - public function testToHectoLitres() + public function testToHectoLitres(): void { $area = new Volume(1, 'l'); $this->assertEquals(0.01, $area->toUnit('hl')); @@ -130,7 +130,7 @@ public function testToHectoLitres() $this->assertEquals(1, $area->toUnit('hl')); } - public function testToKiloLitres() + public function testToKiloLitres(): void { $area = new Volume(1, 'l'); $this->assertEquals(0.001, $area->toUnit('kl')); @@ -138,11 +138,11 @@ public function testToKiloLitres() $this->assertEquals(0.1, $area->toUnit('kl')); } - public function testToGallon() + public function testToGallon(): void { $area = new Volume(1, 'm^3'); - $this->assertEquals(264.172051, $area->toUnit('gal'), '', 0.000001); + $this->assertEqualsWithDelta(264.172051, $area->toUnit('gal'), '', 0.000001); $area = new Volume(100, 'm^3'); - $this->assertEquals(26417.205124, $area->toUnit('gal'), '', 0.000001); + $this->assertEqualsWithDelta(26417.205124, $area->toUnit('gal'), '', 0.000001); } }