Skip to content

Commit

Permalink
Issue 67: Implementation of Power
Browse files Browse the repository at this point in the history
  • Loading branch information
pierpaolocira committed May 12, 2017
1 parent 96d3695 commit 8dc6141
Show file tree
Hide file tree
Showing 2 changed files with 85 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',
]
);
}
}
53 changes: 53 additions & 0 deletions tests/PhysicalQuantity/PowerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?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 Energy(1000, 'W');
$this->assertEquals(1, $quantity->toUnit('kW'));
}

public function testToWatt()
{
$quantity = new Energy(1, 'kW');
$this->assertEquals(1000, $quantity->toUnit('W'));
}

}

0 comments on commit 8dc6141

Please sign in to comment.