PHP Classes
elePHPant
Icontem

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

Recommend this page to a friend!
  Classes of Asher Wolfstein  >  Abstract Data Types  >  Falcraft/examples/Data/Types/RestrictedQueue.php  >  Download  
File: Falcraft/examples/Data/Types/RestrictedQueue.php
Role: Example script
Content type: text/plain
Description: Queue Example
Class: Abstract Data Types
Set of abstract data types as pure PHP classes
Author: By
Last change:
Date: 3 years ago
Size: 7,517 bytes
 

Contents

Class file image Download
<?php

require_once('../../../Data/Types/Type.php');
require_once(
'../../../Data/Types/Restrictions.php');
require_once(
'../../../Data/Types/RestrictedQueue.php');

use
Falcraft\Data\Types;
use
Falcraft\Data\Types\Type;

echo
"Falcraft\\Data\\Types\\RestrictedQueue.php Test\n";
echo
"--------------------------------------------\n\n";

echo
"Various Instantiations -> \n";
echo
" \$testRestrictions = new Types\\Restrictions(array(Type::BASIC_INT)) -> ";

$success = true;

$testRestrictions = null;

try {
   
$testRestrictions = new Types\Restrictions(array(Type::BASIC_INT));
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n";
} else {
    echo
"Failure...\n";
}

echo
" \$testRestrictedQueue = new Types\\RestrictedQueue() -> ";

$success = true;

$testRestrictedQueue = null;

try {
   
$testRestrictedQueue = new Types\RestrictedQueue();
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n";
} else {
    echo
"Failure...\n";
}

echo
" \$testRestrictedQueue = new Types\\RestrictedQueue(null, null, array('strict' => true)) -> ";

$success = true;

$testRestrictedQueue = null;

try {
   
$testRestrictedQueue = new Types\RestrictedQueue(null, null, array('strict' => true));
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n";
} else {
    echo
"Failure...\n";
}

echo
" \$testRestrictedQueue = new Types\\RestrictedQueue(
                null,
                new Types\Restrictions(array(Type::BASIC_INT)),
                array('strict' => true)) -> "
;

$success = true;

$testRestrictedQueue = null;

try {
   
$testRestrictedQueue = new Types\RestrictedQueue(
       
null,
        new
Types\Restrictions(array(Type::BASIC_INT)),
        array(
'strict' => true));
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n";
} else {
    echo
"Failure...\n";
}

echo
" \$testRestrictedQueue = new Types\RestrictedQueue(
                array(1, 2, 3, 'string',),
                \$testRestrictions) -> "
;
               
$fail = true;

$testRestrictedQueue = null;

try {
   
$testRestrictedQueue = new Types\RestrictedQueue(
        array(
1, 2, 3, 'string',),
       
$testRestrictions);
   
$fail = false;
} catch (\
Exception $e) {
   
}

if (
$fail) {
    echo
"Failure!\n";
} else {
    echo
"Success...\n";
}

echo
" \$testRestrictedQueue = new Types\RestrictedQueue(
                array(1, 2, 3, 'string',),
                \$testRestrictions,
                array('strict' => true)) -> "
;
               
$fail = true;

$testRestrictedQueue = null;

try {
   
$testRestrictedQueue = new Types\RestrictedQueue(
        array(
1, 2, 3, 'string',),
       
$testRestrictions,
        array(
'strict' => true));
   
$fail = false;
} catch (\
Exception $e) {
   
}

if (
$fail) {
    echo
"Failure!\n";
} else {
    echo
"Success...\n";
}

echo
" \$testRestrictedQueue = new Types\RestrictedQueue(
                array(1, 2, 3, 4, 5,),
                \$testRestrictions,
                array('strict' => true)) -> "
;
               
$success = true;

$testRestrictedQueue = null;

try {
   
$testRestrictedQueue = new Types\RestrictedQueue(
        array(
1, 2, 3, 4, 5,),
       
$testRestrictions,
        array(
'strict' => true));
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success\n";
} else {
    echo
"Failure...\n";
}

echo
"\nQueue Operations --\n\n";

