Skip to content

Commit

Permalink
Implement Kilopascal and Megapascal and write tests (#29)
Browse files Browse the repository at this point in the history
* implement Kilopascal

* implement Megapascal

* fix docblocks
  • Loading branch information
arubacao authored and jordanbrauer committed Oct 11, 2017
1 parent 37e0f01 commit e1bc33c
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/UnitConverter/Unit/Pressure/Kilopascal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* This file is part of the jordanbrauer/unit-converter PHP package.
*
* @copyright 2017 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.
*/

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 <[email protected]>
*/
class Kilopascal extends PressureUnit
{
protected function configure () : void
{
$this
->setName("kilopascal")

->setSymbol("kpa")

->setUnits(1000)
;
}
}
39 changes: 39 additions & 0 deletions src/UnitConverter/Unit/Pressure/Megapascal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* This file is part of the jordanbrauer/unit-converter PHP package.
*
* @copyright 2017 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.
*/

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 <[email protected]>
*/
class Megapascal extends PressureUnit
{
protected function configure () : void
{
$this
->setName("megapascal")

->setSymbol("mpa")

->setUnits(1000000)
;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use UnitConverter\Registry\UnitRegistry;
use UnitConverter\Unit\Pressure\{
Pascal,
Kilopascal,
PoundForcePerSquareInch as PSI
};

Expand All @@ -34,6 +35,7 @@ protected function setUp ()
$this->converter = new UnitConverter(
new UnitRegistry(array(
new Pascal,
new Kilopascal,
new PSI,
))
);
Expand All @@ -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));
}
}

0 comments on commit e1bc33c

Please sign in to comment.