Add tests and mark incomplete tests

This commit is contained in:
Dennis Eichhorn 2020-07-11 20:26:01 +02:00
parent efd76ef4c2
commit 3e77b4505c
18 changed files with 355 additions and 46 deletions

View File

@ -53,6 +53,10 @@ final class FDistribution
*/ */
public static function getMode(int $d1, int $d2) : float public static function getMode(int $d1, int $d2) : float
{ {
if ($d1 === 0) {
return 0.0;
}
return ($d1 - 2) / $d1 * $d2 / ($d2 + 2); return ($d1 - 2) / $d1 * $d2 / ($d2 + 2);
} }

View File

@ -98,30 +98,30 @@ final class FileUtils
*/ */
public static function absolute(string $origPath) : string public static function absolute(string $origPath) : string
{ {
if (!\file_exists($origPath) || \realpath($origPath) === false) { if (\file_exists($origPath) || \realpath($origPath) !== false) {
$startsWithSlash = \strpos($origPath, '/') === 0 ? '/' : ''; return \realpath($origPath);
$path = [];
$parts = \explode('/', $origPath);
foreach ($parts as $part) {
if (empty($part) || $part === '.') {
continue;
}
if ($part !== '..') {
$path[] = $part;
} elseif (!empty($path)) {
\array_pop($path);
} else {
throw new PathException($origPath);
}
}
return $startsWithSlash . \implode('/', $path);
} }
return \realpath($origPath); $startsWithSlash = \strpos($origPath, '/') === 0 ? '/' : '';
$path = [];
$parts = \explode('/', $origPath);
foreach ($parts as $part) {
if (empty($part) || $part === '.') {
continue;
}
if ($part !== '..') {
$path[] = $part;
} elseif (!empty($path)) {
\array_pop($path);
} else {
throw new PathException($origPath);
}
}
return $startsWithSlash . \implode('/', $path);
} }
/** /**

View File

@ -221,6 +221,12 @@ class AccountTest extends \PHPUnit\Framework\TestCase
new class() extends PermissionAbstract {}, new class() extends PermissionAbstract {},
]); ]);
self::assertCount(4, $account->getPermissions()); self::assertCount(4, $account->getPermissions());
$account->addPermissions([[
new class() extends PermissionAbstract {},
new class() extends PermissionAbstract {},
]]);
self::assertCount(6, $account->getPermissions());
} }
/** /**

View File

@ -100,22 +100,28 @@ class GroupTest extends \PHPUnit\Framework\TestCase
*/ */
public function testPermissionAdd() : void public function testPermissionAdd() : void
{ {
$account = new Group(); $group = new Group();
$account->addPermission(new class() extends PermissionAbstract {}); $group->addPermission(new class() extends PermissionAbstract {});
self::assertCount(1, $account->getPermissions()); self::assertCount(1, $group->getPermissions());
$account->setPermissions([ $group->setPermissions([
new class() extends PermissionAbstract {}, new class() extends PermissionAbstract {},
new class() extends PermissionAbstract {}, new class() extends PermissionAbstract {},
]); ]);
self::assertCount(2, $account->getPermissions()); self::assertCount(2, $group->getPermissions());
$account->addPermissions([ $group->addPermissions([
new class() extends PermissionAbstract {}, new class() extends PermissionAbstract {},
new class() extends PermissionAbstract {}, new class() extends PermissionAbstract {},
]); ]);
self::assertCount(4, $account->getPermissions()); self::assertCount(4, $group->getPermissions());
$group->addPermissions([[
new class() extends PermissionAbstract {},
new class() extends PermissionAbstract {},
]]);
self::assertCount(6, $group->getPermissions());
} }
/** /**
@ -125,13 +131,13 @@ class GroupTest extends \PHPUnit\Framework\TestCase
*/ */
public function testPermissionExists() : void public function testPermissionExists() : void
{ {
$account = new Group(); $group = new Group();
$account->addPermission(new class() extends PermissionAbstract {}); $group->addPermission(new class() extends PermissionAbstract {});
self::assertCount(1, $account->getPermissions()); self::assertCount(1, $group->getPermissions());
self::assertFalse($account->hasPermission(PermissionType::READ, 1, 'a', 'a', 1, 1, 1)); self::assertFalse($group->hasPermission(PermissionType::READ, 1, 'a', 'a', 1, 1, 1));
self::assertTrue($account->hasPermission(PermissionType::NONE)); self::assertTrue($group->hasPermission(PermissionType::NONE));
} }
/** /**
@ -141,16 +147,16 @@ class GroupTest extends \PHPUnit\Framework\TestCase
*/ */
public function testPermissionRemove() : void public function testPermissionRemove() : void
{ {
$account = new Group(); $group = new Group();
$perm = new class() extends PermissionAbstract {}; $perm = new class() extends PermissionAbstract {};
$perm->setPermission(PermissionType::READ); $perm->setPermission(PermissionType::READ);
$account->addPermission($perm); $group->addPermission($perm);
self::assertCount(1, $account->getPermissions()); self::assertCount(1, $group->getPermissions());
$account->removePermission($perm); $group->removePermission($perm);
self::assertCount(0, $account->getPermissions()); self::assertCount(0, $group->getPermissions());
} }
/** /**

View File

@ -0,0 +1,26 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace phpOMS\tests\Ai\Ocr;
/**
* @internal
*/
class BasicOcrTest extends \PHPUnit\Framework\TestCase
{
public function testPlaceholder() : void
{
self::markTestIncomplete();
}
}

