Skip to content

Commit

Permalink
Add: test for different calculator value equivalencies
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbrauer committed Feb 4, 2018
1 parent 930c9f6 commit 39ffd1b
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions tests/integration/UnitConverter/CalculatorResults.spec.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?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;

use PHPUnit\Framework\TestCase;
use UnitConverter\UnitConverter;
use UnitConverter\Calculator\SimpleCalculator;
use UnitConverter\Calculator\BinaryCalculator;
use UnitConverter\Registry\UnitRegistry;
use UnitConverter\Unit\Length\Centimetre;
use UnitConverter\Unit\Length\Inch;

/**
* Tests that both the Simlpe and Binary calculator implementations
* generate the same results, regardless of typing (int/float, or string).
*/
class CalculatorResultsSpec extends TestCase
{
protected function setUp ()
{
$registry = new UnitRegistry([
new Centimetre,
new Inch,
]);

$this->simpleConverter = new UnitConverter(
$registry, new SimpleCalculator
);

$this->binaryConverter = new UnitConverter(
$registry, new BinaryCalculator
);
}

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

/**
* @test
*/
public function assertSimpleAndBinaryCalculatorsProduceSameResult ()
{
$value = 1;
$expectedSimpleResult = 2.54;
$expectedBinaryResult = "2.54";
$simpleResult = $this->simpleConverter->convert($value)->from("in")->to("cm");
$binaryResult = $this->binaryConverter->convert("{$value}")->from("in")->to("cm");

$this->assertEquals($simpleResult, $binaryResult);
$this->assertSame($expectedSimpleResult, $simpleResult);
$this->assertSame($expectedBinaryResult, $binaryResult);
}
}

0 comments on commit 39ffd1b

Please sign in to comment.