PHP Classes

File: test.php

Recommend this page to a friend!
  Classes of Biswarup Adhikari   PHP Linked List   test.php   Download  
File: test.php
Role: Unit test script
Content type: text/plain
Description: PHPLinkedList Test Cases
Class: PHP Linked List
Manage elements stored in a linked list
Author: By
Last change:
Date: 8 years ago
Size: 1,973 bytes
 

Contents

Class file image Download
<?php
/**
 * PHPLinkedList Test Cases
 * examples.php
 * @category DataStructure
 * @package PHPLinkedList Test
 * @author Biswarup Adhikari <biswarupadhikari@gmail.com>
 */
require_once 'PHPLinkedList.php';


/**
 * Test Helper Function
 */
function runTest($result,$testCase='',$successMsg='Pass',$failedMsg='Failed')
{
    echo
"$testCase\n";
    if(
$result)
    {
        echo
"\033[32m ".$successMsg." \033[0m\n";
    }
    else
    {
        echo
"\033[31m ".$failedMsg." \033[0m\n";
    }
}
/**
 * Create New LinkedList
 */
$myLinkedList=new PHPLinkedList;


/**
 * Zero Item Count Test
 */
runTest($myLinkedList->count()==0,"Zero Item Count Test");
/**
 * Count After Adding One Item
 */
$first=5;
$myLinkedList->put($first);
runTest($myLinkedList->count()==1,"Count After Adding One Item");

/**
 * Test Get First Item
 */
runTest($myLinkedList->first()==5,"Get First Item");

/**
 * Test Last Item
 */
runTest($myLinkedList->last()==5,"Get Last Item");

/**
 * Element At position Test
 */

runTest($myLinkedList->get(0)==5,"Element at Position Test");

/**
 * Test Count After Adding Two Element
 */
$second=58;
$myLinkedList->put($second);
runTest($myLinkedList->count()==2,"Count After Adding Two Item");


/**
 * Test Get First Item
 */
runTest($myLinkedList->first()==5,"Get First Item");
/**
 * Test Last Item
 */
runTest($myLinkedList->last()==58,"Get Last Item");



/**
 * Test Dynamic Element
 */
$items=new PHPLinkedList;
$start=10;
$limit=50;
$total=($limit - $start) + 1;
for(
$i=$start;$i<=$limit;$i++)
{
   
$items->put($i);
}

$j=0;
for(
$i=$start;$i<=$limit;$i++)
{
   
runTest($items->get($j)==$i,"Put And Get Test For Dynamic Data $i");
   
$j++;
}

/**
 * Count Test After Dynamic Data Insert
 */


runTest($items->count()==$total,"Count After Adding Dynaic Data");
/**
 * Test Get First Item
 */
runTest($items->first()==$start,"Get First Item in Dynamic Data");
/**
 * Test Last Item
 */
runTest($items->last()==$limit,"Get Last Item in Dynamic Data");

$items->printChain();