------------------------------------------------------------------------- --| --| S T A C K T E S T --| --| Abstract : This file contains a procedure to test the implementation --| of stack operations. --| --| Related compilation units contained in this directory are: --| --| Type Name File --| ---- ---- ---- --| Test Procedure stack_test This file --| Procedure get_word get_word.ada --| --| Specification stack_package stack.ada --| Implementation stack_package stack.ada --| --------------------------------------------------------------------------- --| Date 4/22/93 Version 1.0 --------------------------------------------------------------------------- with text_io; use text_io; with get_word; with stack_package; procedure stack_test is package stack_pak is new stack_package(integer); package iio is new integer_io(integer); use iio; operation : string(1..20); line : string(1..80); n, len, last : natural; object : integer; stack : stack_pak.stack(5); procedure put_object(object : integer) is begin iio.put(object,3); end put_object; procedure display_stack is new stack_pak.display(put_object); begin loop1 : loop begin -- This begin block is included so that exceptions -- generated by the package being tested will not -- cuase termination of the test program. loop2 : loop if end_of_file then exit loop1; else get_line(line, len); -- Get next command line. end if; get_word(line(1..len), operation, n); -- Isolate command. if n = 0 then exit loop1; end if; -- Empty line; terminate test. put(line(1..len)); if operation(1..2) = "--" -- Command is a comment. then new_line; else set_col(15); put("=> "); if operation(1..n) = "push" then iio.get(line(n+1..len), object, last); stack_pak.push(stack, object); elsif operation(1..n) = "top" then put_object(stack_pak.top(stack)); elsif operation(1..n) = "pop" then stack_pak.pop(stack); elsif operation(1..n) = "clear" then stack_pak.clear(stack); else put("??????"); end if; set_col(25); display_stack(stack); new_line; end if; end loop loop2; exception when stack_pak.stack_empty => set_col(25); put_line("stack_empty exception raised"); when stack_pak.stack_full => set_col(25); put_line("stack_full exception raised"); end; end loop loop1; new_line(2); put_line("Stack test completed."); end stack_test;