View File

@ -0,0 +1,41 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace phpOMS\tests\Business\Marketing;
use phpOMS\Business\Marketing\Metrics;
/**
* @testdox phpOMS\tests\Business\Marketing\CustomerValueTest: Customer value
*
* @internal
*/
class CustomerValueTest extends \PHPUnit\Framework\TestCase
{
/**
* @group framework
*/
public function testSimpleCLV() : void
{
self::markTestIncomplete();
}
/**
* @group framework
*/
public function testMRR() : void
{
self::markTestIncomplete();
}
}

View File

@ -31,4 +31,44 @@ class MetricsTest extends \PHPUnit\Framework\TestCase
{ {
self::assertEqualsWithDelta(0.85, Metrics::getCustomerRetention(105, 20, 100), 0.01); self::assertEqualsWithDelta(0.85, Metrics::getCustomerRetention(105, 20, 100), 0.01);
} }
/**
* @group framework
*/
public function testBerrysCustomerProfits() : void
{
self::markTestIncomplete();
}
/**
* @group framework
*/
public function testLifeTimeValue() : void
{
self::markTestIncomplete();
}
/**
* @group framework
*/
public function testSimpleRetentionLifeTimeValue() : void
{
self::markTestIncomplete();
}
/**
* @group framework
*/
public function testMailingSuccess() : void
{
self::markTestIncomplete();
}
/**
* @group framework
*/
public function testMigrationModel() : void
{
self::markTestIncomplete();
}
} }

View File

@ -0,0 +1,40 @@
<?php
/**
* Orange Management
*
* PHP Version 7.4
*
* @package tests
* @copyright Dennis Eichhorn
* @license OMS License 1.0
* @version 1.0.0
* @link https://orange-management.org
*/
declare(strict_types=1);
namespace phpOMS\tests\Math\Functions;
use phpOMS\Math\Functions\Beta;
/**
* @testdox phpOMS\tests\Math\Functions\BetaTest: Beta function
*
* @internal
*/
class BetaTest extends \PHPUnit\Framework\TestCase
{
public function testIncompleteBeta() : void
{
self::markTestIncomplete();
}
public function testLogBeta() : void
{
self::markTestIncomplete();
}
public function beta() : void
{
self::markTestIncomplete();
}
}

View File

