-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Cover Calculator class with unit tests
- Loading branch information
1 parent
5217688
commit 60a9717
Showing
2 changed files
with
81 additions
and
4 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
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 |
---|---|---|
@@ -1,16 +1,93 @@ | ||
<?php | ||
namespace NamelessCoder\Numerolog\Tests\Unit; | ||
use NamelessCoder\Numerolog\Calculator; | ||
|
||
/** | ||
* Class CalculatorTest | ||
*/ | ||
class CalculatorTest extends \PHPUnit_Framework_TestCase { | ||
|
||
/** | ||
* @test | ||
* @param float $value | ||
* @param boolean $expected | ||
* @dataProvider getIsSignedTestValues | ||
*/ | ||
public function testMarkIncomplete() { | ||
$this->markTestIncomplete('Not yet implemented'); | ||
public function testIsSigned($value, $expected) { | ||
$calculator = new Calculator(); | ||
$this->assertEquals($expected, $calculator->isSigned($value)); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getIsSignedTestValues() { | ||
return array( | ||
array(1, FALSE), | ||
array(-1, TRUE), | ||
array(0.514, FALSE), | ||
array(-0.132, TRUE) | ||
); | ||
} | ||
|
||
/** | ||
* @param float $value | ||
* @param mixed $modification | ||
* @param float $expected | ||
* @dataProvider getModifyTestValues | ||
*/ | ||
public function testModify($value, $modification, $expected) { | ||
$calculator = new Calculator(); | ||
$this->assertEquals($expected, $calculator->modify($value, $modification)); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getModifyTestValues() { | ||
return array( | ||
array(1, 2, 2), | ||
array(1, '+1', 2), | ||
array(2, -1, 1) | ||
); | ||
} | ||
|
||
/** | ||
* @param array $values | ||
* @param array $expected | ||
* @dataProvider getStatisticsTestValues | ||
*/ | ||
public function testStatistics(array $values, array $expected) { | ||
$calculator = new Calculator(); | ||
$this->assertEquals($expected, $calculator->statistics($values)); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getStatisticsTestValues() { | ||
return array( | ||
array( | ||
array( | ||
array('value' => 1), | ||
array('value' => 2), | ||
array('value' => 3), | ||
array('value' => 4), | ||
array('value' => 5) | ||
), | ||
array('min' => 1, 'max' => 5, 'sum' => 15, 'average' => 3, 'count' => 5) | ||
), | ||
array( | ||
array( | ||
array('value' => 0.4), | ||
array('value' => 1.2), | ||
array('value' => 2.4), | ||
array('value' => 3.8), | ||
array('value' => 0.5) | ||
), | ||
array('min' => 0.4, 'max' => 3.8, 'sum' => 8.3, 'average' => 1.66, 'count' => 5) | ||
), | ||
|
||
); | ||
} | ||
|
||
} |