Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added inHg and hPa units #158

Merged
merged 1 commit into from
Jan 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}