Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve assertion approaches #24

Merged
merged 2 commits into from
Sep 25, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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));
thomasrockhu-codecov marked this conversation as resolved.
Show resolved Hide resolved
}
}