From eaaf3a8c0a053f0f06862f7c441b4f09b7838a8c Mon Sep 17 00:00:00 2001 From: Michal Podsednik Date: Thu, 31 Dec 2020 17:39:11 +0100 Subject: [PATCH] added inHg and hPa units --- src/Measure.php | 4 ++ src/Unit/Pressure/Hectopascal.php | 37 ++++++++++ src/Unit/Pressure/InchesOfMercury.php | 37 ++++++++++ .../Unit/Pressure/Hectopascal.spec.php | 70 +++++++++++++++++++ .../Unit/Pressure/InchesOfMercury.spec.php | 70 +++++++++++++++++++ 5 files changed, 218 insertions(+) create mode 100644 src/Unit/Pressure/Hectopascal.php create mode 100644 src/Unit/Pressure/InchesOfMercury.php create mode 100644 tests/integration/Unit/Pressure/Hectopascal.spec.php create mode 100644 tests/integration/Unit/Pressure/InchesOfMercury.spec.php diff --git a/src/Measure.php b/src/Measure.php index d6763bb1..18c5cc26 100644 --- a/src/Measure.php +++ b/src/Measure.php @@ -84,6 +84,8 @@ use UnitConverter\Unit\PlaneAngle\Radian; use UnitConverter\Unit\Pressure\Atmosphere; use UnitConverter\Unit\Pressure\Bar; +use UnitConverter\Unit\Pressure\Hectopascal; +use UnitConverter\Unit\Pressure\InchesOfMercury; use UnitConverter\Unit\Pressure\Kilopascal; use UnitConverter\Unit\Pressure\Megapascal; use UnitConverter\Unit\Pressure\Millibar; @@ -221,6 +223,8 @@ class Measure self::PRESSURE => [ Atmosphere::class, Bar::class, + Hectopascal::class, + InchesOfMercury::class, Kilopascal::class, Megapascal::class, Millibar::class, diff --git a/src/Unit/Pressure/Hectopascal.php b/src/Unit/Pressure/Hectopascal.php new file mode 100644 index 00000000..317e3622 --- /dev/null +++ b/src/Unit/Pressure/Hectopascal.php @@ -0,0 +1,37 @@ + + * @license MIT + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace UnitConverter\Unit\Pressure; + +/** + * Kilopascal unit data class. + * + * @version 1.0.0 + * @since 0.8.5 + * @author Michal Podsednik + */ +class Hectopascal extends PressureUnit +{ + protected function configure(): void + { + $this + ->setName("hectopascal") + + ->setSymbol("hPa") + + ->setScientificSymbol("hPa") + + ->setUnits(100); + } +} diff --git a/src/Unit/Pressure/InchesOfMercury.php b/src/Unit/Pressure/InchesOfMercury.php new file mode 100644 index 00000000..b94114e7 --- /dev/null +++ b/src/Unit/Pressure/InchesOfMercury.php @@ -0,0 +1,37 @@ + + * @license MIT + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace UnitConverter\Unit\Pressure; + +/** + * Inches of mercury unit data class. + * + * @version 1.0.0 + * @since 0.8.5 + * @author Michal Podsednik + */ +class InchesOfMercury extends PressureUnit +{ + protected function configure(): void + { + $this + ->setName("inches of mercury") + + ->setSymbol("inHg") + + ->setScientificSymbol("inHg") + + ->setUnits(3386.38867); + } +} diff --git a/tests/integration/Unit/Pressure/Hectopascal.spec.php b/tests/integration/Unit/Pressure/Hectopascal.spec.php new file mode 100644 index 00000000..09ce5d3c --- /dev/null +++ b/tests/integration/Unit/Pressure/Hectopascal.spec.php @@ -0,0 +1,70 @@ + + * @license MIT + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace UnitConverter\Tests\Integration\Unit\Pressure; + +use PHPUnit\Framework\TestCase; +use UnitConverter\Calculator\SimpleCalculator; +use UnitConverter\Registry\UnitRegistry; +use UnitConverter\Unit\Pressure\Hectopascal; +use UnitConverter\Unit\Pressure\Pascal; +use UnitConverter\UnitConverter; + +/** + * Test that a hectopascal is indeed a hectoascal. + * + * @covers UnitConverter\Unit\Pressure\Hectopascal + * @uses UnitConverter\Unit\Pressure\Pascal + * @uses UnitConverter\Unit\AbstractUnit + * @uses UnitConverter\UnitConverter + * @uses UnitConverter\Calculator\SimpleCalculator + * @uses UnitConverter\Calculator\AbstractCalculator + * @uses UnitConverter\Calculator\Formula\AbstractFormula + * @uses UnitConverter\Calculator\Formula\UnitConversionFormula + * @uses UnitConverter\Registry\UnitRegistry + * @uses UnitConverter\Support\ArrayDotNotation + * @uses UnitConverter\Support\Collection + */ +class HectopascalSpec extends TestCase +{ + protected function setUp() + { + $this->converter = new UnitConverter( + new UnitRegistry([ + new Pascal(), + new Hectopascal(), + ]), + new SimpleCalculator() + ); + } + + protected function tearDown() + { + unset($this->converter); + } + + /** + * @test + */ + public function assert1HectopascalIs100Pascal() + { + $expected = 100; + $actual = $this->converter + ->convert(1) + ->from("hPa") + ->to("Pa"); + + $this->assertEquals($expected, $actual); + } +} diff --git a/tests/integration/Unit/Pressure/InchesOfMercury.spec.php b/tests/integration/Unit/Pressure/InchesOfMercury.spec.php new file mode 100644 index 00000000..830e91e3 --- /dev/null +++ b/tests/integration/Unit/Pressure/InchesOfMercury.spec.php @@ -0,0 +1,70 @@ + + * @license MIT + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace UnitConverter\Tests\Integration\Unit\Pressure; + +use PHPUnit\Framework\TestCase; +use UnitConverter\Calculator\SimpleCalculator; +use UnitConverter\Registry\UnitRegistry; +use UnitConverter\Unit\Pressure\InchesOfMercury; +use UnitConverter\Unit\Pressure\Pascal; +use UnitConverter\UnitConverter; + +/** + * Test that an one inch of mercury is indeed a pound-force per sq in. + * + * @covers UnitConverter\Unit\Pressure\PoundForcePerSquareInch + * @uses UnitConverter\Unit\Pressure\Pascal + * @uses UnitConverter\Unit\AbstractUnit + * @uses UnitConverter\UnitConverter + * @uses UnitConverter\Calculator\SimpleCalculator + * @uses UnitConverter\Calculator\AbstractCalculator + * @uses UnitConverter\Calculator\Formula\AbstractFormula + * @uses UnitConverter\Calculator\Formula\UnitConversionFormula + * @uses UnitConverter\Registry\UnitRegistry + * @uses UnitConverter\Support\ArrayDotNotation + * @uses UnitConverter\Support\Collection + */ +class InchesOfMercurySpec extends TestCase +{ + protected function setUp() + { + $this->converter = new UnitConverter( + new UnitRegistry([ + new Pascal(), + new InchesOfMercury(), + ]), + new SimpleCalculator() + ); + } + + protected function tearDown() + { + unset($this->converter); + } + + /** + * @test + */ + public function assert1InchOfMercuryIs338638867Pascals() + { + $expected = 3386.38867; + $actual = $this->converter + ->convert(1) + ->from("inHg") + ->to("Pa"); + + $this->assertEquals($expected, $actual); + } +}