Skip to content

Commit

Permalink
Merge pull request #24 from peter279k/improve_tests
Browse files Browse the repository at this point in the history
Improve assertion approaches
  • Loading branch information
thomasrockhu-codecov authored Sep 25, 2023
2 parents b5ef7c3 + 68e94c1 commit f3a2ef0
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions tests/calculatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,47 @@ class calculatorTest extends PHPUnit\Framework\TestCase
*/
public function testAdd()
{
$this->assertEquals(BasicCalculator::add(1, 2), 3.0);
$this->assertEquals(BasicCalculator::add(1.0, 2.0), 3.0);
$this->assertEquals(BasicCalculator::add(0, 2.0), 2.0);
$this->assertEquals(BasicCalculator::add(2.0, 0), 2.0);
$this->assertEquals(BasicCalculator::add(-4, 2.0), -2.0);
$this->assertEquals(3.0, BasicCalculator::add(1, 2));
$this->assertEquals(3.0, BasicCalculator::add(1.0, 2.0));
$this->assertEquals(2.0, BasicCalculator::add(0, 2.0));
$this->assertEquals(2.0, BasicCalculator::add(2.0, 0));
$this->assertEquals(-2.0, BasicCalculator::add(-4, 2.0));
}

/**
* @covers Calculator\BasicCalculator
*/
public function testSubtract()
{
$this->assertEquals(BasicCalculator::subtract(1, 2), -1.0);
$this->assertEquals(BasicCalculator::subtract(2, 1), 1.0);
$this->assertEquals(BasicCalculator::subtract(1.0, 2.0), -1.0);
$this->assertEquals(BasicCalculator::subtract(0, 2.0), -2.0);
$this->assertEquals(BasicCalculator::subtract(2.0, 0), 2.0);
$this->assertEquals(BasicCalculator::subtract(-4, 2.0), -6.0);
$this->assertEquals(-1.0, BasicCalculator::subtract(1, 2));
$this->assertEquals(1.0, BasicCalculator::subtract(2, 1));
$this->assertEquals(-1.0, BasicCalculator::subtract(1.0, 2.0));
$this->assertEquals(-2.0, BasicCalculator::subtract(0, 2.0));
$this->assertEquals(2.0, BasicCalculator::subtract(2.0, 0));
$this->assertEquals(-6.0, BasicCalculator::subtract(-4, 2.0));
}

/**
* @covers Calculator\BasicCalculator
*/
public function testMultiply()
{
$this->assertEquals(BasicCalculator::multiply(1, 2), 2.0);
$this->assertEquals(BasicCalculator::multiply(1.0, 2.0), 2.0);
$this->assertEquals(BasicCalculator::multiply(0, 2.0), 0.0);
$this->assertEquals(BasicCalculator::multiply(2.0, 0), 0.0);
$this->assertEquals(BasicCalculator::multiply(-4, 2.0), -8.0);
$this->assertEquals(2.0, BasicCalculator::multiply(1, 2));
$this->assertEquals(2.0, BasicCalculator::multiply(1.0, 2.0));
$this->assertEquals(0.0, BasicCalculator::multiply(0, 2.0));
$this->assertEquals(0.0, BasicCalculator::multiply(2.0, 0));
$this->assertEquals(-8.0, BasicCalculator::multiply(-4, 2.0));
}

/**
* @covers Calculator\BasicCalculator
*/
public function testDivide()
{
$this->assertEquals(BasicCalculator::divide(1, 2), 0.5);
$this->assertEquals(BasicCalculator::divide(1.0, 2.0), 0.5);
$this->assertEquals(BasicCalculator::divide(0, 2.0), 0.0);
$this->assertEquals(BasicCalculator::divide(-4, 2.0), -2.0);
// $this->assertEquals(BasicCalculator::divide(2.0, 0), 'Cannot divide by 0');
$this->assertEquals(0.5, BasicCalculator::divide(1, 2));
$this->assertEquals(0.5, BasicCalculator::divide(1.0, 2.0));
$this->assertEquals(0.0, BasicCalculator::divide(0, 2.0));
$this->assertEquals(-2.0, BasicCalculator::divide(-4, 2.0));
// $this->assertEquals('Cannot divide by 0', BasicCalculator::divide(2.0, 0));
}
}

0 comments on commit f3a2ef0

Please sign in to comment.