From 8dc6141126f6a32e5bc7d99f15166c8228f04af7 Mon Sep 17 00:00:00 2001 From: pierpaolocira Date: Fri, 12 May 2017 10:55:23 +0200 Subject: [PATCH 1/2] Issue 67: Implementation of Power --- source/PhysicalQuantity/Power.php | 32 +++++++++++++++++ tests/PhysicalQuantity/PowerTest.php | 53 ++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 source/PhysicalQuantity/Power.php create mode 100644 tests/PhysicalQuantity/PowerTest.php diff --git a/source/PhysicalQuantity/Power.php b/source/PhysicalQuantity/Power.php new file mode 100644 index 0000000..0ec2a70 --- /dev/null +++ b/source/PhysicalQuantity/Power.php @@ -0,0 +1,32 @@ +addAlias('watt'); + $watt->addAlias('watts'); + static::addUnit($watt); + + static::addMissingSIPrefixedUnits( + $watt, + 1, + '%pW', + [ + '%Pwatt', + '%Pwatts', + ] + ); + } +} diff --git a/tests/PhysicalQuantity/PowerTest.php b/tests/PhysicalQuantity/PowerTest.php new file mode 100644 index 0000000..ca21c2b --- /dev/null +++ b/tests/PhysicalQuantity/PowerTest.php @@ -0,0 +1,53 @@ +assertEquals(1, $quantity->toUnit('kW')); + } + + public function testToWatt() + { + $quantity = new Energy(1, 'kW'); + $this->assertEquals(1000, $quantity->toUnit('W')); + } + +} From 19cca508daf72511168c8b185e2bdf1627b5dd75 Mon Sep 17 00:00:00 2001 From: pierpaolocira Date: Fri, 12 May 2017 11:20:02 +0200 Subject: [PATCH 2/2] Fixing test file --- tests/PhysicalQuantity/PowerTest.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tests/PhysicalQuantity/PowerTest.php b/tests/PhysicalQuantity/PowerTest.php index ca21c2b..b66e777 100644 --- a/tests/PhysicalQuantity/PowerTest.php +++ b/tests/PhysicalQuantity/PowerTest.php @@ -40,14 +40,13 @@ protected function instantiateTestQuantity() public function testToKilowatt() { - $quantity = new Energy(1000, 'W'); + $quantity = new Power(1000, 'W'); $this->assertEquals(1, $quantity->toUnit('kW')); } public function testToWatt() { - $quantity = new Energy(1, 'kW'); + $quantity = new Power(1, 'kW'); $this->assertEquals(1000, $quantity->toUnit('W')); } - }