Skip to content

Commit

Permalink
Fixed UnitTests.
Browse files Browse the repository at this point in the history
  • Loading branch information
landy2005 committed Nov 2, 2023
1 parent 61fcdaa commit 6b175c4
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 68 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions tests/PhysicalQuantity/AccelerationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
4 changes: 2 additions & 2 deletions tests/PhysicalQuantity/AreaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ 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'));
$area = new Area(100, 'm^2');
$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'));
Expand Down
4 changes: 2 additions & 2 deletions tests/PhysicalQuantity/EnergyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
6 changes: 3 additions & 3 deletions tests/PhysicalQuantity/LengthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
16 changes: 8 additions & 8 deletions tests/PhysicalQuantity/MassTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
4 changes: 2 additions & 2 deletions tests/PhysicalQuantity/PowerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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'));
Expand Down
17 changes: 9 additions & 8 deletions tests/PhysicalQuantity/StorageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}
Expand Down
28 changes: 14 additions & 14 deletions tests/PhysicalQuantity/TemperatureTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
8 changes: 4 additions & 4 deletions tests/PhysicalQuantity/VelocityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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);
}
}
23 changes: 12 additions & 11 deletions tests/PhysicalQuantity/VolumeFlowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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');
/*
Expand All @@ -353,39 +354,39 @@ 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'));
$area = new VolumeFlow(100, 'm^3/s');
$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'));
$area = new VolumeFlow(100, 'l/s');
$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'));
$area = new VolumeFlow(100, 'l/s');
$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'));
Expand All @@ -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);
}
}
Loading

0 comments on commit 6b175c4

Please sign in to comment.