home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-11-19 | 4.3 KB | 204 lines | [TEXT/MPS ] |
- /*
- File: TestAllocLinkedList.cp
-
- Contains: Tester for the linked list class
-
- Copyright: © 1991-1994 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #ifndef __TESTALLOCLINKEDLIST__
- #include "TestAllocLinkedList.h"
- #endif
-
- /**********************************************************************
- ** PUBLIC Constructor/Destructor
- ***********************************************************************/
-
- Constructor(AllocLinkedList)
- Destructor(AllocLinkedList)
-
- /**********************************************************************
- ** PUBLIC InitTest
- ***********************************************************************/
-
- void TTestAllocLinkedList :: InitTest(BooleanParm verbose, BooleanParm, int, char**)
- {
- short idx;
-
- TStandardPool* pool = GetPool();
-
- for (idx = 0; idx < 100; ++idx)
- fArray[idx] = NULL;
-
- if (pool == NULL)
- {
- Printf("### ERROR: There is no global pool\n");
- return;
- }
-
- fTest = new (pool) TLinkedList(pool);
-
- for (idx = 0; idx < 100; ++idx)
- {
- TNumber* num;
- if ((num = new (pool) TNumber(idx)) == NULL)
- {
- Printf("### ERROR: Out of Memory at #%d\n", idx);
- break;
- }
- fArray[idx] = (TLink*)num;
- }
- if (idx == 100 && verbose)
- Printf("INFO: Allocated 100 objects\n");
- }
-
- /**********************************************************************
- ** PUBLIC RunTestIteration
- ***********************************************************************/
-
- void TTestAllocLinkedList :: RunTestIteration(BooleanParm verbose, BooleanParm)
- {
- short matchFirst;
- short matchLast;
- short toMatch;
- short idx, jdx;
- TNumber* ptr;
- char* str;
-
- if (verbose)
- Printf("INFO: Testing EmptyList\n");
-
- TestIsEmpty(true);
- TestFirstLast(-1, -1);
- TestCount(0);
- for (jdx = 0; jdx < 100; ++jdx)
- TestMember(jdx, true);
-
- if (verbose)
- Printf("INFO: Testing AddFirst, Member, Count, First, Last and IsEmpty\n");
-
- for (idx = 0; idx < 100; ++idx)
- {
- ptr = (TNumber*)fArray[idx];
- fTest->AddFirst(ptr);
-
- TestIsEmpty(false);
- TestCount(idx + 1);
- TestFirstLast(idx, 0);
-
- for (jdx = 0; jdx < 100; ++jdx)
- TestMember(jdx, jdx > idx);
- }
-
- TestIsEmpty(false);
- TestCount(100);
- TestFirstLast(99, 0);
-
- matchFirst = 0;
- matchLast = 99;
- if (verbose)
- Printf("INFO: Testing First, Last, RemoveFirst, RemoveLast, and Member methods\n");
-
- for (idx = 0; idx < 100; ++idx)
- {
- TestIsEmpty(false);
- TestCount(100 - idx);
- TestFirstLast(matchLast, matchFirst);
-
- for (jdx = 0; jdx < 100; ++jdx)
- TestMember(jdx, jdx < matchFirst || jdx > matchLast);
-
- if (idx & 1)
- {
- ptr = (TNumber*)fTest->RemoveFirst();
- toMatch = matchLast;
- matchLast -= 1;
- str = "RemoveFirst";
- }
- else
- {
- ptr = (TNumber*)fTest->RemoveLast();
- toMatch = matchFirst;
- matchFirst += 1;
- str = "RemoveLast";
- }
- if (ptr == NULL)
- Printf("### ERROR: %s return no object, instead of #%hu\n",
- str, toMatch);
- else
- {
- if (ptr->fNumber != toMatch)
- Printf("### ERROR: %s return object #%hu, instead of #%hu\n",
- str, ptr->fNumber, toMatch);
- }
- }
-
- TestIsEmpty(true);
- TestFirstLast(-1, -1);
- TestCount(0);
- for (jdx = 0; jdx < 100; ++jdx)
- TestMember(jdx, true);
-
- if (verbose)
- Printf("INFO: Testing AddLast, Member, Count, First, Last and IsEmpty\n");
-
- for (idx = 0; idx < 100; ++idx)
- {
- ptr = (TNumber*)fArray[idx];
- fTest->AddLast(ptr);
-
- TestIsEmpty(false);
- TestCount(idx + 1);
- TestFirstLast(0, idx);
-
- for (jdx = 0; jdx < 100; ++jdx)
- TestMember(jdx, jdx > idx);
- }
-
- if (verbose)
- Printf("INFO: Testing RemoveAll\n");
-
- fTest->RemoveAll();
-
- TestIsEmpty(true);
- TestCount(0);
- TestFirstLast(-1, -1);
- for (jdx = 0; jdx < 100; ++jdx)
- TestMember(jdx, true);
-
- if (verbose)
- Printf("INFO: Testing Add, Member, Count, First, Last and IsEmpty\n");
-
- for (idx = 0; idx < 100; ++idx)
- {
- fTest->Add((TNumber*)fArray[idx]);
-
- TestIsEmpty(false);
- TestCount(idx + 1);
- TestFirstLast(0, idx);
-
- for (jdx = 0; jdx < 100; ++jdx)
- TestMember(jdx, jdx > idx);
- }
-
- fTest->RemoveAll();
- }
-
- /**********************************************************************
- ** PUBLIC EndTest
- ***********************************************************************/
-
- void TTestAllocLinkedList :: EndTest(BooleanParm verbose, BooleanParm)
- {
- if (verbose)
- Printf("INFO: End of Linked List test\n");
- for (short idx = 0; idx < 100; ++idx)
- {
- TNumber* ptr = (TNumber*)fArray[idx];
- delete ptr;
- }
- if (verbose)
- Printf("INFO: Deleted 100 objects\n");
- }
-