Skip to content

Commit

Permalink
[TASK] Cover Calculator class with unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NamelessCoder committed Aug 28, 2015
1 parent 5217688 commit 60a9717
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Calculator.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function statistics(array $values) {
'max' => 0
);
foreach ($values as $set) {
$value = $set['value'];
$value = (float) $set['value'];
$data['sum'] += $value;
if ($data['min'] === NULL || $value < $data['min']) {
$data['min'] = $value;
Expand Down
83 changes: 80 additions & 3 deletions tests/Unit/CalculatorTest.php
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)
),

);
}

}

0 comments on commit 60a9717

Please sign in to comment.