@ -108,4 +108,14 @@ class FunctionsTest extends \PHPUnit\Framework\TestCase
self::assertEquals(5, Functions::getRelativeDegree(12, 12, 7)); self::assertEquals(5, Functions::getRelativeDegree(12, 12, 7));
self::assertEquals(11, Functions::getRelativeDegree(6, 12, 7)); self::assertEquals(11, Functions::getRelativeDegree(6, 12, 7));
} }
public function testErf() : void
{
self::markTestIncomplete();
}
public function testErfc() : void
{
self::markTestIncomplete();
}
} }

View File

@ -93,4 +93,9 @@ class GammaTest extends \PHPUnit\Framework\TestCase
self::assertTrue(true); self::assertTrue(true);
} }
public function testLogGamma() : void
{
self::markTestIncomplete();
}
} }

View File

@ -14,13 +14,43 @@ declare(strict_types=1);
namespace phpOMS\tests\Math\Stochastic\Distribution; namespace phpOMS\tests\Math\Stochastic\Distribution;
use phpOMS\Math\Stochastic\Distribution\FDistribution;
/** /**
* @internal * @internal
*/ */
class FDistributionTest extends \PHPUnit\Framework\TestCase class FDistributionTest extends \PHPUnit\Framework\TestCase
{ {
public function testPlaceholder() : void public function testMean() : void
{ {
self::markTestIncomplete(); self::assertEquals(0.0, FDistribution::getMean(2));
self::assertEquals(2, FDistribution::getMean(4));
}
public function testMode() : void
{
self::assertEquals(0.0, FDistribution::getMode(0, 0));
self::assertEqualsWithDelta(0.0, FDistribution::getMode(2, 3), 0.01);
self::assertEqualsWithDelta(1 / 3 * 2 / 3, FDistribution::getMode(3, 4), 0.01);
}
public function testVariance() : void
{
self::assertEquals(0.0, FDistribution::getVariance(1, 2));
self::assertEquals(0.0, FDistribution::getVariance(1, 4));
self::assertEqualsWithDelta(11.1111, FDistribution::getVariance(3, 5), 0.01);
}
public function testStandardDeviation() : void
{
self::assertEquals(0.0, FDistribution::getStandardDeviation(1, 2));
self::assertEquals(0.0, FDistribution::getStandardDeviation(1, 4));
self::assertEqualsWithDelta(\sqrt(11.1111), FDistribution::getStandardDeviation(3, 5), 0.01);
}
public function testSkewness() : void
{
self::assertEquals(0.0, FDistribution::getSkewness(1, 6));
self::assertEquals(2 * (2 * 4 + 7 - 2) / (7 - 6) * \sqrt(2 * (7 - 4) / (4 * (7 + 4 - 2))), FDistribution::getSkewness(4, 7));
} }
} }

View File

