mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-11 06:28:40 +00:00
fix package test + graph test started
This commit is contained in:
parent
d7a86d3a49
commit
0be02d40c2
|
|
@ -280,9 +280,10 @@ final class PackageManager
|
||||||
*/
|
*/
|
||||||
private function authenticate(string $signedHash, string $rawHash) : bool
|
private function authenticate(string $signedHash, string $rawHash) : bool
|
||||||
{
|
{
|
||||||
return \sodium_crypto_sign_verify_detached($signedHash, $rawHash, $this->publicKey);
|
try {
|
||||||
//$unsignedHash = \sodium_crypto_sign_open($signedHash, $this->publicKey);
|
return \sodium_crypto_sign_verify_detached($signedHash, $rawHash, $this->publicKey);
|
||||||
|
} catch(\Throwable $t) {
|
||||||
return $unsignedHash === $rawHash;
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,38 +0,0 @@
|
||||||
<?php
|
|
||||||
/**
|
|
||||||
* Orange Management
|
|
||||||
*
|
|
||||||
* PHP Version 7.2
|
|
||||||
*
|
|
||||||
* @package TBD
|
|
||||||
* @copyright Dennis Eichhorn
|
|
||||||
* @license OMS License 1.0
|
|
||||||
* @version 1.0.0
|
|
||||||
* @link http://website.orange-management.de
|
|
||||||
*/
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace phpOMS\Stdlib\Base;
|
|
||||||
|
|
||||||
class ExactFloat
|
|
||||||
{
|
|
||||||
public static function sum($a, $b, $length = null)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function add($a, $b, $length = null)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function sub($a, $b, $length = null)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function mult($a, $b, $length = null)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public static function div($a, $b, $length = null)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -128,13 +128,13 @@ class Graph
|
||||||
*
|
*
|
||||||
* @param mixed $key Node key
|
* @param mixed $key Node key
|
||||||
*
|
*
|
||||||
* @return Node
|
* @return Node|null
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function getNode($key) : Node
|
public function getNode($key) : ?Node
|
||||||
{
|
{
|
||||||
return $this->nodes[$key];
|
return $this->nodes[$key] ?? null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -154,13 +154,25 @@ class Graph
|
||||||
*
|
*
|
||||||
* @param mixed $key Edge key
|
* @param mixed $key Edge key
|
||||||
*
|
*
|
||||||
* @return Edge
|
* @return Edge|null
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function getEdge($key) : Edge
|
public function getEdge($key) : ?Edge
|
||||||
{
|
{
|
||||||
return $this->edges[$key];
|
return $this->edges[$key] ?? null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get graph edges
|
||||||
|
*
|
||||||
|
* @return Node[]
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public function getEdges() : array
|
||||||
|
{
|
||||||
|
return $this->edges;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -193,7 +205,7 @@ class Graph
|
||||||
/**
|
/**
|
||||||
* Get all node neighbors.
|
* Get all node neighbors.
|
||||||
*
|
*
|
||||||
* @param Node $node Graph node
|
* @param mixed $node Graph node
|
||||||
*
|
*
|
||||||
* @return Node[]
|
* @return Node[]
|
||||||
*
|
*
|
||||||
|
|
@ -201,6 +213,10 @@ class Graph
|
||||||
*/
|
*/
|
||||||
public function getNeighbors($node) : array
|
public function getNeighbors($node) : array
|
||||||
{
|
{
|
||||||
|
if (!($node instanceof Node)) {
|
||||||
|
$node = $this->getNode($node);
|
||||||
|
}
|
||||||
|
|
||||||
$edges = $this->getEdgesOfNode($node);
|
$edges = $this->getEdgesOfNode($node);
|
||||||
$neighbors = [];
|
$neighbors = [];
|
||||||
|
|
||||||
|
|
@ -278,7 +294,7 @@ class Graph
|
||||||
*/
|
*/
|
||||||
public function getCircle() : array
|
public function getCircle() : array
|
||||||
{
|
{
|
||||||
// todo: implement
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -290,7 +306,7 @@ class Graph
|
||||||
*/
|
*/
|
||||||
public function getFloydWarshallShortestPath() : array
|
public function getFloydWarshallShortestPath() : array
|
||||||
{
|
{
|
||||||
// todo: implement
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -302,7 +318,7 @@ class Graph
|
||||||
*/
|
*/
|
||||||
public function getDijkstraShortestPath() : array
|
public function getDijkstraShortestPath() : array
|
||||||
{
|
{
|
||||||
// todo: implement
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -314,7 +330,7 @@ class Graph
|
||||||
*/
|
*/
|
||||||
public function depthFirstTraversal() : array
|
public function depthFirstTraversal() : array
|
||||||
{
|
{
|
||||||
// todo: implement
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -326,7 +342,7 @@ class Graph
|
||||||
*/
|
*/
|
||||||
public function breadthFirstTraversal() : array
|
public function breadthFirstTraversal() : array
|
||||||
{
|
{
|
||||||
// todo: implement
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -338,22 +354,30 @@ class Graph
|
||||||
*/
|
*/
|
||||||
public function longestPath() : array
|
public function longestPath() : array
|
||||||
{
|
{
|
||||||
// todo: implement
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get longest path between two nodes.
|
* Get longest path between two nodes.
|
||||||
*
|
*
|
||||||
* @param Node $node1 Graph node
|
* @param mixed $node1 Graph node
|
||||||
* @param Node $node2 Graph node
|
* @param mixed $node2 Graph node
|
||||||
*
|
*
|
||||||
* @return Node[]
|
* @return Node[]
|
||||||
*
|
*
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
public function longestPathBetweenNodes(Node $node1, Node $node2) : array
|
public function longestPathBetweenNodes($node1, $node2) : array
|
||||||
{
|
{
|
||||||
// todo: implement
|
if (!($node1 instanceof Node)) {
|
||||||
|
$node1 = $this->getNode($node1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!($node2 instanceof Node)) {
|
||||||
|
$node2 = $this->getNode($node2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -414,22 +438,22 @@ class Graph
|
||||||
|
|
||||||
public function getGirth() : int
|
public function getGirth() : int
|
||||||
{
|
{
|
||||||
// todo: implement
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCircuitRank() : int
|
public function getCircuitRank() : int
|
||||||
{
|
{
|
||||||
// todo: implement
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getNodeConnectivity() : int
|
public function getNodeConnectivity() : int
|
||||||
{
|
{
|
||||||
// todo: implement
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getEdgeConnectivity() : int
|
public function getEdgeConnectivity() : int
|
||||||
{
|
{
|
||||||
// todo: implement
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isConnected() : bool
|
public function isConnected() : bool
|
||||||
|
|
@ -442,6 +466,8 @@ class Graph
|
||||||
{
|
{
|
||||||
// todo: implement
|
// todo: implement
|
||||||
// get all unconnected sub graphs
|
// get all unconnected sub graphs
|
||||||
|
|
||||||
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function isBipartite() : bool
|
public function isBipartite() : bool
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,8 @@ class PackageManagerTest extends \PHPUnit\Framework\TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_exists(__DIR__ . '/testPackageExtracted')) {
|
if (file_exists(__DIR__ . '/testPackageExtracted')) {
|
||||||
|
\array_map('unlink', \glob(__DIR__ . '/testPackageExtracted/testSubPackage/*'));
|
||||||
|
\rmdir(__DIR__ . '/testPackageExtracted/testSubPackage');
|
||||||
\array_map('unlink', \glob(__DIR__ . '/testPackageExtracted/*'));
|
\array_map('unlink', \glob(__DIR__ . '/testPackageExtracted/*'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -89,6 +91,33 @@ class PackageManagerTest extends \PHPUnit\Framework\TestCase
|
||||||
self::assertTrue($package->isValid());
|
self::assertTrue($package->isValid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testPackageInvalidKey()
|
||||||
|
{
|
||||||
|
$package = new PackageManager(
|
||||||
|
__DIR__ . '/testPackage.zip',
|
||||||
|
'/invalid',
|
||||||
|
\file_get_contents(__DIR__ . '/public.key') . ' '
|
||||||
|
);
|
||||||
|
|
||||||
|
$package->extract(__DIR__ . '/testPackageExtracted');
|
||||||
|
|
||||||
|
self::assertFalse($package->isValid());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testPackageInvalidContent()
|
||||||
|
{
|
||||||
|
$package = new PackageManager(
|
||||||
|
__DIR__ . '/testPackage.zip',
|
||||||
|
'/invalid',
|
||||||
|
\file_get_contents(__DIR__ . '/public.key')
|
||||||
|
);
|
||||||
|
|
||||||
|
$package->extract(__DIR__ . '/testPackageExtracted');
|
||||||
|
\file_put_contents(__DIR__ . '/testPackageExtracted/info.json', ' ', FILE_APPEND);
|
||||||
|
|
||||||
|
self::assertFalse($package->isValid());
|
||||||
|
}
|
||||||
|
|
||||||
public function testCleanup()
|
public function testCleanup()
|
||||||
{
|
{
|
||||||
$package = new PackageManager(
|
$package = new PackageManager(
|
||||||
|
|
@ -111,6 +140,8 @@ class PackageManagerTest extends \PHPUnit\Framework\TestCase
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_exists(__DIR__ . '/testPackageExtracted')) {
|
if (file_exists(__DIR__ . '/testPackageExtracted')) {
|
||||||
|
\array_map('unlink', \glob(__DIR__ . '/testPackageExtracted/testSubPackage/*'));
|
||||||
|
\rmdir(__DIR__ . '/testPackageExtracted/testSubPackage');
|
||||||
\array_map('unlink', \glob(__DIR__ . '/testPackageExtracted/*'));
|
\array_map('unlink', \glob(__DIR__ . '/testPackageExtracted/*'));
|
||||||
\rmdir(__DIR__ . '/testPackageExtracted');
|
\rmdir(__DIR__ . '/testPackageExtracted');
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,8 +17,41 @@ use phpOMS\Stdlib\Graph\Graph;
|
||||||
|
|
||||||
class GraphTest extends \PHPUnit\Framework\TestCase
|
class GraphTest extends \PHPUnit\Framework\TestCase
|
||||||
{
|
{
|
||||||
public function testPlaceholder()
|
public function testDefault()
|
||||||
{
|
{
|
||||||
self::markTestIncomplete();
|
$graph = new Graph();
|
||||||
|
|
||||||
|
self::assertEquals(null, $graph->getNode('invalid'));
|
||||||
|
self::assertEquals([], $graph->getNodes());
|
||||||
|
|
||||||
|
self::assertEquals(null, $graph->getEdge('invalid'));
|
||||||
|
self::assertEquals([], $graph->getEdges());
|
||||||
|
|
||||||
|
self::assertEquals([], $graph->getEdgesOfNode('invalid'));
|
||||||
|
self::assertEquals([], $graph->getNeighbors('invalid'));
|
||||||
|
|
||||||
|
self::assertEquals(0, $graph->getDimension());
|
||||||
|
self::assertEquals(0, $graph->getDiameter());
|
||||||
|
self::assertEquals(0, $graph->getOrder());
|
||||||
|
self::assertEquals(0, $graph->getSize());
|
||||||
|
self::assertEquals(0, $graph->getGirth());
|
||||||
|
self::assertEquals(0, $graph->getCircuitRank());
|
||||||
|
self::assertEquals(0, $graph->getNodeConnectivity());
|
||||||
|
self::assertEquals(0, $graph->getEdgeConnectivity());
|
||||||
|
|
||||||
|
self::assertTrue($graph->isConnected());
|
||||||
|
self::assertTrue($graph->isBipartite());
|
||||||
|
self::assertTrue($graph->isTriangleFree());
|
||||||
|
self::assertTrue($graph->isCircleFree());
|
||||||
|
|
||||||
|
self::assertEquals([], $graph->getBridges());
|
||||||
|
self::assertEquals([], $graph->getCircle());
|
||||||
|
self::assertEquals([], $graph->getFloydWarshallShortestPath());
|
||||||
|
self::assertEquals([], $graph->getDijkstraShortestPath());
|
||||||
|
self::assertEquals([], $graph->depthFirstTraversal());
|
||||||
|
self::assertEquals([], $graph->breadthFirstTraversal());
|
||||||
|
self::assertEquals([], $graph->longestPath());
|
||||||
|
self::assertEquals([], $graph->longestPathBetweenNodes('invalid1', 'invalid2'));
|
||||||
|
self::assertEquals([], $graph->getUnconnected());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user