Skip to content

Commit

Permalink
Update: add missing integration tests for units of volume
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbrauer committed Nov 14, 2017
1 parent 541f1d1 commit 8651ae6
Show file tree
Hide file tree
Showing 5 changed files with 279 additions and 11 deletions.
67 changes: 67 additions & 0 deletions tests/integration/UnitConverter/Unit/Volume/CubicMetre.spec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?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\Tests\Integration\Unit\Volume;

use PHPUnit\Framework\TestCase;
use UnitConverter\UnitConverter;
use UnitConverter\Calculator\SimpleCalculator;
use UnitConverter\Registry\UnitRegistry;
use UnitConverter\Unit\Volume\Litre;
use UnitConverter\Unit\Volume\CubicMetre;

/**
* Ensure that a cubic metre is a metre that has been cubed.
*
* @covers UnitConverter\Unit\Volume\CubicMetre
* @uses UnitConverter\Unit\Volume\Litre
* @uses UnitConverter\Unit\AbstractUnit
* @uses UnitConverter\UnitConverter
* @uses UnitConverter\Calculator\SimpleCalculator
* @uses UnitConverter\Calculator\AbstractCalculator
* @uses UnitConverter\Registry\UnitRegistry
*/
class CubicMetreSpec extends TestCase
{
protected function setUp ()
{
$this->converter = new UnitConverter(
new UnitRegistry(array(
new Litre,
new CubicMetre,
)),
new SimpleCalculator
);
}

protected function tearDown ()
{
unset($this->converter);
}

/**
* @test
*/
public function assert1CubicMetreIs1000Litres ()
{
$expected = 1000;
$actual = $this->converter
->convert(1)
->from("m3")
->to("L")
;

$this->assertEquals($expected, $actual);
}
}
67 changes: 67 additions & 0 deletions tests/integration/UnitConverter/Unit/Volume/Gallon.spec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?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\Tests\Integration\Unit\Volume;

use PHPUnit\Framework\TestCase;
use UnitConverter\UnitConverter;
use UnitConverter\Calculator\SimpleCalculator;
use UnitConverter\Registry\UnitRegistry;
use UnitConverter\Unit\Volume\Litre;
use UnitConverter\Unit\Volume\Gallon;

/**
* Ensure that a U.S. gallon is a U.S. gallon.
*
* @covers UnitConverter\Unit\Volume\Gallon
* @uses UnitConverter\Unit\Volume\Litre
* @uses UnitConverter\Unit\AbstractUnit
* @uses UnitConverter\UnitConverter
* @uses UnitConverter\Calculator\SimpleCalculator
* @uses UnitConverter\Calculator\AbstractCalculator
* @uses UnitConverter\Registry\UnitRegistry
*/
class GallonSpec extends TestCase
{
protected function setUp ()
{
$this->converter = new UnitConverter(
new UnitRegistry(array(
new Litre,
new Gallon,
)),
new SimpleCalculator
);
}

protected function tearDown ()
{
unset($this->converter);
}

/**
* @test
*/
public function assert1GallonIs3decimal78541Litres ()
{
$expected = 3.78541;
$actual = $this->converter
->convert(1, 5)
->from("gal")
->to("L")
;

$this->assertEquals($expected, $actual);
}
}
64 changes: 64 additions & 0 deletions tests/integration/UnitConverter/Unit/Volume/Litre.spec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?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\Tests\Integration\Unit\Volume;

use PHPUnit\Framework\TestCase;
use UnitConverter\UnitConverter;
use UnitConverter\Calculator\SimpleCalculator;
use UnitConverter\Registry\UnitRegistry;
use UnitConverter\Unit\Volume\Litre;

/**
* Ensure that a litre is litre.
*
* @covers UnitConverter\Unit\Volume\Litre
* @uses UnitConverter\Unit\AbstractUnit
* @uses UnitConverter\UnitConverter
* @uses UnitConverter\Calculator\SimpleCalculator
* @uses UnitConverter\Calculator\AbstractCalculator
* @uses UnitConverter\Registry\UnitRegistry
*/
class LitreSpec extends TestCase
{
protected function setUp ()
{
$this->converter = new UnitConverter(
new UnitRegistry(array(
new Litre,
)),
new SimpleCalculator
);
}

protected function tearDown ()
{
unset($this->converter);
}

/**
* @test
*/
public function assert1LitreIs1Litre ()
{
$expected = 1;
$actual = $this->converter
->convert(1)
->from("L")
->to("L")
;

$this->assertEquals($expected, $actual);
}
}
67 changes: 67 additions & 0 deletions tests/integration/UnitConverter/Unit/Volume/Millilitre.spec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?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\Tests\Integration\Unit\Volume;

use PHPUnit\Framework\TestCase;
use UnitConverter\UnitConverter;
use UnitConverter\Calculator\SimpleCalculator;
use UnitConverter\Registry\UnitRegistry;
use UnitConverter\Unit\Volume\Litre;
use UnitConverter\Unit\Volume\Millilitre;

/**
* Ensure that a millilitre is a millilitre.
*
* @covers UnitConverter\Unit\Volume\Millilitre
* @uses UnitConverter\Unit\Volume\Litre
* @uses UnitConverter\Unit\AbstractUnit
* @uses UnitConverter\UnitConverter
* @uses UnitConverter\Calculator\SimpleCalculator
* @uses UnitConverter\Calculator\AbstractCalculator
* @uses UnitConverter\Registry\UnitRegistry
*/
class MillilitreSpec extends TestCase
{
protected function setUp ()
{
$this->converter = new UnitConverter(
new UnitRegistry(array(
new Litre,
new Millilitre,
)),
new SimpleCalculator
);
}

protected function tearDown ()
{
unset($this->converter);
}

/**
* @test
*/
public function assert1MillilitreIs0decimal001Litres ()
{
$expected = 0.001;
$actual = $this->converter
->convert(1, 3)
->from("mL")
->to("L")
;

$this->assertEquals($expected, $actual);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,26 @@
use UnitConverter\Calculator\SimpleCalculator;
use UnitConverter\Registry\UnitRegistry;
use UnitConverter\Unit\Volume\Litre;
use UnitConverter\Unit\Volume\Mililitre;
use UnitConverter\Unit\Volume\Gallon;
use UnitConverter\Unit\Volume\Pint;

/**
* Test the default volume units for conversion accuracy.
* Ensure that a pint is a pint.
*
* @covers UnitConverter\Unit\Volume\Pint
* @uses UnitConverter\Unit\Volume\Litre
* @uses UnitConverter\Unit\AbstractUnit
* @uses UnitConverter\UnitConverter
* @uses UnitConverter\Calculator\SimpleCalculator
* @uses UnitConverter\Calculator\AbstractCalculator
* @uses UnitConverter\Registry\UnitRegistry
*/
class VolumeUnitsSpec extends TestCase
class PintSpec extends TestCase
{
protected function setUp ()
{
$this->converter = new UnitConverter(
new UnitRegistry(array(
new Litre,
new Mililitre,
new Gallon,
new Pint,
)),
new SimpleCalculator
Expand All @@ -48,15 +52,14 @@ protected function tearDown ()

/**
* @test
* @coversNothing
*/
public function assert ()
public function assert1PintIs0decimal473176Litres ()
{
$expected = 4.73176;
$expected = 0.473176;
$actual = $this->converter
->convert(10, 5)
->convert(1, 6)
->from("pt")
->to("l")
->to("L")
;

$this->assertEquals($expected, $actual);
Expand Down

0 comments on commit 8651ae6

Please sign in to comment.