00001 /*****************************************************************************\ 00002 * * 00003 * Name : test_symbol_tree * 00004 * Author : Chris Koeritz * 00005 * * 00006 * Purpose: * 00007 * * 00008 * Creates a symbol_tree and performs some operations on it to assure * 00009 * basic functionality. * 00010 * * 00011 ******************************************************************************* 00012 * Copyright (c) 1992-$now By Author. This program is free software; you can * 00013 * redistribute it and/or modify it under the terms of the GNU General Public * 00014 * License as published by the Free Software Foundation; either version 2 of * 00015 * the License or (at your option) any later version. This is online at: * 00016 * http://www.fsf.org/copyleft/gpl.html * 00017 * Please send any updates to: fred@gruntose.com * 00018 \*****************************************************************************/ 00019 00020 #include <basis/chaos.h> 00021 #include <basis/function.h> 00022 #include <basis/guards.h> 00023 #include <basis/istring.h> 00024 #include <basis/portable.h> 00025 #include <nodes/symbol_tree.h> 00026 #include <opsystem/application_shell.h> 00027 #include <loggers/console_logger.h> 00028 #include <loggers/file_logger.h> 00029 #include <data_struct/static_memory_gremlin.h> 00030 #include <textual/string_manipulation.h> 00031 00032 #include <stdio.h> 00033 #include <stdlib.h> 00034 00035 using namespace nodes; 00036 00037 #define DEBUG_SYMBOL_TREE 00038 00039 class test_symbol_tree : public application_shell 00040 { 00041 public: 00042 test_symbol_tree() : application_shell(static_class_name()) {} 00043 IMPLEMENT_CLASS_NAME("test_symbol_tree"); 00044 int execute(); 00045 }; 00046 00047 int test_symbol_tree::execute() 00048 { 00049 printf("please check memory usage and record it, then hit a key to " 00050 "start testing.\n"); 00051 // getchar(); 00052 00053 try { 00054 symbol_tree t("blork"); 00055 symbol_tree *curr = &t; 00056 for (int i = 0; i < 40000; i++) { 00057 // if the current node has any branches, we'll jump on one as the next 00058 // place. 00059 if (curr->branches()) { 00060 // move to a random branch. 00061 int which = randomizer().inclusive(0, curr->branches() - 1); 00062 curr = (symbol_tree *)curr->branch(which); 00063 } 00064 istring rando = string_manipulation::make_random_name(1, 10); 00065 curr->add(new symbol_tree(rando)); 00066 } 00067 printf("check memory usage now with full size. then hit a key.\n"); 00068 // getchar(); 00069 } catch (...) { 00070 printf("crashed during tree stuffing.\n"); 00071 return 1; 00072 } 00073 00074 printf("check memory usage after the run. then hit a key to end " 00075 "the program.\n"); 00076 // getchar(); 00077 00078 //create a tree structure... 00079 //perform known operations and validate shape of tree. 00080 00081 guards::alert_message("symbol_tree:: works for those functions tested."); 00082 return 0; 00083 } 00084 00086 00087 HOOPLE_MAIN(test_symbol_tree, ) 00088
1.5.1