Task 1: Calculator init
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use App\Calculator;
|
||||
use App\Operation;
|
||||
use InvalidArgumentException;
|
||||
|
||||
class CalculatorTest extends TestCase
|
||||
{
|
||||
private Calculator $calculator;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->calculator = new Calculator();
|
||||
}
|
||||
|
||||
public function testAdd(): void
|
||||
{
|
||||
$result = $this->calculator->calculate(10, 5, Operation::ADD);
|
||||
$this->assertEquals(15, $result);
|
||||
}
|
||||
|
||||
public function testSubtract(): void
|
||||
{
|
||||
$result = $this->calculator->calculate(10, 5, Operation::SUBTRACT);
|
||||
$this->assertEquals(5, $result);
|
||||
}
|
||||
|
||||
public function testMultiply(): void
|
||||
{
|
||||
$result = $this->calculator->calculate(10, 5, Operation::MULTIPLY);
|
||||
$this->assertEquals(50, $result);
|
||||
}
|
||||
|
||||
public function testDivide(): void
|
||||
{
|
||||
$result = $this->calculator->calculate(10, 5, Operation::DIVIDE);
|
||||
$this->assertEquals(2, $result);
|
||||
}
|
||||
|
||||
public function testDivideByZero(): void
|
||||
{
|
||||
$this->expectException(InvalidArgumentException::class);
|
||||
$this->calculator->calculate(10, 0, Operation::DIVIDE);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user