From 39ffd1b70f696b56bd276b8350d9c8adba90df5f Mon Sep 17 00:00:00 2001 From: Jordan Brauer <18744334+jordanbrauer@users.noreply.github.com> Date: Sat, 3 Feb 2018 19:17:23 -0600 Subject: [PATCH] Add: test for different calculator value equivalencies --- .../UnitConverter/CalculatorResults.spec.php | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 tests/integration/UnitConverter/CalculatorResults.spec.php diff --git a/tests/integration/UnitConverter/CalculatorResults.spec.php b/tests/integration/UnitConverter/CalculatorResults.spec.php new file mode 100644 index 00000000..30fccf4c --- /dev/null +++ b/tests/integration/UnitConverter/CalculatorResults.spec.php @@ -0,0 +1,68 @@ + + * @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); + } +}