mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
fix bugs and implement more sort algs
This commit is contained in:
parent
35e410f832
commit
85abb6c520
|
|
@ -28,6 +28,7 @@ final class MinimumCoinProblem
|
|||
* Constructure
|
||||
*
|
||||
* @since 1.0.0
|
||||
* @codeCoverageIgnore
|
||||
*/
|
||||
private function __construct()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
|
|
|
|||
|
|
@ -45,6 +45,10 @@ class BucketSort
|
|||
return [];
|
||||
}
|
||||
|
||||
if (\count($list) < 2) {
|
||||
return $list;
|
||||
}
|
||||
|
||||
foreach ($list as $element) {
|
||||
$buckets[(int) \floor(($bucketCount - 1) * $element->getValue() / $M)][] = $element;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class CycleSort implements SortInterface
|
|||
$pos = $start;
|
||||
$length0 = \count($list);
|
||||
for ($i = $start + 1; $i < $length0; ++$i) {
|
||||
if ($list[$i]->getValue() < $item->getValue()) {
|
||||
if (!$list[$i]->compare($item, $order)) {
|
||||
++$pos;
|
||||
}
|
||||
}
|
||||
|
|
@ -51,7 +51,7 @@ class CycleSort implements SortInterface
|
|||
continue;
|
||||
}
|
||||
|
||||
while ($item->getValue() === $list[$pos]->getValue()) {
|
||||
while ($item->equals($list[$pos])) {
|
||||
++$pos;
|
||||
}
|
||||
|
||||
|
|
@ -64,12 +64,12 @@ class CycleSort implements SortInterface
|
|||
$pos = $start;
|
||||
$length1 = \count($list);
|
||||
for ($i = $start + 1; $i < $length1; ++$i) {
|
||||
if ($list[$i]->getValue() < $item->getValue()) {
|
||||
if (!$list[$i]->compare($item, $order)) {
|
||||
++$pos;
|
||||
}
|
||||
}
|
||||
|
||||
while ($item->getValue() === $list[$pos]->getValue()) {
|
||||
while ($item->equals($list[$pos])) {
|
||||
++$pos;
|
||||
}
|
||||
|
||||
|
|
@ -80,6 +80,6 @@ class CycleSort implements SortInterface
|
|||
}
|
||||
}
|
||||
|
||||
return $order === SortOrder::ASC ? $list : \array_reverse($list, false);
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,124 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package phpOMS\Algorithm\Sort;
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Algorithm\Sort;
|
||||
|
||||
use phpOMS\Utils\NumericUtils;
|
||||
|
||||
/**
|
||||
* FlashSort class.
|
||||
*
|
||||
* @package phpOMS\Algorithm\Sort;
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class FlashSort implements SortInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function sort(array $list, int $order = SortOrder::ASC) : array
|
||||
{
|
||||
$n = \count($list);
|
||||
$i = 0;
|
||||
$j = 0;
|
||||
$k = 0;
|
||||
$m = 0.43 * $n;
|
||||
|
||||
if ($m > 262143) {
|
||||
$m = 262143;
|
||||
}
|
||||
|
||||
$l = \array_fill(0, $n, 0);
|
||||
$anmin = $list[0];
|
||||
$anmax = $anmin;
|
||||
$nmax = 0;
|
||||
$nmove = 0;
|
||||
$lk = 0;
|
||||
|
||||
$kmin = null;
|
||||
$kmax = null;
|
||||
|
||||
// todo: replace >>> with Numeric::uRightShift
|
||||
|
||||
for ($i = 0; NumericUtils::uRightShift(($i += 2) - $n, 31);) {
|
||||
if (NumericUtils::uRightShift(($kmax = $list[$i - 1])->getValue() - ($kmin = $list[$i])->getValue(), 31)) {
|
||||
if (NumericUtils::uRightShift($kmax->getValue() - $anmin->getValue(), 31)) {
|
||||
$anmin = $list[$i - 1];
|
||||
}
|
||||
|
||||
if (NumericUtils::uRightShift($anmax->getValue() - $kmin->getValue(), 31)) {
|
||||
$anmax = $list[$i];
|
||||
$nmax = $i;
|
||||
}
|
||||
} else {
|
||||
if (NumericUtils::uRightShift($kmin->getValue() - $anmin->getValue(), 31)) {
|
||||
$anmin = $list[$i];
|
||||
}
|
||||
|
||||
if (NumericUtils::uRightShift($anmax->getValue() - $kmin->getValue(), 31)) {
|
||||
$anmax = $list[$i - 1];
|
||||
$nmax = $i - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NumericUtils::uRightShift(--$i - $n, 31)) {
|
||||
if (NumericUtils::uRightShift(($k = $list[$i])->getValue() - $anmin->getValue(), 31)) {
|
||||
$anmin = $list[$i];
|
||||
} elseif (NumericUtils::uRightShift($anmax->getValue() - $k->getValue(), 31)) {
|
||||
$anmax = $list[$i];
|
||||
$nmax = $i;
|
||||
}
|
||||
}
|
||||
|
||||
if ($anmin->getValue() === $anmax->getValue()) {
|
||||
return $list;
|
||||
}
|
||||
|
||||
$c1 = (($m - 1) << 13) / ($anmax->getValue() - $anmin->getValue());
|
||||
|
||||
for ($i = -1; NumericUtils::uRightShift(++$i - $n, 31);) {
|
||||
++$l[($c1 * ($list[$i]->getValue() - $anmin->getValue())) >> 13];
|
||||
}
|
||||
|
||||
$lk = $l[0];
|
||||
for ($k = 0; NumericUtils::uRightShift(++$k - $m, 31);) {
|
||||
$lk = ($l[$k] += $lk);
|
||||
}
|
||||
|
||||
$hold = $anmax;
|
||||
$list[$nmax] = $list[0];
|
||||
$list[0] = $hold;
|
||||
|
||||
$flash = null;
|
||||
$j = 0;
|
||||
$k = ($m - 1);
|
||||
$i = ($n - 1);
|
||||
|
||||
while (NumericUtils::uRightShift($nmove - $i, 31)) {
|
||||
while ($j !== $lk) {
|
||||
$k = ($c1 * ($list[(++$j)]->getValue() - $anmin->getValue())) >> 13;
|
||||
}
|
||||
|
||||
$flash = $a[$j];
|
||||
$lk = $l[$k];
|
||||
|
||||
while ($j !== $lk) {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -29,7 +29,12 @@ class HeapSort implements SortInterface
|
|||
*/
|
||||
public static function sort(array $list, int $order = SortOrder::ASC) : array
|
||||
{
|
||||
$n = \count($list);
|
||||
$n = \count($list);
|
||||
|
||||
if ($n < 2) {
|
||||
return $list;
|
||||
}
|
||||
|
||||
$copy = $list;
|
||||
|
||||
for ($p = ($n - 1) / 2; $p >= 0; --$p) {
|
||||
|
|
|
|||
|
|
@ -31,6 +31,10 @@ class InsertionSort implements SortInterface
|
|||
{
|
||||
$n = \count($list);
|
||||
|
||||
if ($n < 2) {
|
||||
return $list;
|
||||
}
|
||||
|
||||
for ($i = 1; $i < $n; ++$i) {
|
||||
$pivot = $list[$i];
|
||||
$j = $i - 1;
|
||||
|
|
|
|||
|
|
@ -29,8 +29,14 @@ class MergeSort implements SortInterface
|
|||
*/
|
||||
public static function sort(array $list, int $order = SortOrder::ASC) : array
|
||||
{
|
||||
$n = \count($list);
|
||||
|
||||
if ($n < 2) {
|
||||
return $list;
|
||||
}
|
||||
|
||||
$clone = $list;
|
||||
self::sortHalve($clone, 0, \count($list) - 1, $order);
|
||||
self::sortHalve($clone, 0, $n - 1, $order);
|
||||
|
||||
return $clone;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,77 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package phpOMS\Algorithm\Sort;
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Algorithm\Sort;
|
||||
|
||||
/**
|
||||
* PancakeSort class.
|
||||
*
|
||||
* @package phpOMS\Algorithm\Sort;
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class PancakeSort implements SortInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function sort(array $list, int $order = SortOrder::ASC) : array
|
||||
{
|
||||
$n = \count($list);
|
||||
|
||||
if ($n < 2) {
|
||||
return $list;
|
||||
}
|
||||
|
||||
for ($i = $n; $i > 1; --$i) {
|
||||
$m = 0;
|
||||
for ($j = 0; $j < $i; ++$j) {
|
||||
if ($list[$j]->compare($list[$m], $order)) {
|
||||
$m = $j;
|
||||
}
|
||||
}
|
||||
|
||||
if ($m !== $i - 1) {
|
||||
// flip max/min to the beginning
|
||||
$start = 0;
|
||||
$c = $m;
|
||||
|
||||
while ($start < $c) {
|
||||
$temp = $list[$start];
|
||||
$list[$start] = $list[$c];
|
||||
$list[$c] = $temp;
|
||||
|
||||
++$start;
|
||||
--$c;
|
||||
}
|
||||
|
||||
// flip reverse array
|
||||
$start = 0;
|
||||
$c = $i - 1;
|
||||
|
||||
while ($start < $c) {
|
||||
$temp = $list[$start];
|
||||
$list[$start] = $list[$c];
|
||||
$list[$c] = $temp;
|
||||
|
||||
++$start;
|
||||
--$c;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
|
|
@ -29,8 +29,14 @@ class QuickSort implements SortInterface
|
|||
*/
|
||||
public static function sort(array $list, int $order = SortOrder::ASC) : array
|
||||
{
|
||||
$n = \count($list);
|
||||
|
||||
if ($n < 2) {
|
||||
return $list;
|
||||
}
|
||||
|
||||
$copy = $list;
|
||||
self::qsort($copy, 0, \count($list) - 1, $order);
|
||||
self::qsort($copy, 0, $n - 1, $order);
|
||||
|
||||
return $copy;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,52 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package phpOMS\Algorithm\Sort;
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Algorithm\Sort;
|
||||
|
||||
/**
|
||||
* ShellSort class.
|
||||
*
|
||||
* @package phpOMS\Algorithm\Sort;
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class ShellSort implements SortInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function sort(array $list, int $order = SortOrder::ASC) : array
|
||||
{
|
||||
$n = \count($list);
|
||||
|
||||
if ($n < 2) {
|
||||
return $list;
|
||||
}
|
||||
|
||||
for ($i = $n / 2; $i > 0; $i = (int) ($i / 2)) {
|
||||
for ($j = $i; $j < $n; ++$j) {
|
||||
$temp = $list[$j];
|
||||
|
||||
for ($c = $j; $c >= $i && $list[$c - $i]->compare($temp, $order); $c -= $i) {
|
||||
$list[$c] = $list[$c - $i];
|
||||
}
|
||||
|
||||
$list[$c] = $temp;
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
|
|
@ -45,6 +45,17 @@ interface SortableInterface
|
|||
*/
|
||||
public function getValue();
|
||||
|
||||
/**
|
||||
* Is value the same
|
||||
*
|
||||
* @param SortableInterface $obj Object to compare with
|
||||
*
|
||||
* @return bool
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function equals(self $obj) : bool;
|
||||
|
||||
/**
|
||||
* Get maximum element
|
||||
*
|
||||
|
|
|
|||
76
Algorithm/Sort/StoogeSort.php
Normal file
76
Algorithm/Sort/StoogeSort.php
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package phpOMS\Algorithm\Sort;
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Algorithm\Sort;
|
||||
|
||||
/**
|
||||
* StoogeSort class.
|
||||
*
|
||||
* @package phpOMS\Algorithm\Sort;
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class StoogeSort implements SortInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function sort(array $list, int $order = SortOrder::ASC) : array
|
||||
{
|
||||
$n = \count($list);
|
||||
|
||||
if ($n < 2) {
|
||||
return $list;
|
||||
}
|
||||
|
||||
$copy = $list;
|
||||
self::stoogeSort($copy, 0, $n - 1, $order);
|
||||
|
||||
return $copy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively sort each 3rd of the list
|
||||
*
|
||||
* @param array $list Data to sort
|
||||
* @param int $lo Lower bound
|
||||
* @param int $hi Higher bound
|
||||
* @param int $order Sort order
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private static function stoogeSort(array &$list, int $lo, int $hi, int $order) : void
|
||||
{
|
||||
if ($lo >= $hi) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($list[$lo]->compare($list[$hi], $order)) {
|
||||
$temp = $list[$lo];
|
||||
$list[$lo] = $list[$hi];
|
||||
$list[$hi] = $temp;
|
||||
}
|
||||
|
||||
if ($hi - $lo + 1 > 2) {
|
||||
$t = (int) (($hi - $lo + 1) / 3);
|
||||
|
||||
self::stoogeSort($list, $lo, $hi - $t, $order);
|
||||
self::stoogeSort($list, $lo + $t, $hi, $order);
|
||||
self::stoogeSort($list, $lo, $hi - $t, $order);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,115 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package phpOMS\Algorithm\Sort;
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace phpOMS\Algorithm\Sort;
|
||||
|
||||
/**
|
||||
* TimSort class.
|
||||
*
|
||||
* @package phpOMS\Algorithm\Sort;
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class TimSort implements SortInterface
|
||||
{
|
||||
/**
|
||||
* Blocks the sorting is devided into
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private const BLOCKS = 32;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public static function sort(array $list, int $order = SortOrder::ASC) : array
|
||||
{
|
||||
$n = \count($list);
|
||||
|
||||
if ($n < 2) {
|
||||
return $list;
|
||||
}
|
||||
|
||||
for ($lo = 0; $lo < $n; $lo += self::BLOCKS) {
|
||||
// insertion sort
|
||||
$hi = \min($lo + 31, $n - 1);
|
||||
for ($j = $lo + 1; $j <= $hi; ++$j) {
|
||||
$temp = $list[$j];
|
||||
$c = $j - 1;
|
||||
|
||||
while ($c >= $lo && $list[$c]->compare($temp, $order))
|
||||
{
|
||||
$list[$c + 1] = $list[$c];
|
||||
--$c;
|
||||
}
|
||||
|
||||
$list[$c + 1] = $temp;
|
||||
}
|
||||
}
|
||||
|
||||
for ($size = self::BLOCKS; $size < $n; $size *= 2) {
|
||||
for ($lo = 0; $lo < $n; $lo += 2 * $size) {
|
||||
// merge sort
|
||||
$mi = $lo + $size - 1;
|
||||
$hi = \min($lo + 2 * $size - 1, $n - 1);
|
||||
|
||||
$n1 = $mi - $lo + 1;
|
||||
$n2 = $hi - $mi;
|
||||
|
||||
$loList = [];
|
||||
$hiList = [];
|
||||
|
||||
for ($i = 0; $i < $n1; ++$i) {
|
||||
$loList[$i] = $list[$lo + $i];
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $n2; ++$i) {
|
||||
$hiList[$i] = $list[$mi + 1 + $i];
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
$j = 0;
|
||||
$k = $lo;
|
||||
|
||||
while ($i < $n1 && $j < $n2) {
|
||||
if (!$loList[$i]->compare($hiList[$j], $order)) {
|
||||
$list[$k] = $loList[$i];
|
||||
++$i;
|
||||
} else {
|
||||
$list[$k] = $hiList[$j];
|
||||
++$j;
|
||||
}
|
||||
|
||||
++$k;
|
||||
}
|
||||
|
||||
while ($i < $n1) {
|
||||
$list[$k] = $loList[$i];
|
||||
++$i;
|
||||
++$k;
|
||||
}
|
||||
|
||||
while ($j < $n2) {
|
||||
$list[$k] = $hiList[$j];
|
||||
++$j;
|
||||
++$k;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ class NaiveBayesFilter
|
|||
|
||||
if (\is_array($value)) {
|
||||
foreach ($value as $word) {
|
||||
if(!isset($this->dict[$criteria][$attr]['data'][$word])) {
|
||||
if (!isset($this->dict[$criteria][$attr]['data'][$word])) {
|
||||
$this->dict[$criteria][$attr]['data'][$word] = 0;
|
||||
}
|
||||
|
||||
|
|
@ -152,7 +152,7 @@ class NaiveBayesFilter
|
|||
if (isset($this->dict[$criteria][$attr]['data'][$word])
|
||||
&& $this->dict[$criteria][$attr]['data'][$word] >= $minimum
|
||||
) {
|
||||
$p = $this->dict[$criteria][$attr]['data'][$word] / \array_sum($this->dict[$criteria][$attr]['data'])
|
||||
$p = $this->dict[$criteria][$attr]['data'][$word] / \array_sum($this->dict[$criteria][$attr]['data'])
|
||||
/ $this->probabilities['attr'][$attr]['evidence'];
|
||||
|
||||
$n += \log(1 - $p) - \log($p);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ final class FileUtils
|
|||
public const VIDEO_EXTENSION = ['mp4', 'flv', 'vob', 'wmv', 'swf', 'mpg', 'mpeg', 'mov', 'mkv', 'h264', 'avi'];
|
||||
public const SPREADSHEET_EXTENSION = ['xls', 'xlsm', 'xlr', 'ods'];
|
||||
public const IMAGE_EXTENSION = ['png', 'gif', 'jpg', 'jpeg', 'tif', 'tiff', 'bmp', 'svg', 'ico'];
|
||||
public const DIRECTORY = ['collection'];
|
||||
public const DIRECTORY = ['collection', '/'];
|
||||
public const SYSTEM_EXTENSION = ['bak', 'dll', 'sys', 'tmp', 'msi', 'so', 'exe', 'bin', 'iso'];
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -26,14 +26,6 @@ namespace phpOMS\System\File;
|
|||
*/
|
||||
abstract class StorageAbstract
|
||||
{
|
||||
/**
|
||||
* Storage type.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected int $type = 0;
|
||||
|
||||
/**
|
||||
* Get instance.
|
||||
*
|
||||
|
|
@ -54,18 +46,6 @@ abstract class StorageAbstract
|
|||
*/
|
||||
abstract protected static function getClassType(string $path) : string;
|
||||
|
||||
/**
|
||||
* Get storage type.
|
||||
*
|
||||
* @return int storage type
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getType() : int
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the datetime when the resource got created.
|
||||
*
|
||||
|
|
|
|||
|
|
@ -64,6 +64,8 @@ class CsvSettings
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
$line = \fgets($file);
|
||||
}
|
||||
|
||||
$results = \array_keys($results, \max($results));
|
||||
|
|
|
|||
|
|
@ -33,7 +33,9 @@ abstract class Json extends ValidatorAbstract
|
|||
*/
|
||||
public static function isValid($value, array $constraints = null) : bool
|
||||
{
|
||||
return true;
|
||||
\json_decode($value);
|
||||
|
||||
return \json_last_error() == \JSON_ERROR_NONE;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -37,6 +37,10 @@ class PermissionAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertNull($perm->getElement());
|
||||
self::assertNull($perm->getComponent());
|
||||
self::assertEquals(PermissionType::NONE, $perm->getPermission());
|
||||
self::assertTrue($perm->hasPermission(PermissionType::NONE));
|
||||
self::assertTrue($perm->hasPermissionFlags(PermissionType::NONE));
|
||||
self::assertFalse($perm->hasPermission(2));
|
||||
self::assertFalse($perm->hasPermissionFlags(2));
|
||||
|
||||
self::assertEquals(
|
||||
[
|
||||
|
|
@ -86,5 +90,9 @@ class PermissionAbstractTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertTrue($perm->hasPermission(PermissionType::CREATE));
|
||||
self::assertTrue($perm->hasPermission(PermissionType::READ));
|
||||
self::assertFalse($perm->hasPermission(PermissionType::MODIFY));
|
||||
|
||||
self::assertTrue($perm->hasPermissionFlags(PermissionType::READ));
|
||||
self::assertTrue($perm->hasPermissionFlags(PermissionType::READ & PermissionType::CREATE));
|
||||
self::assertFalse($perm->hasPermissionFlags(PermissionType::MODIFY));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,14 @@ class BitonicSortTest extends \PHPUnit\Framework\TestCase
|
|||
];
|
||||
}
|
||||
|
||||
public function testSmallList() : void
|
||||
{
|
||||
$smallList = [new NumericElement(3)];
|
||||
$newList = BitonicSort::sort($smallList);
|
||||
|
||||
self::assertEquals($smallList, $newList);
|
||||
}
|
||||
|
||||
public function testSortASC() : void
|
||||
{
|
||||
$newList = BitonicSort::sort($this->list);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,14 @@ class BubbleSortTest extends \PHPUnit\Framework\TestCase
|
|||
];
|
||||
}
|
||||
|
||||
public function testSmallList() : void
|
||||
{
|
||||
$smallList = [new NumericElement(3)];
|
||||
$newList = BubbleSort::sort($smallList);
|
||||
|
||||
self::assertEquals($smallList, $newList);
|
||||
}
|
||||
|
||||
public function testSortASC() : void
|
||||
{
|
||||
$newList = BubbleSort::sort($this->list);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,14 @@ class BucketSortTest extends \PHPUnit\Framework\TestCase
|
|||
];
|
||||
}
|
||||
|
||||
public function testSmallList() : void
|
||||
{
|
||||
$smallList = [new NumericElement(3)];
|
||||
$newList = BucketSort::sort($smallList, 2);
|
||||
|
||||
self::assertEquals($smallList, $newList);
|
||||
}
|
||||
|
||||
public function testSortASC() : void
|
||||
{
|
||||
$newList = BucketSort::sort($this->list, 2, \phpOMS\Algorithm\Sort\SelectionSort::class);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,14 @@ class CocktailShakerSortTest extends \PHPUnit\Framework\TestCase
|
|||
];
|
||||
}
|
||||
|
||||
public function testSmallList() : void
|
||||
{
|
||||
$smallList = [new NumericElement(3)];
|
||||
$newList = CocktailShakerSort::sort($smallList);
|
||||
|
||||
self::assertEquals($smallList, $newList);
|
||||
}
|
||||
|
||||
public function testSortASC() : void
|
||||
{
|
||||
$newList = CocktailShakerSort::sort($this->list);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,14 @@ class CombSortTest extends \PHPUnit\Framework\TestCase
|
|||
];
|
||||
}
|
||||
|
||||
public function testSmallList() : void
|
||||
{
|
||||
$smallList = [new NumericElement(3)];
|
||||
$newList = CombSort::sort($smallList);
|
||||
|
||||
self::assertEquals($smallList, $newList);
|
||||
}
|
||||
|
||||
public function testSortASC() : void
|
||||
{
|
||||
$newList = CombSort::sort($this->list);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,14 @@ class CycleSortTest extends \PHPUnit\Framework\TestCase
|
|||
];
|
||||
}
|
||||
|
||||
public function testSmallList() : void
|
||||
{
|
||||
$smallList = [new NumericElement(3)];
|
||||
$newList = CycleSort::sort($smallList);
|
||||
|
||||
self::assertEquals($smallList, $newList);
|
||||
}
|
||||
|
||||
public function testSortASC() : void
|
||||
{
|
||||
$newList = CycleSort::sort($this->list);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,14 @@ class GnomeSortTest extends \PHPUnit\Framework\TestCase
|
|||
];
|
||||
}
|
||||
|
||||
public function testSmallList() : void
|
||||
{
|
||||
$smallList = [new NumericElement(3)];
|
||||
$newList = GnomeSort::sort($smallList);
|
||||
|
||||
self::assertEquals($smallList, $newList);
|
||||
}
|
||||
|
||||
public function testSortASC() : void
|
||||
{
|
||||
$newList = GnomeSort::sort($this->list);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,14 @@ class HeapSortTest extends \PHPUnit\Framework\TestCase
|
|||
];
|
||||
}
|
||||
|
||||
public function testSmallList() : void
|
||||
{
|
||||
$smallList = [new NumericElement(3)];
|
||||
$newList = HeapSort::sort($smallList);
|
||||
|
||||
self::assertEquals($smallList, $newList);
|
||||
}
|
||||
|
||||
public function testSortASC() : void
|
||||
{
|
||||
$newList = HeapSort::sort($this->list);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,14 @@ class InsertionSortTest extends \PHPUnit\Framework\TestCase
|
|||
];
|
||||
}
|
||||
|
||||
public function testSmallList() : void
|
||||
{
|
||||
$smallList = [new NumericElement(3)];
|
||||
$newList = InsertionSort::sort($smallList);
|
||||
|
||||
self::assertEquals($smallList, $newList);
|
||||
}
|
||||
|
||||
public function testSortASC() : void
|
||||
{
|
||||
$newList = InsertionSort::sort($this->list);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,14 @@ class IntroSortTest extends \PHPUnit\Framework\TestCase
|
|||
];
|
||||
}
|
||||
|
||||
public function testSmallList() : void
|
||||
{
|
||||
$smallList = [new NumericElement(3)];
|
||||
$newList = IntroSort::sort($smallList);
|
||||
|
||||
self::assertEquals($smallList, $newList);
|
||||
}
|
||||
|
||||
public function testSortASC() : void
|
||||
{
|
||||
$newList = IntroSort::sort($this->list);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,14 @@ class MergeSortTest extends \PHPUnit\Framework\TestCase
|
|||
];
|
||||
}
|
||||
|
||||
public function testSmallList() : void
|
||||
{
|
||||
$smallList = [new NumericElement(3)];
|
||||
$newList = MergeSort::sort($smallList);
|
||||
|
||||
self::assertEquals($smallList, $newList);
|
||||
}
|
||||
|
||||
public function testSortASC() : void
|
||||
{
|
||||
$newList = MergeSort::sort($this->list);
|
||||
|
|
|
|||
|
|
@ -33,6 +33,11 @@ class NumericElement implements SortableInterface
|
|||
return $order === SortOrder::ASC ? $this->value > $obj->value : $this->value < $obj->value;
|
||||
}
|
||||
|
||||
public function equals(SortableInterface $obj) : bool
|
||||
{
|
||||
return $this->value === $obj->getValue();
|
||||
}
|
||||
|
||||
public function getValue()
|
||||
{
|
||||
return $this->value;
|
||||
|
|
|
|||
|
|
@ -39,6 +39,14 @@ class OddEvenSortTest extends \PHPUnit\Framework\TestCase
|
|||
];
|
||||
}
|
||||
|
||||
public function testSmallList() : void
|
||||
{
|
||||
$smallList = [new NumericElement(3)];
|
||||
$newList = OddEvenSort::sort($smallList);
|
||||
|
||||
self::assertEquals($smallList, $newList);
|
||||
}
|
||||
|
||||
public function testSortASC() : void
|
||||
{
|
||||
$newList = OddEvenSort::sort($this->list);
|
||||
|
|
|
|||
73
tests/Algorithm/Sort/PancakeSortTest.php
Normal file
73
tests/Algorithm/Sort/PancakeSortTest.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?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\Algorithm\Sort;
|
||||
|
||||
use phpOMS\Algorithm\Sort\PancakeSort;
|
||||
use phpOMS\Algorithm\Sort\SortOrder;
|
||||
|
||||
require_once __DIR__ . '/../../Autoloader.php';
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Algorithm\Sort: Pancake sort test
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class PancakeSortTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $list = [];
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->list = [
|
||||
new NumericElement(5),
|
||||
new NumericElement(1),
|
||||
new NumericElement(4),
|
||||
new NumericElement(2),
|
||||
new NumericElement(8),
|
||||
];
|
||||
}
|
||||
|
||||
public function testSmallList() : void
|
||||
{
|
||||
$smallList = [new NumericElement(3)];
|
||||
$newList = PancakeSort::sort($smallList);
|
||||
|
||||
self::assertEquals($smallList, $newList);
|
||||
}
|
||||
|
||||
public function testSortASC() : void
|
||||
{
|
||||
$newList = PancakeSort::sort($this->list);
|
||||
self::assertEquals(
|
||||
[1, 2, 4, 5, 8], [$newList[0]->value, $newList[1]->value, $newList[2]->value, $newList[3]->value, $newList[4]->value,]
|
||||
);
|
||||
|
||||
self::assertEquals(
|
||||
[5, 1, 4, 2, 8], [$this->list[0]->value, $this->list[1]->value, $this->list[2]->value, $this->list[3]->value, $this->list[4]->value,]
|
||||
);
|
||||
}
|
||||
|
||||
public function testSortDESC() : void
|
||||
{
|
||||
$newList = PancakeSort::sort($this->list, SortOrder::DESC);
|
||||
self::assertEquals(
|
||||
[8, 5, 4, 2, 1], [$newList[0]->value, $newList[1]->value, $newList[2]->value, $newList[3]->value, $newList[4]->value,]
|
||||
);
|
||||
|
||||
self::assertEquals(
|
||||
[5, 1, 4, 2, 8], [$this->list[0]->value, $this->list[1]->value, $this->list[2]->value, $this->list[3]->value, $this->list[4]->value,]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -39,6 +39,14 @@ class QuickSortTest extends \PHPUnit\Framework\TestCase
|
|||
];
|
||||
}
|
||||
|
||||
public function testSmallList() : void
|
||||
{
|
||||
$smallList = [new NumericElement(3)];
|
||||
$newList = QuickSort::sort($smallList);
|
||||
|
||||
self::assertEquals($smallList, $newList);
|
||||
}
|
||||
|
||||
public function testSortASC() : void
|
||||
{
|
||||
$newList = QuickSort::sort($this->list);
|
||||
|
|
|
|||
|
|
@ -39,6 +39,14 @@ class SelectionSortTest extends \PHPUnit\Framework\TestCase
|
|||
];
|
||||
}
|
||||
|
||||
public function testSmallList() : void
|
||||
{
|
||||
$smallList = [new NumericElement(3)];
|
||||
$newList = SelectionSort::sort($smallList);
|
||||
|
||||
self::assertEquals($smallList, $newList);
|
||||
}
|
||||
|
||||
public function testSortASC() : void
|
||||
{
|
||||
$newList = SelectionSort::sort($this->list);
|
||||
|
|
|
|||
73
tests/Algorithm/Sort/ShellSortTest.php
Normal file
73
tests/Algorithm/Sort/ShellSortTest.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?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\Algorithm\Sort;
|
||||
|
||||
use phpOMS\Algorithm\Sort\ShellSort;
|
||||
use phpOMS\Algorithm\Sort\SortOrder;
|
||||
|
||||
require_once __DIR__ . '/../../Autoloader.php';
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Algorithm\Sort: Shell sort test
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class ShellSortTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $list = [];
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->list = [
|
||||
new NumericElement(5),
|
||||
new NumericElement(1),
|
||||
new NumericElement(4),
|
||||
new NumericElement(2),
|
||||
new NumericElement(8),
|
||||
];
|
||||
}
|
||||
|
||||
public function testSmallList() : void
|
||||
{
|
||||
$smallList = [new NumericElement(3)];
|
||||
$newList = ShellSort::sort($smallList);
|
||||
|
||||
self::assertEquals($smallList, $newList);
|
||||
}
|
||||
|
||||
public function testSortASC() : void
|
||||
{
|
||||
$newList = ShellSort::sort($this->list);
|
||||
self::assertEquals(
|
||||
[1, 2, 4, 5, 8], [$newList[0]->value, $newList[1]->value, $newList[2]->value, $newList[3]->value, $newList[4]->value,]
|
||||
);
|
||||
|
||||
self::assertEquals(
|
||||
[5, 1, 4, 2, 8], [$this->list[0]->value, $this->list[1]->value, $this->list[2]->value, $this->list[3]->value, $this->list[4]->value,]
|
||||
);
|
||||
}
|
||||
|
||||
public function testSortDESC() : void
|
||||
{
|
||||
$newList = ShellSort::sort($this->list, SortOrder::DESC);
|
||||
self::assertEquals(
|
||||
[8, 5, 4, 2, 1], [$newList[0]->value, $newList[1]->value, $newList[2]->value, $newList[3]->value, $newList[4]->value,]
|
||||
);
|
||||
|
||||
self::assertEquals(
|
||||
[5, 1, 4, 2, 8], [$this->list[0]->value, $this->list[1]->value, $this->list[2]->value, $this->list[3]->value, $this->list[4]->value,]
|
||||
);
|
||||
}
|
||||
}
|
||||
73
tests/Algorithm/Sort/StoogeSortTest.php
Normal file
73
tests/Algorithm/Sort/StoogeSortTest.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?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\Algorithm\Sort;
|
||||
|
||||
use phpOMS\Algorithm\Sort\StoogeSort;
|
||||
use phpOMS\Algorithm\Sort\SortOrder;
|
||||
|
||||
require_once __DIR__ . '/../../Autoloader.php';
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Algorithm\Sort: Stooge sort test
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class StoogeSortTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $list = [];
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->list = [
|
||||
new NumericElement(5),
|
||||
new NumericElement(1),
|
||||
new NumericElement(4),
|
||||
new NumericElement(2),
|
||||
new NumericElement(8),
|
||||
];
|
||||
}
|
||||
|
||||
public function testSmallList() : void
|
||||
{
|
||||
$smallList = [new NumericElement(3)];
|
||||
$newList = StoogeSort::sort($smallList);
|
||||
|
||||
self::assertEquals($smallList, $newList);
|
||||
}
|
||||
|
||||
public function testSortASC() : void
|
||||
{
|
||||
$newList = StoogeSort::sort($this->list);
|
||||
self::assertEquals(
|
||||
[1, 2, 4, 5, 8], [$newList[0]->value, $newList[1]->value, $newList[2]->value, $newList[3]->value, $newList[4]->value,]
|
||||
);
|
||||
|
||||
self::assertEquals(
|
||||
[5, 1, 4, 2, 8], [$this->list[0]->value, $this->list[1]->value, $this->list[2]->value, $this->list[3]->value, $this->list[4]->value,]
|
||||
);
|
||||
}
|
||||
|
||||
public function testSortDESC() : void
|
||||
{
|
||||
$newList = StoogeSort::sort($this->list, SortOrder::DESC);
|
||||
self::assertEquals(
|
||||
[8, 5, 4, 2, 1], [$newList[0]->value, $newList[1]->value, $newList[2]->value, $newList[3]->value, $newList[4]->value,]
|
||||
);
|
||||
|
||||
self::assertEquals(
|
||||
[5, 1, 4, 2, 8], [$this->list[0]->value, $this->list[1]->value, $this->list[2]->value, $this->list[3]->value, $this->list[4]->value,]
|
||||
);
|
||||
}
|
||||
}
|
||||
73
tests/Algorithm/Sort/TimSortTest.php
Normal file
73
tests/Algorithm/Sort/TimSortTest.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?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\Algorithm\Sort;
|
||||
|
||||
use phpOMS\Algorithm\Sort\TimSort;
|
||||
use phpOMS\Algorithm\Sort\SortOrder;
|
||||
|
||||
require_once __DIR__ . '/../../Autoloader.php';
|
||||
|
||||
/**
|
||||
* @testdox phpOMS\tests\Algorithm\Sort: Tim sort test
|
||||
*
|
||||
* @internal
|
||||
*/
|
||||
class TimSortTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
protected $list = [];
|
||||
|
||||
protected function setUp() : void
|
||||
{
|
||||
$this->list = [
|
||||
new NumericElement(5),
|
||||
new NumericElement(1),
|
||||
new NumericElement(4),
|
||||
new NumericElement(2),
|
||||
new NumericElement(8),
|
||||
];
|
||||
}
|
||||
|
||||
public function testSmallList() : void
|
||||
{
|
||||
$smallList = [new NumericElement(3)];
|
||||
$newList = TimSort::sort($smallList);
|
||||
|
||||
self::assertEquals($smallList, $newList);
|
||||
}
|
||||
|
||||
public function testSortASC() : void
|
||||
{
|
||||
$newList = TimSort::sort($this->list);
|
||||
self::assertEquals(
|
||||
[1, 2, 4, 5, 8], [$newList[0]->value, $newList[1]->value, $newList[2]->value, $newList[3]->value, $newList[4]->value,]
|
||||
);
|
||||
|
||||
self::assertEquals(
|
||||
[5, 1, 4, 2, 8], [$this->list[0]->value, $this->list[1]->value, $this->list[2]->value, $this->list[3]->value, $this->list[4]->value,]
|
||||
);
|
||||
}
|
||||
|
||||
public function testSortDESC() : void
|
||||
{
|
||||
$newList = TimSort::sort($this->list, SortOrder::DESC);
|
||||
self::assertEquals(
|
||||
[8, 5, 4, 2, 1], [$newList[0]->value, $newList[1]->value, $newList[2]->value, $newList[3]->value, $newList[4]->value,]
|
||||
);
|
||||
|
||||
self::assertEquals(
|
||||
[5, 1, 4, 2, 8], [$this->list[0]->value, $this->list[1]->value, $this->list[2]->value, $this->list[3]->value, $this->list[4]->value,]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -333,7 +333,7 @@ class FinanceFormulasTest extends \PHPUnit\Framework\TestCase
|
|||
$r = 0.05;
|
||||
|
||||
self::assertEqualsWithDelta(13.863, FinanceFormulas::getDoublingTimeContinuousCompounding($r), 0.01);
|
||||
self::assertEqualsWithDelta($r, FinanceFormulas::getDoublingTimeContinuousCompounding(13.863), 0.01);
|
||||
self::assertEqualsWithDelta($r, FinanceFormulas::getDoublingContinuousCompoundingRate(13.863), 0.01);
|
||||
}
|
||||
|
||||
public function testEquivalentAnnualAnnuity() : void
|
||||
|
|
|
|||
|
|
@ -20,6 +20,8 @@ use phpOMS\Math\Numerics\Integration;
|
|||
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
* Commented out assertions which take a loong time with xdebug. without xdebug these are fine!
|
||||
*/
|
||||
class IntegrationTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
|
|
@ -27,39 +29,39 @@ class IntegrationTest extends \PHPUnit\Framework\TestCase
|
|||
{
|
||||
self::assertEqualsWithDelta(0.235322, Integration::intLeftRect(0.0, 1.0, 100.0, function($x) { return $x**3; }), 0.001);
|
||||
self::assertEqualsWithDelta(4.654000, Integration::intLeftRect(1.0, 100.0, 1000.0, function($x) { return 1 / $x; }), 0.001);
|
||||
self::assertEqualsWithDelta(12499992.500730, Integration::intLeftRect(0.0, 5000.0, 5000000.0, function($x) { return $x; }), 0.001);
|
||||
self::assertEqualsWithDelta(17999991.001392, Integration::intLeftRect(0.0, 6000.0, 6000000.0, function($x) { return $x; }), 0.001);
|
||||
//self::assertEqualsWithDelta(12499992.500730, Integration::intLeftRect(0.0, 5000.0, 5000000.0, function($x) { return $x; }), 0.001);
|
||||
//self::assertEqualsWithDelta(17999991.001392, Integration::intLeftRect(0.0, 6000.0, 6000000.0, function($x) { return $x; }), 0.001);
|
||||
}
|
||||
|
||||
public function testRRect(): void
|
||||
{
|
||||
self::assertEqualsWithDelta(0.245025, Integration::intRightRect(0.0, 1.0, 100.0, function($x) { return $x**3; }), 0.001);
|
||||
self::assertEqualsWithDelta(4.555991, Integration::intRightRect(1.0, 100.0, 1000.0, function($x) { return 1 / $x; }), 0.001);
|
||||
self::assertEqualsWithDelta(12499997.500729, Integration::intRightRect(0.0, 5000.0, 5000000.0, function($x) { return $x; }), 0.001);
|
||||
self::assertEqualsWithDelta(17999997.001390, Integration::intRightRect(0.0, 6000.0, 6000000.0, function($x) { return $x; }), 0.001);
|
||||
//self::assertEqualsWithDelta(12499997.500729, Integration::intRightRect(0.0, 5000.0, 5000000.0, function($x) { return $x; }), 0.001);
|
||||
//self::assertEqualsWithDelta(17999997.001390, Integration::intRightRect(0.0, 6000.0, 6000000.0, function($x) { return $x; }), 0.001);
|
||||
}
|
||||
|
||||
public function testMRect(): void
|
||||
{
|
||||
self::assertEqualsWithDelta(0.240137, Integration::intMiddleRect(0.0, 1.0, 100.0, function($x) { return $x**3; }), 0.001);
|
||||
self::assertEqualsWithDelta(4.603772, Integration::intMiddleRect(1.0, 100.0, 1000.0, function($x) { return 1 / $x; }), 0.001);
|
||||
self::assertEqualsWithDelta(12499995.000729, Integration::intMiddleRect(0.0, 5000.0, 5000000.0, function($x) { return $x; }), 0.001);
|
||||
self::assertEqualsWithDelta(17999994.001391, Integration::intMiddleRect(0.0, 6000.0, 6000000.0, function($x) { return $x; }), 0.001);
|
||||
//self::assertEqualsWithDelta(12499995.000729, Integration::intMiddleRect(0.0, 5000.0, 5000000.0, function($x) { return $x; }), 0.001);
|
||||
//self::assertEqualsWithDelta(17999994.001391, Integration::intMiddleRect(0.0, 6000.0, 6000000.0, function($x) { return $x; }), 0.001);
|
||||
}
|
||||
|
||||
public function testTrapeze(): void
|
||||
{
|
||||
self::assertEqualsWithDelta(0.250025, Integration::intTrapezium(0.0, 1.0, 100.0, function($x) { return $x**3; }), 0.001);
|
||||
self::assertEqualsWithDelta(4.605986, Integration::intTrapezium(1.0, 100.0, 1000.0, function($x) { return 1 / $x; }), 0.001);
|
||||
self::assertEqualsWithDelta(12500000.0, Integration::intTrapezium(0.0, 5000.0, 5000000.0, function($x) { return $x; }), 0.001);
|
||||
self::assertEqualsWithDelta(18000000.0, Integration::intTrapezium(0.0, 6000.0, 6000000.0, function($x) { return $x; }), 0.001);
|
||||
//self::assertEqualsWithDelta(12500000.0, Integration::intTrapezium(0.0, 5000.0, 5000000.0, function($x) { return $x; }), 0.001);
|
||||
//self::assertEqualsWithDelta(18000000.0, Integration::intTrapezium(0.0, 6000.0, 6000000.0, function($x) { return $x; }), 0.001);
|
||||
}
|
||||
|
||||
public function testSimpson(): void
|
||||
{
|
||||
self::assertEqualsWithDelta(0.25, Integration::intSimpson(0.0, 1.0, 100.0, function ($x) { return $x ** 3; }), 0.001);
|
||||
self::assertEqualsWithDelta(4.605170, Integration::intSimpson(1.0, 100.0, 1000.0, function ($x) { return 1 / $x; }), 0.001);
|
||||
self::assertEqualsWithDelta(12500000.0, Integration::intSimpson(0.0, 5000.0, 5000000.0, function ($x) { return $x; }), 0.001);
|
||||
self::assertEqualsWithDelta(18000000.0, Integration::intSimpson(0.0, 6000.0, 6000000.0, function ($x) { return $x; }), 0.001);
|
||||
//self::assertEqualsWithDelta(12500000.0, Integration::intSimpson(0.0, 5000.0, 5000000.0, function ($x) { return $x; }), 0.001);
|
||||
//self::assertEqualsWithDelta(18000000.0, Integration::intSimpson(0.0, 6000.0, 6000000.0, function ($x) { return $x; }), 0.001);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class PackageManagerTest extends \PHPUnit\Framework\TestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testPackageValid() : void
|
||||
public function testPackageValidInstall() : void
|
||||
{
|
||||
$package = new PackageManager(
|
||||
__DIR__ . '/testPackage.zip',
|
||||
|
|
@ -90,6 +90,21 @@ class PackageManagerTest extends \PHPUnit\Framework\TestCase
|
|||
$package->extract(__DIR__ . '/testPackageExtracted');
|
||||
|
||||
self::assertTrue($package->isValid());
|
||||
|
||||
$package->load();
|
||||
}
|
||||
|
||||
public function testNotExtractedLoad() : void
|
||||
{
|
||||
self::expectException(\phpOMS\System\File\PathException::class);
|
||||
|
||||
$package = new PackageManager(
|
||||
__DIR__ . '/testPackage.zip',
|
||||
'/invalid',
|
||||
\file_get_contents(__DIR__ . '/public.key')
|
||||
);
|
||||
|
||||
$package->load();
|
||||
}
|
||||
|
||||
public function testPackageInvalidKey() : void
|
||||
|
|
|
|||
|
|
@ -34,6 +34,10 @@ class FileUtilsTest extends \PHPUnit\Framework\TestCase
|
|||
self::assertEquals(ExtensionType::VIDEO, FileUtils::getExtensionType('mp4'));
|
||||
self::assertEquals(ExtensionType::SPREADSHEET, FileUtils::getExtensionType('xls'));
|
||||
self::assertEquals(ExtensionType::IMAGE, FileUtils::getExtensionType('png'));
|
||||
self::assertEquals(ExtensionType::WORD, FileUtils::getExtensionType('doc'));
|
||||
self::assertEquals(ExtensionType::WORD, FileUtils::getExtensionType('docx'));
|
||||
self::assertEquals(ExtensionType::DIRECTORY, FileUtils::getExtensionType('collection'));
|
||||
self::assertEquals(ExtensionType::DIRECTORY, FileUtils::getExtensionType('/'));
|
||||
}
|
||||
|
||||
public function testAbsolute() : void
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ class StorageTest extends \PHPUnit\Framework\TestCase
|
|||
|
||||
self::assertTrue(Storage::register('ftp', '\phpOMS\System\File\Ftp\FtpStorage'));
|
||||
self::assertTrue(Storage::register('test', LocalStorage::getInstance()));
|
||||
self::assertFalse(Storage::register('test', LocalStorage::getInstance()));
|
||||
|
||||
self::assertInstanceOf('\phpOMS\System\File\Ftp\FtpStorage', Storage::env('ftp'));
|
||||
self::assertInstanceOf('\phpOMS\System\File\Local\LocalStorage', Storage::env('test'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,13 +14,18 @@
|
|||
|
||||
namespace phpOMS\tests\Utils\IO\Csv;
|
||||
|
||||
use phpOMS\Utils\IO\Csv\CsvSettings;
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class CsvSettingsTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testPlaceholder() : void
|
||||
public function testDelimiter() : void
|
||||
{
|
||||
self::markTestIncomplete();
|
||||
self::assertEquals(':', CsvSettings::getFileDelimiter(\fopen(__DIR__ . '/colon.csv', 'r')));
|
||||
self::assertEquals(',', CsvSettings::getFileDelimiter(\fopen(__DIR__ . '/comma.csv', 'r')));
|
||||
self::assertEquals('|', CsvSettings::getFileDelimiter(\fopen(__DIR__ . '/pipe.csv', 'r')));
|
||||
self::assertEquals(';', CsvSettings::getFileDelimiter(\fopen(__DIR__ . '/semicolon.csv', 'r')));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
8
tests/Utils/IO/Csv/colon.csv
Normal file
8
tests/Utils/IO/Csv/colon.csv
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
"asdf":123:1.2:"h ahsdflkwe: lekr"
|
||||
"asdf":123:1.2:"h ahsdflkwe: lekr"
|
||||
"asdf":123:1.2:"h ahsdflkwe: lekr"
|
||||
"asdf":123:1.2:"h ahsdflkwe: lekr"
|
||||
"asdf":123:1.2:"h ahsdflkwe: lekr"
|
||||
"asdf":123:1.2:"h ahsdflkwe: lekr"
|
||||
"asdf":123:1.2:"h ahsdflkwe: lekr"
|
||||
"asdf":123:1.2:"h ahsdflkwe: lekr"
|
||||
|
Can't render this file because it contains an unexpected character in line 1 and column 6.
|
8
tests/Utils/IO/Csv/comma.csv
Normal file
8
tests/Utils/IO/Csv/comma.csv
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
"asdf",123,1.2,"h ahsdflkwe, lekr"
|
||||
"asdf",123,1.2,"h ahsdflkwe, lekr"
|
||||
"asdf",123,1.2,"h ahsdflkwe, lekr"
|
||||
"asdf",123,1.2,"h ahsdflkwe, lekr"
|
||||
"asdf",123,1.2,"h ahsdflkwe, lekr"
|
||||
"asdf",123,1.2,"h ahsdflkwe, lekr"
|
||||
"asdf",123,1.2,"h ahsdflkwe, lekr"
|
||||
"asdf",123,1.2,"h ahsdflkwe, lekr"
|
||||
|
8
tests/Utils/IO/Csv/pipe.csv
Normal file
8
tests/Utils/IO/Csv/pipe.csv
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
"asdf"|123|1.2|"h ahsdflkwe| lekr"
|
||||
"asdf"|123|1.2|"h ahsdflkwe| lekr"
|
||||
"asdf"|123|1.2|"h ahsdflkwe| lekr"
|
||||
"asdf"|123|1.2|"h ahsdflkwe| lekr"
|
||||
"asdf"|123|1.2|"h ahsdflkwe| lekr"
|
||||
"asdf"|123|1.2|"h ahsdflkwe| lekr"
|
||||
"asdf"|123|1.2|"h ahsdflkwe| lekr"
|
||||
"asdf"|123|1.2|"h ahsdflkwe| lekr"
|
||||
|
8
tests/Utils/IO/Csv/semicolon.csv
Normal file
8
tests/Utils/IO/Csv/semicolon.csv
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
"asdf";123;1.2;"h ahsdflkwe; lekr"
|
||||
"asdf";123;1.2;"h ahsdflkwe; lekr"
|
||||
"asdf";123;1.2;"h ahsdflkwe; lekr"
|
||||
"asdf";123;1.2;"h ahsdflkwe; lekr"
|
||||
"asdf";123;1.2;"h ahsdflkwe; lekr"
|
||||
"asdf";123;1.2;"h ahsdflkwe; lekr"
|
||||
"asdf";123;1.2;"h ahsdflkwe; lekr"
|
||||
"asdf";123;1.2;"h ahsdflkwe; lekr"
|
||||
|
31
tests/Utils/NumericUtilsTest.php
Normal file
31
tests/Utils/NumericUtilsTest.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?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\Utils;
|
||||
|
||||
use phpOMS\Utils\NumericUtils;
|
||||
|
||||
require_once __DIR__ . '/../Autoloader.php';
|
||||
|
||||
/**
|
||||
* @internal
|
||||
*/
|
||||
class NumericUtilsTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testShift() : void
|
||||
{
|
||||
self::assertEquals(10, NumericUtils::uRightShift(10, 0));
|
||||
self::assertEquals(3858, NumericUtils::uRightShift(123456, 5));
|
||||
}
|
||||
}
|
||||
|
|
@ -22,6 +22,12 @@ use phpOMS\Validation\Base\Json;
|
|||
class JsonTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
public function testJson() : void
|
||||
{
|
||||
self::assertTrue(Json::isValid('{}'));
|
||||
self::assertFalse(Json::isValid('{'));
|
||||
}
|
||||
|
||||
public function testJsonTemplate() : void
|
||||
{
|
||||
$template = \json_decode(\file_get_contents(__DIR__ . '/json/template.json'), true);
|
||||
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ class IbanTest extends \PHPUnit\Framework\TestCase
|
|||
public function testValid() : void
|
||||
{
|
||||
self::assertTrue(Iban::isValid('DE22 6008 0000 0960 0280 00'));
|
||||
self::assertFalse(Iban::isValid('DE22 6X08 0000 0960 0280 00'));
|
||||
self::assertFalse(Iban::isValid('DE22 6008 0000 0960 0280 0'));
|
||||
self::assertFalse(Iban::isValid('QQ22 6008 0000 0960 0280 00'));
|
||||
self::assertFalse(Iban::isValid('MU22 6118 1111 1961 1281 1281 0111 23'));
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user