<?php
require_once('../../../Data/Types/Resource/VertexInterface.php');
require_once('../../../Data/Types/UnorderedNode.php');
require_once('../../../Data/Types/VertexList.php');
use Falcraft\Data\Types;
use Falcraft\Data\Types\Resource as TypesResource;
echo "Falcraft\\Data\\Types\\VertexList.php Test\n";
echo "---------------------------------------\n\n";
echo "\nInstantistion -- \n\n";
echo "Empty Instantiation -> ";
$success = true;
$testVertexList = null;
try {
$testVertexList = new Types\VertexList();
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success! List Empty? ";
if (empty($testVertexList->getVerticesAsArray())) {
echo "Yes!\n";
} else {
echo "No...\n";
}
} else {
echo "Failure...\n";
}
function listVertices() {
global $testVertexList;
foreach($testVertexList->getVerticesAsArray() as $vertex) {
echo $vertex->getIdentifier() . " ";
}
if (empty($testVertexList->getVerticesAsArray())) {
echo "EMPTY!";
}
}
echo "Single Node Instantiation -> ";
$success = true;
$testVertexList = null;
try {
$testVertexList = new Types\VertexList(array(new Types\UnorderedNode()));
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success! Vertices: ";
listVertices();
echo "\n";
} else {
echo "Failure...\n";
}
echo "Three Node Instantiation -> ";
$success = true;
$testVertexList = null;
try {
$testVertexList = new Types\VertexList(array(
new Types\UnorderedNode(),
new Types\UnorderedNode(),
new Types\UnorderedNode(),));
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success! Vertices: ";
foreach($testVertexList->getVerticesAsArray() as $vertex) {
echo $vertex->getIdentifier() . " ";
}
echo "\n";
} else {
echo "Failure...\n";
}
echo "Six Node Instantiation -> ";
$success = true;
$testVertexList = null;
try {
$testVertexList = new Types\VertexList(array(
new Types\UnorderedNode(),
new Types\UnorderedNode(),
new Types\UnorderedNode(),
new Types\UnorderedNode(),
new Types\UnorderedNode(),
new Types\UnorderedNode(),));
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success! Vertices: ";
foreach($testVertexList->getVerticesAsArray() as $vertex) {
echo $vertex->getIdentifier() . " ";
}
echo "\n";
} else {
echo "Failure...\n";
}
echo "\nFunctions and Operations -- \n\n";
echo " Test getVertices (as RestrictedSet) -> ";
try {
listVertices();
echo "\n";
} catch (\Exception $e) {
echo "EXCEPTION CAUGHT\n";
}
echo "\nPush -- vertexList push (notReferenceNode, new UnorderedNode) -> ";
$success = true;
$notReferenceNode = null;
try {
$notReferenceNode = new Types\UnorderedNode();
$testVertexList->push($notReferenceNode, new Types\UnorderedNode());
$notReferenceNode = new Types\UnorderedNode();
echo "\n [notReferenceNode id=" . $notReferenceNode->getIdentifier() . "]: ";
listVertices();
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo "\nPush Reference -- vertexList (referenceNode) -> ";
$success = true;
$referenceNode = null;
try {
$referenceNode = new Types\UnorderedNode();
echo "\n [referenceNode id=" . $referenceNode->getIdentifier() . "] - \n";
$testVertexList->pushReference($referenceNode);
echo " "; listVertices(); echo "\n";
$referenceNode = new Types\UnorderedNode();
echo " [referenceNode id=" . $referenceNode->getIdentifier() . "]: \n";
echo " ";
listVertices();
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo "\nResetting testVertexList...\n\n";
unset($testVertexList);
echo "Instantiating and Pushing Three New Nodes -> ";
$success = true;
$testVertexList = null;
try {
$testVertexList = new Types\VertexList();
$testVertexList->push(new Types\UnorderedNode());
echo "\n";
listVertices();
echo "\n";
$testVertexList->push(new Types\UnorderedNode());
listVertices();
echo "\n";
$testVertexList->push(new Types\UnorderedNode());
listVertices();
echo "\n";
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo "Pop -- vertexList pop -> \n";
echo " (testVertexList not reset)\n";
echo " POP!\n";
$success = true;
$v = null;
try {
$v = $testVertexList->pop();
echo " popped value class: ";
echo get_class($v);
echo " popped value identifier: ";
echo $v->getIdentifier();
echo "\n vertexList: ";
listVertices();
echo " ";
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo " POP!\n";
$success = true;
$v = null;
try {
$v = $testVertexList->pop();
echo " popped value class: ";
echo get_class($v);
echo " popped value identifier: ";
echo $v->getIdentifier();
echo "\n vertexList: ";
listVertices();
echo " ";
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo " POP!\n";
$success = true;
$v = null;
try {
$v = $testVertexList->pop();
echo " popped value class: ";
echo get_class($v);
echo " popped value identifier: ";
echo $v->getIdentifier();
echo "\n vertexList: ";
listVertices();
echo " ";
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo " POP!\n";
$fail = true;
$v = null;
try {
$v = $testVertexList->pop();
if ($v) {
echo " popped value class: ";
echo get_class($v);
echo " popped value identifier: ";
echo $v->getIdentifier();
echo "\n vertexList: ";
listVertices();
echo " ";
} else {
echo " NULL VALUE\n";
}
$fail = false;
} catch (\Exception $e) {
}
if ($fail) {
echo "Failure!!\n";
} else {
echo "Success...\n";
}
echo " List Empty? ";
if (empty($testVertexList->getVerticesAsArray())) {
echo "Yes!\n\n";
} else {
echo "No...\n\n";
}
echo "Unshift -- vertexList unshift -> \n";
echo " (testVertexList not reset)\n";
echo " UNSHIFT!\n";
$success = true;
try {
$notReferenceNode = new Types\UnorderedNode();
echo " [preshift notReferenceNode id=" . $notReferenceNode->getIdentifier() . "]\n";
$testVertexList->unshift($notReferenceNode, new Types\UnorderedNode());
$notReferenceNode = new Types\UnorderedNode();
echo " [postshift notReferenceNode id=" . $notReferenceNode->getIdentifier() . "]\n";
echo " Vertices: ";
listVertices();
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo " UNSHIFT REFERENCE!\n";
$success = true;
unset($referenceNode);
$referenceNode = null;
try {
$referenceNode = new Types\UnorderedNode();
echo " [preshift referenceNode id=" . $referenceNode->getIdentifier() . "]\n";
$testVertexList->unshiftReference($referenceNode);
$referenceNode = new Types\UnorderedNode();
echo " [postshift referenceNode id=" . $referenceNode->getIdentifier() . "]\n";
echo " Vertices: ";
listVertices();
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo "\nResetting testVertexList...\n\n";
$success = true;
try {
unset($testVertexList);
$testVertexList = new Types\VertexList();
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo "Unshift -- vertexList unshift -> \n";
echo " UNSHIFT!\n";
$success = true;
try {
$testVertexList->unshift(new Types\UnorderedNode());
echo " Vertices: ";
listVertices();
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo " UNSHIFT!\n";
$success = true;
try {
$testVertexList->unshift(new Types\UnorderedNode());
echo " Vertices: ";
listVertices();
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo " UNSHIFT!\n";
$success = true;
try {
$testVertexList->unshift(new Types\UnorderedNode());
echo " Vertices: ";
listVertices();
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo "Shift -- vertexList shift -> \n";
echo " (testVertexList not reset)\n";
echo " SHIFT!\n";
$success = true;
$v = null;
try {
$v = $testVertexList->shift();
echo " shifted value class: ";
echo get_class($v);
echo " shifted value identifier: ";
echo $v->getIdentifier();
echo "\n vertexList: ";
listVertices();
echo " ";
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo " SHIFT!\n";
$success = true;
$v = null;
try {
$v = $testVertexList->shift();
echo " shifted value class: ";
echo get_class($v);
echo " shifted value identifier: ";
echo $v->getIdentifier();
echo "\n vertexList: ";
listVertices();
echo " ";
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo " SHIFT!\n";
$fail = true;
$v = null;
try {
$v = $testVertexList->shift();
echo " shifted value class: ";
echo get_class($v);
echo " shifted value identifier: ";
echo $v->getIdentifier();
echo "\n vertexList: ";
listVertices();
echo " ";
$fail = false;
} catch (\Exception $e) {
}
if ($fail) {
echo "Failure!\n";
} else {
echo "Success...\n";
}
echo " List Empty? ";
if (empty($testVertexList->getVerticesAsArray())) {
echo "Yes!\n\n";
} else {
echo "No...\n\n";
}
echo "Top, Bottom on Empty List -- \n";
echo " (listVertex not reset)\n";
echo " Top -> ";
$fail = true;
$v = null;
try {
$v = $testVertexList->top();
if ($v) {
$fail = false;
}
} catch (\Exception $e) {
}
if ($fail) {
echo "Failure!\n";
} else {
echo "Success...\n";
}
echo " Bottom -> ";
$fail = true;
$v = null;
try {
$v = $testVertexList->bottom();
if ($v) {
$fail = false;
}
} catch (\Exception $e) {
$success = false;
}
if ($fail) {
echo "Failure!\n";
} else {
echo "Success...\n";
}
echo "Top and Bottom on Three Vertex List -- \n";
echo " populating vertexList (new) -> ";
$success = true;
unset($testVertexList);
try {
$testVertexList = new Types\VertexList(array(
new Types\UnorderedNode(),
new Types\UnorderedNode(),
new Types\UnorderedNode(),));
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo " Top -> ";
$success = true;
$v = null;
try {
$v = $testVertexList->top();
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo " Bottom -> ";
$success = true;
$v = null;
try {
$v = $testVertexList->bottom();
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo "\nVertexList Current State -> ";
listVertices();
echo "\n\n";
echo "Clear List -> ";
$success = true;
try {
$testVertexList->clear();
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success! List Empty? ";
if (empty($testVertexList->getVerticesAsArray())) {
echo "Yes!\n";
} else {
echo "No...\n";
}
} else {
echo "Failure...\n";
}
echo "insertAfter Operation -- \n";
echo " (vertexList not reset)\n";
echo " INSERTAFTER!\n";
$fail = true;
$testNode = null;
$success = false;
try {
$testNode = new Types\UnorderedNode();
$success = $testVertexList->insertAfter($testNode, 0);
$fail = false;
} catch (\Exception $e) {
}
if ($success) {
echo " InsertAfter returned true, Fail = " .
($fail ? "True" : "False") . "\n";
} else {
echo " InsertAfter returned false, Fail = " .
($fail ? "True" : "False") . "\n";
}
echo " Populating VertexList with One Node -> ";
$success = true;
unset($testVertexList);
try {
$testVertexList = new Types\VertexList(array(new Types\UnorderedNode()));
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success! Vertices: ";
listVertices();
echo "\n";
} else {
echo "Failure...\n";
}
echo " INSERTAFTER (improper identifier) [42]!\n";
$fail = true;
$testNode = null;
$success = false;
try {
$testNode = new Types\UnorderedNode();
$success = $testVertexList->insertAfter($testNode, 42);
$fail = false;
} catch (\Exception $e) {
}
if ($success) {
echo " InsertAfter returned true, Fail = " .
($fail ? "True" : "False") . "\n";
} else {
echo " InsertAfter returned false, Fail = " .
($fail ? "True" : "False") . "\n";
}
$id = $testVertexList->top()->getIdentifier();
echo " INSERTAFTER (proper) [$id] {Top Node}\n";
$fail = true;
$testNode = null;
$success = false;
try {
$testNode = new Types\UnorderedNode();
$success = $testVertexList->insertAfter($testNode, $id);
$fail = false;
} catch (\Exception $e) {
}
if ($success) {
echo " InsertAfter returned true, Fail = " .
($fail ? "True" : "False") . "\n";
} else {
echo " InsertAfter returned false, Fail = " .
($fail ? "True" : "False") . "\n";
}
echo " Vertices: ";
listVertices();
echo "\n";
echo " insertAfter Uses References: \n";
try {
$testNode = new Types\UnorderedNode();
echo " [testNode identifier=" . $testNode->getIdentifier() . "]\n";
echo " Vertices: ";
listVertices();
echo "\n";
} catch (\Exception $e) {
echo "EXCEPTION CAUGHT\n";
}
echo " insertAfter Top Creating New OrderedEdge -- \n";
$success = false;
$fail = true;
$id = null;
unset($testNode); // Reference As Demonstrated
try {
$id = $testVertexList->top()->getIdentifier();
$testNode = new Types\UnorderedNode();
echo " [testNode identifier=" . $testNode->getIdentifier() . "]\n";
$success = $testVertexList->insertAfter($testNode, $id);
$fail = false;
} catch (\Exception $e) {
}
if ($success) {
echo " Success! Vertices: ";
listVertices();
echo "\n";
echo " InsertAfter returned true, Fail = " .
($fail ? "True" : "False") . "\n";
} else {
echo " InsertAfter returned false, Fail = " .
($fail ? "True" : "False") . "\n";
}
$array = $testVertexList->getVerticesAsArray();
$id = $array[1]->getIdentifier();
echo " insertAfter First Item [1], Pushing Other Items Over -- \n";
$success = false;
$fail = true;
unset($testNode);
$testNode = null;
try {
$testNode = new Types\UnorderedNode();
echo " [testNode identifier=" . $testNode->getIdentifier() . "], id=$id\n";
$success = $testVertexList->insertAfter($testNode, $id);
$fail = false;
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo " Success! Vertices: ";
listVertices();
echo "\n";
echo " InsertAfter returned true, Fail = " .
($fail ? "True" : "False") . "\n";
} else {
echo " InsertAfter returned false, Fail = " .
($fail ? "True" : "False") . "\n";
}
$array = $testVertexList->getVerticesAsArray();
$id = $array[2]->getIdentifier();
echo " insertAfter Second Item [2], Pushing Other Items Over -- \n";
$success = true;
$fail = true;
unset($testNode);
$testNode = null;
try {
$testNode = new Types\UnorderedNode();
echo " [testNode identifier=" . $testNode->getIdentifier() . "] id=$id\n";
$success = $testVertexList->insertAfter($testNode, $id);
$fail = false;
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo " Success! Vertices: ";
listVertices();
echo "\n";
echo " InsertAfter returned true, Fail = " .
($fail ? "True" : "False") . "\n";
} else {
echo " InsertAfter returned false, Fail = " .
($fail ? "True" : "False") . "\n";
}
echo " Resetting / Populating VertexList with Two Nodes -> ";
$success = true;
unset($testVertexList);
$testVertexList = null;
try {
$testVertexList = new Types\VertexList(array(
new Types\UnorderedNode(),
new Types\UnorderedNode,));
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success! Vertices: ";
listVertices();
echo "\n";
} else {
echo "Failure...\n";
}
echo " insertAfter end of List Twice -- \n";
echo " INSERTAFTER (top) -> ";
$success = false;
$fail = true;
$id = null;
try {
$id = $testVertexList->top()->getIdentifier();
$success = $testVertexList->insertAfter(new Types\UnorderedNode, $id);
$fail = false;
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo " Success! Vertices: ";
listVertices();
echo "\n";
echo " InsertAfter returned true, Fail = " .
($fail ? "True" : "False") . "\n";
} else {
echo " InsertAfter returned false, Fail = " .
($fail ? "True" : "False") . "\n";
}
echo " INSERTAFTER (top) -> ";
$success = false;
$fail = true;
$id = null;
try {
$id = $testVertexList->top()->getIdentifier();
$success = $testVertexList->insertAfter(new Types\UnorderedNode, $id);
$fail = false;
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo " Success! Vertices: ";
listVertices();
echo "\n";
echo " InsertAfter returned true, Fail = " .
($fail ? "True" : "False") . "\n";
} else {
echo " InsertAfter returned false, Fail = " .
($fail ? "True" : "False") . "\n";
}
echo "\ninsertBefore Operation -- \n";
echo " Reset testVertexList to empty -> ";
$success = true;
try {
unset($testVertexList);
$testVertexList = new Types\VertexList();
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success! Vertices: ";
listVertices();
echo "\n";
} else {
echo "Failure...\n";
}
echo " insertBefore on empty list -> \n";
echo " INSERTBEFORE\n";
$success = false;
$fail = true;
$testNode = null;
try {
$testNode = new Types\UnorderedNode();
$success = $testVertexList->insertBefore($testNode, 0);
$fail = false;
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo " Success! Vertices: ";
listVertices();
echo "\n";
echo " InsertBefore returned true, Fail = " .
($fail ? "True" : "False") . "\n";
} else {
echo " InsertBefore returned false, Fail = " .
($fail ? "True" : "False") . "\n";
}
echo " Populating testVertexList with One Node -> ";
$success = true;
unset($testVertexList);
try {
$testVertexList = new Types\VertexList(array(new Types\UnorderedNode(),));
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success! Vertices: ";
listVertices();
echo "\n";
} else {
echo "Failure...\n";
}
echo " INSERTBEFORE\n";
echo " With improper identiifer [128] -> \n";
$success = false;
$fail = true;
try {
$success = $testVertexList->insertBefore(new Types\UnorderedNode(), 128);
$fail = false;
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo " Success! Vertices: ";
listVertices();
echo "\n";
echo " InsertBefore returned true, Fail = " .
($fail ? "True" : "False") . "\n";
} else {
echo " InsertBefore returned false, Fail = " .
($fail ? "True" : "False") . "\n";
}
echo " INSERTBEFORE\n";
$id = $testVertexList->bottom()->getIdentifier();
echo " Before Bottom Node [$id] -> ";
$success = false;
$fail = true;
try {
$success = $testVertexList->insertBefore(new Types\UnorderedNode(), $id);
$fail = false;
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo " Success! Vertices: ";
listVertices();
echo "\n";
echo " InsertBefore returned true, Fail = " .
($fail ? "True" : "False") . "\n";
} else {
echo " InsertBefore returned false, Fail = " .
($fail ? "True" : "False") . "\n";
}
echo " INSERTBEFORE\n";
$id = $testVertexList->bottom()->getIdentifier();
echo " insertAfter Bottom Creating New OrderedEdge [$id]\n";
$success = false;
$fail = true;
unset($testNode);
try {
$testNode = new Types\UnorderedNode();
$success = $testVertexList->insertBefore($testNode, $id);
$fail = false;
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo " Success! Vertices: ";
listVertices();
echo "\n";
echo " InsertBefore returned true, Fail = " .
($fail ? "True" : "False") . "\n";
} else {
echo " InsertBefore returned false, Fail = " .
($fail ? "True" : "False") . "\n";
}
echo " INSERTBEFORE\n";
$id = $testVertexList->bottom()->getIdentifier();
echo " insertBefore First Item, Pushing Other Items Over [$id] -> \n";
$success = false;
$fail = true;
try {
$success = $testVertexList->insertBefore(new Types\UnorderedNode(), $id);
$fail = false;
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo " Success! Vertices: ";
listVertices();
echo "\n";
echo " InsertBefore returned true, Fail = " .
($fail ? "True" : "False") . "\n";
} else {
echo " InsertBefore returned false, Fail = " .
($fail ? "True" : "False") . "\n";
}
echo " INSERTBEFORE\n";
$array = $testVertexList->getVerticesAsArray();
$id = $array[3]->getIdentifier();
echo " insertBefore Third Item [$id] -> \n";
$success = false;
$fail = true;
try {
$success = $testVertexList->insertBefore(new Types\UnorderedNode(), $id);
$fail = false;
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo " Success! Vertices: ";
listVertices();
echo "\n";
echo " InsertBefore returned true, Fail = " .
($fail ? "True" : "False") . "\n";
} else {
echo " InsertBefore returned false, Fail = " .
($fail ? "True" : "False") . "\n";
}
echo " Reset testVertexList to empty -> ";
$success = true;
try {
unset($testVertexList);
$testVertexList = new Types\VertexList();
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success! Vertices: ";
listVertices();
echo "\n";
} else {
echo "Failure...\n";
}
echo " Populating testVertexList with Two Nodes -> ";
$success = true;
unset($testVertexList);
try {
$testVertexList = new Types\VertexList(array(
new Types\UnorderedNode(),
new Types\UnorderedNode(),));
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success! Vertices: ";
listVertices();
echo "\n";
} else {
echo "Failure...\n";
}
echo " INSERTBEFORE\n";
$id = $testVertexList->top()->getIdentifier();
echo " insertBefore Beginning of List Twice [$id] -> \n";
$success = false;
$fail = true;
try {
$success = $testVertexList->insertBefore(new Types\UnorderedNode(), $id);
$fail = false;
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo " Success! Vertices: ";
listVertices();
echo "\n";
echo " InsertBefore returned true, Fail = " .
($fail ? "True" : "False") . "\n";
} else {
echo " InsertBefore returned false, Fail = " .
($fail ? "True" : "False") . "\n";
}
$id = $testVertexList->top()->getIdentifier();
$success = false;
$fail = true;
try {
$success = $testVertexList->insertBefore(new Types\UnorderedNode(), $id);
$fail = false;
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo " Success! Vertices: ";
listVertices();
echo "\n";
echo " InsertBefore returned true, Fail = " .
($fail ? "True" : "False") . "\n";
} else {
echo " InsertBefore returned false, Fail = " .
($fail ? "True" : "False") . "\n";
}
echo "\nClear Operation -> ";
$success = true;
try {
$testVertexList->clear();
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success! Vertices: ";
listVertices();
echo "\n";
} else {
echo "Failure...\n";
}
echo "push testNode ref, use testNode ref to Delete -> \n";
$success = true;
unset($testNode);
try {
$testNode = new Types\UnorderedNode();
$testVertexList->pushReference($testNode);
echo " PUSHREFERENCE: ";
listVertices();
echo "\n";
$testVertexList->deleteVertex($testNode);
echo " DELETE: ";
if (empty($testVertexList->getVerticesAsArray())) {
echo "Yes!\n";
} else {
echo "No...\n";
}
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success! Vertices: ";
listVertices();
echo "\n";
} else {
echo "Failure...\n";
}
echo "push testNode clone, use tesdNode clone to delete -> \n";
unset($testNode);
try {
$testNode = new Types\UnorderedNode();
$testVertexList->push($testNode);
echo " PUSH: ";
listVertices();
echo "\n";
$testVertexList->deleteVertex($testNode);
echo " DELETE: ";
if (empty($testVertexList->getVerticesAsArray())) {
echo "Yes!\n";
} else {
echo "No...\n";
}
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success! Vertices: ";
listVertices();
echo "\n";
} else {
echo "Failure...\n";
}
echo "\nPopulate testVertexList with array values -> ";
$success = true;
unset($testNodes);
try {
$testNodes = array(new Types\UnorderedNode(),
new Types\UnorderedNode(),
new Types\UnorderedNode(),
new Types\UnorderedNode(),
new Types\UnorderedNode(),
new Types\UnorderedNode(),);
unset($testVertexList);
$testVertexList = new Types\VertexList(array(
$testNodes[0],
$testNodes[1],
$testNodes[2],
$testNodes[3],
$testNodes[4],
$testNodes[5],));
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo "array list matching -- \n";
echo " Delete From Beginning of List -> ";
$success = true;
try {
$testVertexList->deleteVertex($testNodes[0]);
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success! Vertices: ";
listVertices();
echo "\n";
} else {
echo "Failure...\n";
}
echo " Delete From End of List -> ";
$success = true;
try {
$testVertexList->deleteVertex($testNodes[5]);
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success! Vertices: ";
listVertices();
echo "\n";
} else {
echo "Failure...\n";
}
$success = true;
echo " Delete From Middle of List -> ";
try {
$testVertexList->deleteVertex($testNodes[2]);
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success! Vertices: ";
listVertices();
echo "\n";
} else {
echo "Failure...\n";
}
echo "\nfindIdentifiedVertex Testing -- \n";
echo " NOTE: findIdentifiedVertex returns reference\n";
echo " Current Vertex List: ";
listVertices();
echo "\n";
echo " Retrieve Vertex 58 -> ";
$success = true;
$retrievedVertex = null;
try {
$retrievedVertex =& $testVertexList->findIdentifiedVertex(58);
echo $retrievedVertex->getIdentifier() . " ";
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo " Test Reference (58 to 61) -> ";
$success = true;
try {
$retrievedVertex = new Types\UnorderedNode();
echo "Vertices: ";
listVertices();
echo "\n";
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo " Retrieve First Iem (56) -> ";
$success = true;
unset($retrievedVertex);
$retrievedVertex = null;
try {
$retrievedVertex = $testVertexList->findIdentifiedVertex(56);
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success! -> ";
echo $retrievedVertex->getIdentifier();
echo "\n";
} else {
echo "Failure...\n";
}
echo " Retrieve Last Item (59) -> ";
$success = true;
unset($retrievedVertex);
$retrievedVertex = null;
try {
$retrievedVertex = $testVertexList->findIdentifiedVertex(59);
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success! -> ";
echo $retrievedVertex->getIdentifier();
echo "\n";
} else {
echo "Failure...\n";
}
echo "Delete By Identifier Testing -- \n";
echo " vertexList Identifier 58 -> \n";
$success = false;
$fail = true;
try {
$success = $testVertexList->delete(58);
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo " ->delete return true, fail: " .
( $fail ? "true" : "false" ) . "\n";
} else {
echo " ->delete return false, fail: " .
( $fail ? "true" : "false" ) . "\n";
}
echo " vertexList Identifier 56 -> ";
$success = true;
try {
$testVertexList->delete(56);
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo " vertexList Identifier 59 -> ";
$success = true;
try {
$testVertexList->delete(59);
} catch (\Exception $e) {
$success = false;
}
if ($success) {
echo "Success!\n";
} else {
echo "Failure...\n";
}
echo "Vertices: ";
listVertices();
echo "\n\n";
|