Lecture_20 – November 7,
2006
We
went over the specification for the generic stack package and discussed:
generic parameters
the purpose
of each function and procedure
the
pre-conditions for each procedure and function
that the pop
procedure just alters the stack but doesn’t return a value which means that in order to retrieve the
value peek has to be called first
everyone downloaded the specification – which is also shown
below
GENERIC TYPE
Element IS PRIVATE; PACKAGE Stacks_Generic
IS TYPE Stack (Capacity: Positive) IS LIMITED
PRIVATE; StackFull : EXCEPTION; StackEmpty:
EXCEPTION; PROCEDURE
MakeEmpty (S : IN OUT Stack); PROCEDURE
Push (S : IN OUT Stack; E : IN Element); PROCEDURE
Pop (S : IN OUT Stack); FUNCTION
Peek (S: IN Stack) RETURN Element; FUNCTION IsEmpty(S : IN Stack) RETURN Boolean; FUNCTION IsFull (S : IN Stack) RETURN Boolean; PRIVATE TYPE
List IS ARRAY ( TYPE Stack (Capacity : Positive ) IS RECORD Latest : Natural := 0; Store : List(1..Capacity); END RECORD; END Stacks_Generic; |
We
discussed the assignment which will be due on Friday by Midnight in the drop
box with yourname16.zip containing the given specification and your implementation.
The
assignment is to complete the implementation of the generic stack package (i.e.
the body).
We
ran the program I wrote to test MY generic stack package implementation and
discussed the features necessary for a good test
program. We discussed and looked at the necessary
declarations and instantiations to test the program for different data types. Everyone downloaded the code which is also
shown below.
WITH ada.text_io; WITH Stacks_Generic; PROCEDURE Stacks_Generic_Test IS TYPE fruit IS (apple, berry, cheery, banana, orange,
blueberry); TYPE cars IS
(corolla, Super308, carrera, sylvia); PACKAGE fruit_io IS NEW ada.text_io.Enumeration_io (fruit); PACKAGE bool_io IS NEW ada.text_io.Enumeration_io (boolean); PACKAGE cars_io IS NEW ada.text_io.Enumeration_io (cars); PACKAGE Stacks IS NEW Stacks_Generic (Element =>
Character); PACKAGE FruitStack IS NEW Stacks_Generic (Element =>
fruit); PACKAGE CarStack IS NEW Stacks_Generic (Element =>
cars); myFruitStack
: FruitStack.Stack (20); aStack
: Stacks.Stack (5); parkingLot
: CarStack.Stack (50); BEGIN -- test 1 ada.text_io.put
(" about to call MakeEmpty "); Stacks.MakeEmpty
(aStack); FruitStack.MakeEmpty
(myFruitStack); CarStack.MakeEmpty
(parkingLot); ada.text_io.put
(" stack should not be full so will call isFull
"); ada.text_io.put
(" expect FALSE FALSE FALSE
"); bool_io.put
(Stacks.isFull(aStack)); bool_io.put
(CarStack.isFull (parkingLot)); bool_io.put
(FruitStack.isFull (myFruitStack)); ada.text_io.new_line; |
Everyone
downloaded the executable which tests MY program (not yours).
Its
only value is to show you what a good test might be. You will need to test your program
yourselves. When I grade yourname16 I will compile my test program
with your spec and body. The test program you write as yourname17 (i.e. your test program which
is due Monday at midnight) will be compiled and tested with MY implementation.
Here are some
of the things my test program will test:
1.
makeEmpty at start of
program
2.
makeEmpty in middle of
program
3.
push onto a full stack
4.
push onto a non-full stack
5.
pop from an empty stack
6.
pop from a non-empty stack
7.
peek at an empty stack
8.
peek at a non-empty stack
9.
is a stackFull exception
raised
10.
is a stackEmpty exception
raised
It will test
these things on different data types and in appropriate places.
We looked at a specification for a binary search tree which differs
from the one in our book. FOR THURSDAY
you should study it (which is shown below) and write and bring to class a
stubbed out implementation.
PACKAGE Binary_Search_Trees IS TYPE BinaryTreeNode; TYPE Tree IS
ACCESS BinaryTreeNode; TYPE BinaryTreeNode IS RECORD Info : Integer; Left
: Tree := NULL; Right: Tree := Null; END RECORD; NotFound : Exception; PROCEDURE Initialize
(T : in out Tree); PROCEDURE Insert (T :
IN OUT Tree; E : Integer); FUNCTION Search (T :
Tree; K : Integer) RETURN Tree; FUNCTION Retrieve (T
: Tree ) RETURN Integer; PROCEDURE Delete (T :
IN OUT Tree; K : IN Integer); PROCEDURE Traverse_LNR (T : Tree); -- PROCEDURE Traverse_NLR (T : Tree); -- PROCEDURE Traverse_LRN (T : Tree); END Binary_Search_Trees; |
You
should also look at the implementations given in the book for the procedures and
functions in their specification which match the ones in ours.