2022-07-05 15:55:47 +02:00
|
|
|
<?php
|
|
|
|
|
2024-02-02 14:53:38 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2022-07-05 15:55:47 +02:00
|
|
|
namespace DNW\Skills\Tests\Numerics;
|
2010-08-28 22:05:41 -04:00
|
|
|
|
2022-07-05 15:33:34 +02:00
|
|
|
use DNW\Skills\Numerics\BasicMath;
|
2024-02-01 10:50:18 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2024-05-14 08:46:43 +00:00
|
|
|
use PHPUnit\Framework\Attributes\CoversClass;
|
2016-05-24 14:06:43 +02:00
|
|
|
|
2024-05-14 08:46:43 +00:00
|
|
|
#[CoversClass(BasicMath::class)]
|
2016-05-24 14:06:43 +02:00
|
|
|
class BasicMathTest extends TestCase
|
2016-05-24 13:59:35 +02:00
|
|
|
{
|
2023-08-01 11:26:38 +00:00
|
|
|
public function testSquare(): void
|
2016-05-24 13:59:35 +02:00
|
|
|
{
|
2016-05-24 15:12:29 +02:00
|
|
|
$this->assertEquals(1, BasicMath::square(1));
|
|
|
|
$this->assertEquals(1.44, BasicMath::square(1.2));
|
|
|
|
$this->assertEquals(4, BasicMath::square(2));
|
2010-08-28 22:05:41 -04:00
|
|
|
}
|
2024-02-06 13:45:40 +00:00
|
|
|
|
|
|
|
public function testSum(): void
|
|
|
|
{
|
|
|
|
$arr = [1, 1, 1, 1];
|
|
|
|
|
2024-02-21 13:48:37 +00:00
|
|
|
$func_return = static fn(float $f): float => $f;
|
|
|
|
$func_double = static fn(float $f): float => $f * 2;
|
2024-02-06 13:45:40 +00:00
|
|
|
$this->assertEquals(4, BasicMath::sum($arr, $func_return));
|
|
|
|
$this->assertEquals(8, BasicMath::sum($arr, $func_double));
|
|
|
|
}
|
2022-07-05 15:55:47 +02:00
|
|
|
}
|