//============================================================================== // // Copyright (C) 2004 Dick van Oudheusden // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public // License as published by the Free Software Foundation; either // version 2 of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU // General Public License for more details. // // You should have received a copy of the GNU General Public // License along with this program; if not, write to the Free // Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // //============================================================================== // // $Date: 2004/06/24 10:01:02 $ $Revision: 1.1 $ // //============================================================================== #include #include "ofc/config.h" #include "ofc/DCircle.h" #include "DInc.h" #include "DTest.h" //-Collections----------------------------------------------------------------- void DCircle_test() { DCircle *stack = [DCircle alloc]; DCircle *stack2 = nil; DCircle *queue = [DCircle new]; DInc *obj1 = nil; DInc *obj2 = nil; DInc *obj3 = nil; long i; STARTTEST(); [stack init :20]; TEST( [stack isEmpty]); TEST(![stack isFull]); TEST(![stack isValid :0]); TEST( [stack length] == 0); // Stack test obj1 = [DInc new]; TEST([stack push :obj1]); TEST([stack length] == 1); TEST([stack tos] == obj1); TEST(![stack isEmpty]); TEST(![stack isFull]); TEST( [stack isValid :0]); TEST([stack get :0 ] == obj1); TEST([stack get :-1] == obj1); TEST([stack push :obj2]); TEST([stack push :obj3]); TEST([stack length] == 3); TEST([stack pop] == obj3); TEST([stack pop] == obj2); TEST([stack pop] == obj1); TEST([stack length] == 0); TEST([stack isEmpty]); TEST(![stack isFull]); TEST([stack pop] == nil); TEST([stack tos] == nil); [DInc reset]; for (i = 0; i < [stack size]; i++) { TEST([stack push :[DInc new]]); } TEST(![stack push :[DInc new]]); TEST(![stack isEmpty]); TEST([stack isFull]); TEST( [stack isValid :[stack size]-1]); TEST(![stack isValid :[stack size]]); stack2 = [stack copy]; [stack free]; TEST(![stack2 push :[DInc new]]); TEST(![stack2 isEmpty]); TEST([stack2 isFull]); TEST( [stack2 isValid :[stack2 size]-1]); TEST([stack2 length] == [stack2 size]); [stack2 size :40]; TEST([stack2 size ] == 40); TEST([stack2 length] == 20); TEST(![stack2 isEmpty]); TEST(![stack2 isFull]); TEST([stack2 push :[DInc new]]); #if 0 [stack2 each :@selector(print)]; [stack2 reach :@selector(print)]; #endif [stack2 free]; // Queue test TEST([queue size] == 1); TEST([queue isEmpty]); TEST(![queue isFull]); [DInc reset]; obj1 = [DInc new]; TEST([queue enqueue :obj1]); TEST([queue isFull]); TEST(![queue enqueue :obj1]); [queue size :20]; obj2 = [DInc new]; obj3 = [DInc new]; TEST([queue enqueue :obj2]); TEST([queue enqueue :obj3]); TEST([queue length] == 3); TEST([queue size ] == 20); TEST([queue get :0 ] == obj1); TEST([queue get :-2] == obj2); TEST([queue get :2 ] == obj3); TEST([queue dequeue] == obj1); TEST([queue dequeue] == obj2); TEST([queue dequeue] == obj3); TEST([queue dequeue] == nil); TEST([queue isEmpty]); TEST(![queue isFull]); [DInc reset]; for (i = 0; i < [queue size]; i++) { TEST([queue enqueue :[DInc new]]); } TEST(![queue enqueue :[DInc new]]); TEST(![queue isEmpty]); TEST([queue isFull]); TEST( [queue isValid :[queue size]-1]); TEST(![queue isValid :[queue size]]); #if 0 [queue each :@selector(print)]; [queue reach :@selector(print)]; #endif [queue free]; STOPTEST(); }