X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=nucleus%2Flibrary%2Ftests_nodes%2Ftest_list.cpp;fp=nucleus%2Flibrary%2Ftests_nodes%2Ftest_list.cpp;h=0000000000000000000000000000000000000000;hb=7b39f7e279005c8466ef508220a532ce2aa4abf8;hp=14a4fc7bea7065a22f56edf9f1c5e17fb778c215;hpb=3fbd372b35b15a19fb171d5ae34294ff7b1e6485;p=feisty_meow.git diff --git a/nucleus/library/tests_nodes/test_list.cpp b/nucleus/library/tests_nodes/test_list.cpp deleted file mode 100644 index 14a4fc7b..00000000 --- a/nucleus/library/tests_nodes/test_list.cpp +++ /dev/null @@ -1,140 +0,0 @@ -/*****************************************************************************\ -* * -* Name : test_list * -* Author : Chris Koeritz * -* * -******************************************************************************* -* Copyright (c) 1993-$now By Author. 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 is online at: * -* http://www.fsf.org/copyleft/gpl.html * -* Please send any updates to: fred@gruntose.com * -\*****************************************************************************/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace application; -using namespace basis; -using namespace configuration; -using namespace loggers; -using namespace mathematics; -using namespace nodes; -using namespace structures; -using namespace unit_test; - -//#define DEBUG_LIST - // uncomment this line to get more debugging output. - -const int DEFAULT_ITERATIONS = 50; - // the default number of times we run through our phase loop. - -typedef basket t_node; - // the object we store in the list, a templated integer. - -#define CASTER(bare_node) static_cast(bare_node) - // turns a node pointer into our special t_node. - -#define LOG(to_print) EMERGENCY_LOG(program_wide_logger::get(), to_print) - -////////////// - -class test_list : virtual public unit_base, virtual public application_shell -{ -public: - test_list() : unit_base() {} - DEFINE_CLASS_NAME("test_list"); - virtual int execute(); -}; - -HOOPLE_MAIN(test_list, ); - -////////////// - -int test_list::execute() -{ - FUNCDEF("execute"); - - list the_list; - chaos randomizer; - - int iterations_left = DEFAULT_ITERATIONS; - while (iterations_left-- > 0) { - - // run through the phases below as many times as we are told. - - { - // phase for adding a random number into the list. - int to_add = randomizer.inclusive(0, 100000); - - // seek the correct insertion place to keep the list ordered. - list::iterator iter = the_list.head(); - while (!iter.is_tail() && iter.observe() - && (CASTER(iter.observe())->stored() <= to_add) ) - iter++; - the_list.insert(iter, new t_node(2, to_add)); - } - - { - // test the list invariant (which is that all elements should be sorted - // in non-decreasing order). - list::iterator iter = the_list.tail(); - // initialize our comparator. - int bigger = CASTER(iter.observe())->stored(); - // loop backwards until we hit the head. - while (!iter.is_head()) { - // check that the last value is not less than the current value. - ASSERT_FALSE(bigger < CASTER(iter.observe())->stored(), - "invariant check should not find a mal-ordering in the list"); - bigger = CASTER(iter.observe())->stored(); - iter--; - } - } - - { - // if the conditions are favorable, we whack at least one element out of - // the list. - if (randomizer.inclusive(1, 100) < 20) { - int elem = the_list.elements(); - int to_whack = randomizer.inclusive(0, elem - 1); - - // start at the head of the list... - list::iterator iter = the_list.head(); - // and jump to the element we chose. - the_list.forward(iter, to_whack); - ASSERT_EQUAL(the_list.index(iter), to_whack, - "forward should not see logic error where index of element to zap is incorrect"); - ASSERT_FALSE(iter.is_tail(), - "forward should not see logic error where we get to the tail somehow"); - the_list.zap(iter); - } - } - - } - -#ifdef DEBUG_LIST - list::iterator iter = the_list.head(); - log(astring("")); - log(astring("list contents:")); - int indy = 0; - while (!iter.is_tail()) { - int item = CASTER(iter.observe())->stored(); - log(a_sprintf("item #%d: %d", indy, item)); - indy++; - iter++; - } -#endif - - return final_report(); -} - -