echo
"Instantiate Queue 2 and Push (1) -> ";

$success = true;

$testRestrictedQueue2 = null;

try {
   
$testRestrictedQueue2 = new Types\RestrictedQueue(array(), $testRestrictions);
   
$testRestrictedQueue2->push(1);
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n\n";
    echo
"Queue Internals -- \n\n";
   
var_dump($testRestrictedQueue2->getList());
    echo
"\n";
} else {
    echo
"Failure...\n";
}

echo
"Push Queue 1 (6, 7, 8) -> ";

$success = true;

try {
   
$testRestrictedQueue->push(6, 7, 8);
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n\n";
    echo
"Queue Internals -- \n\n";
   
var_dump($testRestrictedQueue->getList());
    echo
"\n";
} else {
    echo
"Failure...\n";
}

echo
"Top -> ";

$success = true;

$val = null;

try {
   
$val = $testRestrictedQueue->top();
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success! ($val)\n";
} else {
    echo
"Failure...\n";
}

echo
"Pop -> ";

$success = true;

$val = null;

try {
   
$val = $testRestrictedQueue->pop();
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success! ($val)\n";
} else {
    echo
"Failure...\n";
}

class
testObject {
    public
$publicProp;
}

$obj = new testObject();
$obj->publicProp = 3;
$testRestrictedQueueReference = new Types\RestrictedQueue(
    array(),
    new
Types\Restrictions(array(Type::TYPED_OBJECT), array('testObject')),
    array(
'strict' => true));

echo
"Push Reference -> ";

$success = true;

//try {
   
$testRestrictedQueueReference->pushReference($obj);
//} catch (\Exception $e) {
// $success = false;
//}

if ($success) {
    echo
"Success!\n";
} else {
    echo
"Failure...\n";
}

echo
"Test Reference: ";

$success = true;

try {
   
$obj->publicProp = 5;
    echo
"\n"; var_dump($testRestrictedQueueReference->getList()); echo "\n";
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n";
} else {
    echo
"Failure...\n";
}

echo
"BottomReference -> ";

$success = true;

$val = null;

try {
   
$obj->publicProp = 7;
   
$val = $testRestrictedQueueReference->bottomReference();
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success! ({$val->publicProp})\n";
} else {
    echo
"Failure...\n";
}

echo
"PopReference -> ";

$success = true;

$val = null;

try {
   
$obj->publicProp = 11;
   
$val = $testRestrictedQueueReference->popReference();
} catch(\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success! ({$val->publicProp})\n";
} else {
    echo
"Failure...\n";
}

echo
"Testing Array Functionality -- \n";
echo
" ( [] ) -> ";

$success = true;

try {
   
$testRestrictedQueue[] = 12;
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n\n";
    echo
"Queue Internals --\n\n";
   
var_dump($testRestrictedQueue->getList());
    echo
"\n";
} else {
    echo
"Failure...\n";
}

echo
" ( [3] = 20 ) -> ";

$success = true;

try {
   
$testRestrictedQueue[3] = 20;
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n\n";
    echo
"Queue Internals --\n\n";
   
var_dump($testRestrictedQueue->getList());
    echo
"\n";
} else {
    echo
"Failure...\n";
}

echo
"Queue Roll Operations -- \n\n";
echo
" Pre-Roll -> \n\n";
var_dump($testRestrictedQueue->getList());
echo
"\n";

echo
" ::roll(2) -> ";

$success = true;

try {
   
$testRestrictedQueue->roll(2);
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n\n";
    echo
"Queue Internals --\n\n";
   
var_dump($testRestrictedQueue->getList());
    echo
"\n";
} else {
    echo
"Failure...\n";
}

echo
" ::roll(-5) -> ";

$success = true;

try {
   
$testRestrictedQueue->roll(-5);
} catch (\
Exception $e) {
   
$success = false;
}

if (
$success) {
    echo
"Success!\n\n";
    echo
"Queue Internals --\n\n";
   
var_dump($testRestrictedQueue->getList());
    echo
"\n";
} else {
    echo
"Failure...\n";
}