From e1bc33c8acfe86c8b85d5071f642f0e43f09ec6a Mon Sep 17 00:00:00 2001 From: arubacao Date: Wed, 11 Oct 2017 18:54:30 +0200 Subject: [PATCH] Implement Kilopascal and Megapascal and write tests (#29) * implement Kilopascal * implement Megapascal * fix docblocks --- .../Unit/Pressure/Kilopascal.php | 39 +++++++++++ .../Unit/Pressure/Megapascal.php | 39 +++++++++++ .../Unit/Pressure/PressureUnits.spec.php | 64 +++++++++++++++++++ 3 files changed, 142 insertions(+) create mode 100644 src/UnitConverter/Unit/Pressure/Kilopascal.php create mode 100644 src/UnitConverter/Unit/Pressure/Megapascal.php diff --git a/src/UnitConverter/Unit/Pressure/Kilopascal.php b/src/UnitConverter/Unit/Pressure/Kilopascal.php new file mode 100644 index 00000000..4cd27c44 --- /dev/null +++ b/src/UnitConverter/Unit/Pressure/Kilopascal.php @@ -0,0 +1,39 @@ + + * @license MIT + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types = 1); + +namespace UnitConverter\Unit\Pressure; + +use UnitConverter\Measure; +use UnitConverter\Unit\{ AbstractUnit, UnitInterface }; + +/** + * Kilopascal unit data class. + * + * @version 1.0.0 + * @since 1.0.0 + * @author Jordan Brauer + */ +class Kilopascal extends PressureUnit +{ + protected function configure () : void + { + $this + ->setName("kilopascal") + + ->setSymbol("kpa") + + ->setUnits(1000) + ; + } +} diff --git a/src/UnitConverter/Unit/Pressure/Megapascal.php b/src/UnitConverter/Unit/Pressure/Megapascal.php new file mode 100644 index 00000000..dea16d1c --- /dev/null +++ b/src/UnitConverter/Unit/Pressure/Megapascal.php @@ -0,0 +1,39 @@ + + * @license MIT + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types = 1); + +namespace UnitConverter\Unit\Pressure; + +use UnitConverter\Measure; +use UnitConverter\Unit\{ AbstractUnit, UnitInterface }; + +/** + * Megapascal unit data class. + * + * @version 1.0.0 + * @since 1.0.0 + * @author Jordan Brauer + */ +class Megapascal extends PressureUnit +{ + protected function configure () : void + { + $this + ->setName("megapascal") + + ->setSymbol("mpa") + + ->setUnits(1000000) + ; + } +} diff --git a/tests/integration/UnitConverter/Unit/Pressure/PressureUnits.spec.php b/tests/integration/UnitConverter/Unit/Pressure/PressureUnits.spec.php index 420ddd6c..f377e48f 100644 --- a/tests/integration/UnitConverter/Unit/Pressure/PressureUnits.spec.php +++ b/tests/integration/UnitConverter/Unit/Pressure/PressureUnits.spec.php @@ -19,6 +19,7 @@ use UnitConverter\Registry\UnitRegistry; use UnitConverter\Unit\Pressure\{ Pascal, + Kilopascal, PoundForcePerSquareInch as PSI }; @@ -34,6 +35,7 @@ protected function setUp () $this->converter = new UnitConverter( new UnitRegistry(array( new Pascal, + new Kilopascal, new PSI, )) ); @@ -59,4 +61,66 @@ public function assertZeroCelsiusEqualsTwoHundredSeventyThreeDecimalFifteen () $this->assertEquals(round($expected, 2), round($actual, 2)); } + + /** + * @test + * @coversNothing + */ + public function assert1kpaEquals1000pa() + { + $expected = 1000; + $actual = $this->converter + ->convert(1) + ->from("kpa") + ->to("pa") + ; + + $this->assertEquals(round($expected, 2), round($actual, 2)); + } + + /** + * @test + * @coversNothing + */ + public function assert1000paEquals1kpa() + { + $expected = 1; + $actual = $this->converter + ->convert(1000) + ->from("pa") + ->to("kpa") + ; + + $this->assertEquals(round($expected, 2), round($actual, 2)); + } + + /** + * @coversNothing + */ + public function assert1mpaEquals1000000pa() + { + $expected = 1000000; + $actual = $this->converter + ->convert(1) + ->from("mpa") + ->to("pa") + ; + + $this->assertEquals(round($expected, 2), round($actual, 2)); + } + + /** + * @coversNothing + */ + public function assert1mpaEquals1000kpa() + { + $expected = 1000; + $actual = $this->converter + ->convert(1) + ->from("mpa") + ->to("kpa") + ; + + $this->assertEquals(round($expected, 2), round($actual, 2)); + } }