//============================================================================== // // Copyright (C) 2002 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: 2006/07/22 13:28:58 $ $Revision: 1.2 $ // //============================================================================== #include #include "ofc/config.h" #include "ofc/DTree.h" #include "DInc.h" #include "DTest.h" //-Collections----------------------------------------------------------------- void DTree_test() { DTree *tree = [DTree alloc ]; DTreeIterator *iter = [DTreeIterator alloc]; DTree *copy = nil; DInc *num; int j; STARTTEST(); [DInc reset]; [tree init]; [iter init :tree]; TEST([tree length] == 0); TEST([tree isEmpty]); [iter append :[DInc new]]; TEST([tree length] == 1); TEST(![tree isEmpty]); [iter root]; for (j = 0; j < 20; j++) { [iter append :[DInc new]]; [iter parent]; [iter prepend :[DInc new]]; [iter parent]; } TEST([tree length] == 41); num = [DInc new]; [iter prepend :num]; [iter parent]; TEST([iter child] == num); TEST([iter first] == num); [iter parent]; num = [DInc new]; [iter append :num]; [iter first]; TEST([iter isFirst]); TEST([iter last] == num); TEST([iter isLast]); [iter parent]; TEST([iter remove] == nil); num = [iter child]; TEST([tree has :num]); TEST([tree count :num] == 1); TEST([iter remove] != nil); TEST(![tree has :num]); TEST([tree count :num] == 0); [iter parent]; TEST([iter child] != num); #if 0 printf("\n"); [tree each :@selector(print)]; #endif // Shallow copy constructor copy = [tree shallowCopy]; TEST([tree length] == [copy length]); #if 0 printf("\n"); [copy each :@selector(print)]; #endif [copy shallowFree]; copy = nil; // Deep copy constructor copy = [tree copy]; TEST([tree length] == [copy length]); #if 0 printf("\n"); [copy each :@selector(print)]; #endif [copy free]; copy = nil; [tree free]; STOPTEST(); }