Skip to content

Commit

Permalink
Merge pull request #69 from pierpaolocira/issue-67-power
Browse files Browse the repository at this point in the history
Issue 67 power
  • Loading branch information
triplepoint authored Jul 26, 2017
2 parents cdbfa00 + df9d11a commit 212a332
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
32 changes: 32 additions & 0 deletions source/PhysicalQuantity/Power.php
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',
]
);
}
}
52 changes: 52 additions & 0 deletions tests/PhysicalQuantity/PowerTest.php
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'));
}
}

0 comments on commit 212a332

Please sign in to comment.