#================================================================--
# Design Unit  : cew testbench for stack
#
# File Name    : tb.cew
#
# Purpose      : unit testing
#
# Note         :
#
# Limitations  :
#
# Errors       : none known
#
# Modules      : adt::stack
#
# Dependences  : cew
#
# Author       : Peter Walsh, Vancouver Island University
#
# System       : Perl (Linux)
#
#------------------------------------------------------------------
# Revision List
# Version      Author  Date    Changes
# 1.0          PW      Oct 12  New version
#================================================================--

$|=1;
use strict;
use warnings;











use lib '../';
use adt::stack;

my $cew_Test_Count=0;
          my $cew_Error_Count=0;


# Local Function Load (s, n);
# pushes n values on the stack from
# the sequence 10, 100, 1000 ... 
# note: no exception checking

sub load {
   my $s=shift @_;
   my $n=shift @_;
   
   for (my $i=0; $i<$n; $i++) {
      $s->push(($i+1)*10);
   }
}

#############
# empty stack
#############

my $stack0=adt::stack->new();
$cew_Test_Count=$cew_Test_Count+1;
          load($stack0 ,0); $stack0->push(10)  ;
          if (($stack0->top() ) !=  (10 )) {
             $cew_Error_Count=$cew_Error_Count+1;
             print("Test Case ERROR (Ncase) in script at line number ", 58, "\n");
             print("Actual Value is ", $stack0->top() , " \n");
             print("Expected Value is ", 10 , "\n");
          }
;
$cew_Test_Count=$cew_Test_Count+1;
           ;
          if (($stack0->get_full() ) !=  (0 )) {
             $cew_Error_Count=$cew_Error_Count+1;
             print("Test Case ERROR (Ncase) in script at line number ", 59, "\n");
             print("Actual Value is ", $stack0->get_full() , " \n");
             print("Expected Value is ", 0 , "\n");
          }
;

$stack0=adt::stack->new();
$cew_Test_Count=$cew_Test_Count+1;
           ;
          if (($stack0->get_empty() ) !=  (0 )) {
             $cew_Error_Count=$cew_Error_Count+1;
             print("Test Case ERROR (Ncase) in script at line number ", 62, "\n");
             print("Actual Value is ", $stack0->get_empty() , " \n");
             print("Expected Value is ", 0 , "\n");
          }
;
$cew_Test_Count=$cew_Test_Count+1;
          load($stack0 ,0); $stack0->pop()  ;
          if (($stack0->get_empty() ) !=  (1 )) {
             $cew_Error_Count=$cew_Error_Count+1;
             print("Test Case ERROR (Ncase) in script at line number ", 63, "\n");
             print("Actual Value is ", $stack0->get_empty() , " \n");
             print("Expected Value is ", 1 , "\n");
          }
;
$stack0=adt::stack->new();
$cew_Test_Count=$cew_Test_Count+1;
          load($stack0 ,0); $stack0->top()  ;
          if (($stack0->get_empty() ) !=  (1 )) {
             $cew_Error_Count=$cew_Error_Count+1;
             print("Test Case ERROR (Ncase) in script at line number ", 65, "\n");
             print("Actual Value is ", $stack0->get_empty() , " \n");
             print("Expected Value is ", 1 , "\n");
          }
;

#################
# half full stack
#################

$stack0=adt::stack->new();
$cew_Test_Count=$cew_Test_Count+1;
          load($stack0 ,2); $stack0->push(30)  ;
          if (($stack0->top() ) !=  (30 )) {
             $cew_Error_Count=$cew_Error_Count+1;
             print("Test Case ERROR (Ncase) in script at line number ", 72, "\n");
             print("Actual Value is ", $stack0->top() , " \n");
             print("Expected Value is ", 30 , "\n");
          }
;
$cew_Test_Count=$cew_Test_Count+1;
           ;
          if (($stack0->get_full() ) !=  (0 )) {
             $cew_Error_Count=$cew_Error_Count+1;
             print("Test Case ERROR (Ncase) in script at line number ", 73, "\n");
             print("Actual Value is ", $stack0->get_full() , " \n");
             print("Expected Value is ", 0 , "\n");
          }
;

$stack0=adt::stack->new();
$cew_Test_Count=$cew_Test_Count+1;
          load($stack0 ,2)  ;
          if (($stack0->get_empty() ) !=  (0 )) {
             $cew_Error_Count=$cew_Error_Count+1;
             print("Test Case ERROR (Ncase) in script at line number ", 76, "\n");
             print("Actual Value is ", $stack0->get_empty() , " \n");
             print("Expected Value is ", 0 , "\n");
          }
;
$cew_Test_Count=$cew_Test_Count+1;
          $stack0->pop()  ;
          if (($stack0->top() ) !=  (10 )) {
             $cew_Error_Count=$cew_Error_Count+1;
             print("Test Case ERROR (Ncase) in script at line number ", 77, "\n");
             print("Actual Value is ", $stack0->top() , " \n");
             print("Expected Value is ", 10 , "\n");
          }
;
$cew_Test_Count=$cew_Test_Count+1;
           ;
          if (($stack0->get_empty() ) !=  (0 )) {
             $cew_Error_Count=$cew_Error_Count+1;
             print("Test Case ERROR (Ncase) in script at line number ", 78, "\n");
             print("Actual Value is ", $stack0->get_empty() , " \n");
             print("Expected Value is ", 0 , "\n");
          }
;

print("\n**********Summary**********\n");
          print("Total number of test cases = ", $cew_Test_Count, "\n");
          print("Total number of test cases in error = ", $cew_Error_Count, "\n");

