phpOMS/tests/Math/Optimization/SimplexTest.php
Dennis Eichhorn f435905146 test fixes
2023-10-22 18:06:50 +00:00

109 lines
2.3 KiB
PHP

<?php
/**
* Jingga
*
* PHP Version 8.1
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 2.0
* @version 1.0.0
* @link https://jingga.app
*/
declare(strict_types=1);
namespace phpOMS\tests\Math\Optimization;
use phpOMS\Math\Optimization\Simplex;
/**
* @testdox phpOMS\tests\Math\Optimization\SimplexTest: Numeric integration
*
* @internal
*
* Commented out assertions which take a long time with xdebug. without xdebug these are fine!
*/
final class SimplexTest extends \PHPUnit\Framework\TestCase
{
public function testSimplexBasicInfeasible() : void
{
$simplex = new Simplex();
self::assertEqualsWithDelta(
[
[11.333333, 3.333333, 0.0, 11.666667, 0.0],
21.333333
],
$simplex->solve(
[
[-1, 1],
[1, 1],
[1, -4],
],
[8, -3, 2],
[1, 3]
),
0.01
);
}
public function testSimplexBasicFeasible() : void
{
$simplex = new Simplex();
self::assertEqualsWithDelta(
[
[1.0, 0.0, 0.0, 0.0],
5.0
],
$simplex->solve(
[
[-1, 1],
[-2, -1],
],
[1, 2],
[5, -3]
),
0.0
);
}
public function testSimplexLPInfeasible() : void
{
$simplex = new Simplex();
self::assertEquals(
[
[-2, -2, -2, -2, -2],
\INF
],
$simplex->solve(
[
[-1, -1],
[2, 2],
],
[2, -10],
[3, -2]
)
);
}
public function testSimplexLPUnbound() : void
{
$simplex = new Simplex();
self::assertEqualsWithDelta(
[
[-1, -1, -1, -1],
\INF
],
$simplex->solve(
[
[2, -1],
[1, 2],
],
[-1, -2],
[1, -1]
),
0.01
);
}
}