@ -19,7 +19,32 @@ namespace phpOMS\tests\Math\Stochastic\Distribution;
*/ */
class LogDistributionTest extends \PHPUnit\Framework\TestCase class LogDistributionTest extends \PHPUnit\Framework\TestCase
{ {
public function testPlaceholder() : void public function testPmf() : void
{
self::markTestIncomplete();
}
public function testMean() : void
{
self::markTestIncomplete();
}
public function testMode() : void
{
self::markTestIncomplete();
}
public function testVariance() : void
{
self::markTestIncomplete();
}
public function testStandardDeviation() : void
{
self::markTestIncomplete();
}
public function testMgf() : void
{ {
self::markTestIncomplete(); self::markTestIncomplete();
} }

View File

@ -19,7 +19,52 @@ namespace phpOMS\tests\Math\Stochastic\Distribution;
*/ */
class LogisticDistributionTest extends \PHPUnit\Framework\TestCase class LogisticDistributionTest extends \PHPUnit\Framework\TestCase
{ {
public function testPlaceholder() : void public function testPdf() : void
{
self::markTestIncomplete();
}
public function testCdf() : void
{
self::markTestIncomplete();
}
public function testMode() : void
{
self::markTestIncomplete();
}
public function testMean() : void
{
self::markTestIncomplete();
}
public function testMedian() : void
{
self::markTestIncomplete();
}
public function testVariance() : void
{
self::markTestIncomplete();
}
public function testStandardDeviation() : void
{
self::markTestIncomplete();
}
public function testSkewness() : void
{
self::markTestIncomplete();
}
public function testExKurtosis() : void
{
self::markTestIncomplete();
}
public function testEntropy() : void
{ {
self::markTestIncomplete(); self::markTestIncomplete();
} }

View File

@ -36,7 +36,7 @@ class ZTestTest extends \PHPUnit\Framework\TestCase
public function testZTest() : void public function testZTest() : void
{ {
//self::assertEqualsWithDelta(0.090574, ZTest::zTest(4, [3, 6, 7, 8, 6, 5, 4, 2, 1, 9]), 0.001); //self::assertEqualsWithDelta(0.090574, ZTest::zTest(4, [3, 6, 7, 8, 6, 5, 4, 2, 1, 9]), 0.001);
self::markTestIncomplete();
self::assertTrue(true); self::assertTrue(true);
} }
} }

View File

@ -93,4 +93,14 @@ class RestTest extends \PHPUnit\Framework\TestCase
self::assertTrue($request->setData('gdata', 'abc')); self::assertTrue($request->setData('gdata', 'abc'));
self::assertEquals('abc', REST::request($request)->getJsonData()['args']['gdata']); self::assertEquals('abc', REST::request($request)->getJsonData()['args']['gdata']);
} }
public function testJsonRequest() : void
{
self::markTestIncomplete();
}
public function testMultiRequest() : void
{
self::markTestIncomplete();
}
} }

View File

@ -295,4 +295,14 @@ class WebRouterTest extends \PHPUnit\Framework\TestCase
) )
); );
} }
public function testDataValidation() : void
{
self::markTestIncomplete();
}
public function testDataFromPattern() : void
{
self::markTestIncomplete();
}
} }

View File

@ -54,6 +54,7 @@ class FileUtilsTest extends \PHPUnit\Framework\TestCase
*/ */
public function testAbsolute() : void public function testAbsolute() : void
{ {
self::assertEquals(\realpath(__DIR__ . '/..'), FileUtils::absolute(__DIR__ . '/..'));
self::assertEquals('/test/ative', FileUtils::absolute('/test/path/for/../rel/../../ative')); self::assertEquals('/test/ative', FileUtils::absolute('/test/path/for/../rel/../../ative'));
} }
@ -66,4 +67,9 @@ class FileUtilsTest extends \PHPUnit\Framework\TestCase
{ {
self::assertEquals(0742, FileUtils::permissionToOctal('rwxr---w-')); self::assertEquals(0742, FileUtils::permissionToOctal('rwxr---w-'));
} }
public function testChangeFileEncoding() : void
{
self::markTestIncomplete();
}
} }

View File

@ -27,7 +27,7 @@ class MbStringUtilsTest extends \PHPUnit\Framework\TestCase
{ {
/** /**
* @testdox The entropy of a string can be calculated * @testdox The entropy of a string can be calculated
* @covers phpOMS\Utils\StringUtils * @covers phpOMS\Utils\MbStringUtils
* @group framework * @group framework
*/ */
public function testEntropy() : void public function testEntropy() : void
@ -37,7 +37,7 @@ class MbStringUtilsTest extends \PHPUnit\Framework\TestCase
/** /**
* @testdox A string can be checked for multi-byte characters * @testdox A string can be checked for multi-byte characters
* @covers phpOMS\Utils\StringUtils * @covers phpOMS\Utils\MbStringUtils
* @group framework * @group framework
*/ */
public function testHasMultiBytes() : void public function testHasMultiBytes() : void
@ -151,4 +151,9 @@ class MbStringUtilsTest extends \PHPUnit\Framework\TestCase
{ {
self::assertEquals(5, MbStringUtils::mb_count_chars('αααααΕεΙιΜμΨψ')['α']); self::assertEquals(5, MbStringUtils::mb_count_chars('αααααΕεΙιΜμΨψ')['α']);
} }
public function testUtf8CharBoundary() : void
{
self::markTestIncomplete();
}
} }