Skip to content

Commit

Permalink
added inHg and hPa units
Browse files Browse the repository at this point in the history
  • Loading branch information
cezam committed Dec 31, 2020
1 parent be778e1 commit eaaf3a8
Show file tree
Hide file tree
Showing 5 changed files with 218 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Measure.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -221,6 +223,8 @@ class Measure
self::PRESSURE => [
Atmosphere::class,
Bar::class,
Hectopascal::class,
InchesOfMercury::class,
Kilopascal::class,
Megapascal::class,
Millibar::class,
Expand Down
37 changes: 37 additions & 0 deletions src/Unit/Pressure/Hectopascal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types = 1);

/**
* This file is part of the jordanbrauer/unit-converter PHP package.
*
* @copyright 2018 Jordan Brauer <[email protected]>
* @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);
}
}
37 changes: 37 additions & 0 deletions src/Unit/Pressure/InchesOfMercury.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

declare(strict_types = 1);

/**
* This file is part of the jordanbrauer/unit-converter PHP package.
*
* @copyright 2018 Jordan Brauer <[email protected]>
* @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);
}
}
70 changes: 70 additions & 0 deletions tests/integration/Unit/Pressure/Hectopascal.spec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

declare(strict_types = 1);

/**
* This file is part of the jordanbrauer/unit-converter PHP package.
*
* @copyright 2018 Jordan Brauer <[email protected]>
* @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);
}
}
70 changes: 70 additions & 0 deletions tests/integration/Unit/Pressure/InchesOfMercury.spec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?php

declare(strict_types = 1);

/**
* This file is part of the jordanbrauer/unit-converter PHP package.
*
* @copyright 2018 Jordan Brauer <[email protected]>
* @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);
}
}

0 comments on commit eaaf3a8

Please sign in to comment.