Skip to content

Commit

Permalink
Updated unit tests for Momentum class and divide by zero exception. [#11
Browse files Browse the repository at this point in the history
][closes #7]
  • Loading branch information
JordanRL committed Aug 26, 2015
1 parent 07e6b3e commit 270e4b8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Samsara/Newton/Core/UnitComposition.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Samsara\Newton\Units\Length;
use Samsara\Newton\Units\Area;
use Samsara\Newton\Units\Mass;
use Samsara\Newton\Units\Momentum;
use Samsara\Newton\Units\Power;
use Samsara\Newton\Units\Pressure;
use Samsara\Newton\Units\Temperature;
Expand Down Expand Up @@ -259,6 +260,9 @@ public function getUnitClass($unit, $value = 0)
case self::MASS:
return new Mass($value, $this);

case self::MOMENTUM:
return new Momentum($value, $this);

case self::POWER:
return new Power($value, $this);

Expand Down
11 changes: 11 additions & 0 deletions tests/Samsara/Newton/Core/UnitCompositionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public function testGetUnitClass()
$unit->getUnitClass('Mass')
);

$this->assertInstanceOf(
'Samsara\\Newton\\Units\\Momentum',
$unit->getUnitClass('Momentum')
);

$this->assertInstanceOf(
'Samsara\\Newton\\Units\\Power',
$unit->getUnitClass('Power')
Expand Down Expand Up @@ -204,6 +209,12 @@ public function testNaiveDivide()
'1',
$acceleration->getValue()
);

$this->setExpectedException('Exception', 'Cannot divide by zero.');

$mass->preConvertedSubtract(1000);

$unit->naiveDivide($thrust, $mass);
}

public function testGetUnitCompNameException()
Expand Down

0 comments on commit 270e4b8

Please sign in to comment.