PHP Classes

File: Falcraft/examples/Data/Types/OrderedNode.php

Recommend this page to a friend!
  Classes of Asher Wolfstein   Abstract Data Types   Falcraft/examples/Data/Types/OrderedNode.php   Download  
File: Falcraft/examples/Data/Types/OrderedNode.php
Role: Example script
Content type: text/plain
Description: Placed Node (Graphs) Example
Class: Abstract Data Types
Set of abstract data types as pure PHP classes
Author: By
Last change:
Date: 9 years ago
Size: 10,868 bytes
 

Contents

Class file image Download
<?php require_once('../../../Data/Types/Restrictions.php'); require_once('../../../Data/Types/Type.php'); require_once('../../../Data/Types/RestrictedSet.php'); require_once('../../../Data/Types/UnorderedNode.php'); require_once('../../../Data/Types/OrderedNode.php'); use Falcraft\Data\Types; use Falcraft\Data\Types\Type; echo "Falcraft\\Data\\Types\\OrderedNode.php Test\n"; echo "----------------------------------------\n\n"; echo "Empty Instantiation -> "; $success = true; $testOrderedNode1 = null; try { $testOrderedNode1 = new Types\OrderedNode(); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success!\n"; } else { echo "Failure...\n"; } echo "Instantiating Incorrect Ordered Node (correctSet1, incorrectSet1) -> "; $failure = true; $testIncorrectRestrictions = $testIncorrectRestrictedSet = $testIncorrectOrderedNode = null; try { $testIncorrectRestrictions = new Types\Restrictions(array(Types\Type::BASIC_BOOL)); $testIncorrectRestrictedSet = Types\RestrictedSet::build(array(), $testIncorrectRestrictions); $testIncorrectOrderedNode = new Types\OrderedNode( $testCorrectRestrictedSet1, array(), $testIncorrectRestrictedSet ); $failure = false; } catch ( \InvalidArgumentException $e ) { $failure = true; } if ($failure) { echo "Failure!\n"; } else { echo "Success...\n"; } echo "Instantiating Incorrect Ordered Node (correctSet2, incorrectSet2) -> "; $failure = true; $testIncorrectRestrictions2 = $testIncorrectRestrictedSet2 = $testIncorrectOrderedNode2 = null; try { $testIncorrectRestrictions2 = new Types\Restrictions( array(Types\Type::TYPED_OBJECT ), array( 'Falcraft\Data\Types\Edge') ); $testIncorrectRestrictedSet2 = Types\RestrictedSet::build(array(), $testIncorrectRestrictions2); $testIncorrectOrderedNode2 = new Types\OrderedNode( $testCorrectRestrictedSet2, array(), $testIncorrectRestrictedSet2 ); $failure = false; } catch ( \InvalidArgumentException $e ) { $failure = true; } if ($failure) { echo "Failure!\n"; } else { echo "Success...\n"; } echo "Instantiating Correct Ordered Node -> "; $testCorrectRestrictions = $testCorrectRestrictedSet1 = null; $testCorrectRestrictedSet2 = $testCorrectOrderedNode = null; $success = true; try { $testCorrectRestrictions = new Types\Restrictions( array(Types\Type::TYPED_OBJECT), array( 'Falcraft\Data\Types\Resource\VertexInterface') ); $testCorrectRestrictedSet1 = Types\RestrictedSet::build(array(), $testCorrectRestrictions); $testCorrectRestrictedSet2 = Types\RestrictedSet::build(array(), $testCorrectRestrictions); $testCorrectOrderedNode = new Types\OrderedNode( $testCorrectRestrictedSet1, array(), $testCorrectRestrictedSet2 ); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success!\n\n"; } else { echo "Failure...\n\n"; } echo "Retrieving Restrictions -> \n\n"; var_dump($testCorrectOrderedNode->getRestrictions()); echo "\n\n"; echo "Creating Vertices -- \n"; echo "UnorderedNodes: parentNode, rightNode, middleNode, leftNode, offsideNode, auxiliaryNode\n"; $success = true; $parentNode = $rightNode = $middleNode = $leftNode = $offsideNode = $auxiliaryNode = null; try { echo " \$parentNode = new Types\\UnorderedNode(): identifier = "; $parentNode = new Types\UnorderedNode(); echo $parentNode->getIdentifier() . "\n"; echo " \$rightNode = new Types\\UnorderedNode(): identifier = "; $rightNode = new Types\UnorderedNode(); echo $rightNode->getIdentifier() . "\n"; echo " \$middleNode = new Types\\UnorderedNode(): identifier = "; $middleNode = new Types\UnorderedNode(); echo $middleNode->getIdentifier() . "\n"; echo " \$leftNode = new Types\\UnorderedNode(): identifier = "; $leftNode = new Types\UnorderedNode(); echo $leftNode->getIdentifier() . "\n"; echo " \$offsideNode = new Types\\UnorderedNode(): identifier = "; $offsideNode = new Types\UnorderedNode(); echo $offsideNode->getIdentifier() . "\n"; echo " \$auxiliaryNode = new Types\\UnorderedNode(): identifier = " ; $auxiliaryNode = new Types\UnorderedNode(); echo $auxiliaryNode->getIdentifier() . "\n"; } catch (\Exception $e) { $success = false; } if ($success) { echo "\n Success!\n\n"; } else { echo "\n Failure...\n\n"; } echo "Attaching parentNode As Parent (Incoming) [Reciprocate As Well] -> "; $success = true; try { $testCorrectOrderedNode->connectIncoming($parentNode); $parentNode->connectOutgoing($testCorrectOrderedNode); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success!\n"; } else { echo "Failure...\n"; } echo " Test Result: "; if ($parentNode->isOutgoing($testCorrectOrderedNode) && $testCorrectOrderedNode->isIncoming($parentNode)) { echo "Successful Bidirectional Link\n\n"; } else { echo "Failure To Establish Bidirectional Link\n\n"; } echo "Attaching offsideNode as Sibling (Mutual) -> "; $success = true; try { $testCorrectOrderedNode->connectMutual($offsideNode); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success!\n"; } else { echo "Failure...\n"; } echo " Test Result: "; if ($offsideNode->isConnected($testCorrectOrderedNode) && $testCorrectOrderedNode->isConnected($offsideNode)) { echo "Successful Bidirectional Link\n\n"; } else { echo "Failure to Establish Bidirectional Link\n\n"; } echo "Attaching Children: Right, Middle, Left -> "; $success = true; try { $testCorrectOrderedNode->connectOutgoing($rightNode); $rightNode->connectIncoming($testCorrectOrderedNode); $testCorrectOrderedNode->connectOutgoing($middleNode); $middleNode->connectIncoming($testCorrectOrderedNode); $testCorrectOrderedNode->connectOutgoing($leftNode); $leftNode->connectIncoming($testCorrectOrderedNode); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success!\n"; } else { echo "Failure...\n"; } echo " Test Result:\n"; if ($testCorrectOrderedNode->isConnected($rightNode) && $rightNode->isConnected($testCorrectOrderedNode)) { echo " rightNode parent-child link successful\n"; } else { echo " rightNode parent-child link unsuccessful\n"; } if ($testCorrectOrderedNode->isConnected($middleNode) && $middleNode->isConnected($testCorrectOrderedNode)) { echo " middleNode parent-child link successful\n"; } else { echo " middleNode parent-child link unsuccessful\n"; } if ($testCorrectOrderedNode->isConnected($leftNode) && $leftNode->isConnected($testCorrectOrderedNode)) { echo " leftNode parent-child link succssful\n\n"; } else { echo " leftNode parent-child link unsuccessful\n\n"; } echo "OrderedNode Specific Functionality Tests --\n"; echo " Retrieval:\n"; $retrieval = null; echo " getFirstOutgoing -> "; $success = true; try { $retrieval = $testCorrectOrderedNode->getFirstOutgoing(); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success!\n"; } else { echo "Failure...\n"; } echo " \$rightNode: " . $rightNode->getIdentifier() . " retrieved node: " . $retrieval->getIdentifier() . "\n"; echo " reference sanity check -- "; $retrieval = new Types\UnorderedNode(); echo " \$rightNode: " . $rightNode->getIdentifier() . " retrieved node: " . $retrieval->getIdentifier() . "\n"; $retrieval = null; echo " getLastOutgoing -> "; $success = true; try { $retrieval = $testCorrectOrderedNode->getLastOutgoing(); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success!\n"; } else { echo "Failure...\n"; } echo " \$leftNode: " . $leftNode->getIdentifier() . " retrieved node: " . $retrieval->getIdentifier() . "\n\n"; echo "Vertices -- \n\n"; var_dump($testCorrectOrderedNode->getOutgoingArrayIdentifiers()); echo "\nPush - "; $success = true; try { $testCorrectOrderedNode->push(new Types\UnorderedNode()); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success!\n\n"; } else { echo "Failure...\n\n"; } var_dump($testCorrectOrderedNode->getOutgoingArrayIdentifiers()); $retrieval = null; echo "\nPop - "; $success = true; try { $retrieval = $testCorrectOrderedNode->pop(); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success! Identifier: " . $retrieval->getIdentifier() . "\n\n"; } else { echo "Failure...\n\n"; } var_dump($testCorrectOrderedNode->getOutgoingArrayIdentifiers()); $retrieval = null; echo "\nShift - "; $success = true; try { $retrieval = $testCorrectOrderedNode->shift(); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success! Identifier: " . $retrieval->getIdentifier() . "\n\n"; } else { echo "Failure...\n\n"; } var_dump($testCorrectOrderedNode->getOutgoingArrayIdentifiers()); echo "Unshift -> "; $success = true; try { $testCorrectOrderedNode->unshift(new Types\UnorderedNode()); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success!\n\n"; } else { echo "Failure...\n\n"; } var_dump($testCorrectOrderedNode->getOutgoingArrayIdentifiers()); echo "insertAfter 7 -> "; $success = true; try { $testCorrectOrderedNode->insertAfter(new Types\UnorderedNode, 7); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success!\n\n"; } else { echo "Failure...\n\n"; } var_dump($testCorrectOrderedNode->getOutgoingArrayIdentifiers()); echo "insertBefore 14 -> "; $success = true; try { $testCorrectOrderedNode->insertBefore(new Types\UnorderedNode, 14); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success!\n\n"; } else { echo "Failure...\n\n"; } var_dump($testCorrectOrderedNode->getOutgoingArrayIdentifiers()); echo "delete 15 -> "; $success = true; try { $testCorrectOrderedNode->delete(15); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success!\n\n"; } else { echo "Failure...\n\n"; } var_dump($testCorrectOrderedNode->getOutgoingArrayIdentifiers()); echo "Count -> " . $testCorrectOrderedNode->count() . "\n"; echo "Is Empty? " . ($testCorrectOrderedNode->isEmpty() ? "true\n" : "false\n"); echo "Clear Outgoing -> "; $success = true; try { $testCorrectOrderedNode->clearOutgoing(); } catch (\Exception $e) { $success = false; } if ($success) { echo "Success!\n\n"; } else { echo "Failure...\n\n"; } echo "Is Empty? " . ($testCorrectOrderedNode->isEmpty() ? "true\n" : "false\n");