-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: test for different calculator value equivalencies
- Loading branch information
1 parent
930c9f6
commit 39ffd1b
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
tests/integration/UnitConverter/CalculatorResults.spec.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |