-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #69 from pierpaolocira/issue-67-power
Issue 67 power
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
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,32 @@ | ||
<?php | ||
namespace PhpUnitsOfMeasure\PhysicalQuantity; | ||
|
||
use PhpUnitsOfMeasure\AbstractPhysicalQuantity; | ||
use PhpUnitsOfMeasure\UnitOfMeasure; | ||
use PhpUnitsOfMeasure\HasSIUnitsTrait; | ||
|
||
class Power extends AbstractPhysicalQuantity | ||
{ | ||
use HasSIUnitsTrait; | ||
|
||
protected static $unitDefinitions; | ||
|
||
protected static function initialize() | ||
{ | ||
// Watt | ||
$watt = UnitOfMeasure::nativeUnitFactory('W'); | ||
$watt->addAlias('watt'); | ||
$watt->addAlias('watts'); | ||
static::addUnit($watt); | ||
|
||
static::addMissingSIPrefixedUnits( | ||
$watt, | ||
1, | ||
'%pW', | ||
[ | ||
'%Pwatt', | ||
'%Pwatts', | ||
] | ||
); | ||
} | ||
} |
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,52 @@ | ||
<?php | ||
|
||
namespace PhpUnitsOfMeasureTest\PhysicalQuantity; | ||
|
||
use PhpUnitsOfMeasure\PhysicalQuantity\Power; | ||
|
||
class PowerTest extends AbstractPhysicalQuantityTestCase | ||
{ | ||
protected $supportedUnitsWithAliases = [ | ||
'W', | ||
'watt', | ||
'watts', | ||
'µW', | ||
'microwatt', | ||
'microwatts', | ||
'mW', | ||
'milliwatt', | ||
'milliwatts', | ||
'kW', | ||
'kilowatt', | ||
'kilowatts', | ||
'MW', | ||
'megawatt', | ||
'megawatts', | ||
'GW', | ||
'gigawatt', | ||
'gigawatts', | ||
'TW', | ||
'terawatt', | ||
'terawatts', | ||
'PW', | ||
'petawatt', | ||
'petawatts', | ||
]; | ||
|
||
protected function instantiateTestQuantity() | ||
{ | ||
return new Power(1, 'W'); | ||
} | ||
|
||
public function testToKilowatt() | ||
{ | ||
$quantity = new Power(1000, 'W'); | ||
$this->assertEquals(1, $quantity->toUnit('kW')); | ||
} | ||
|
||
public function testToWatt() | ||
{ | ||
$quantity = new Power(1, 'kW'); | ||
$this->assertEquals(1000, $quantity->toUnit('W')); | ||
} | ||
} |