From 45e065bc4fc93731ea9a0543462bc7cf9e6084d7 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 7 Jan 2009 15:59:57 +0000 Subject: Only two real changes. First, Bu::FString and Bu::FBasicString are in different files. This won't affect any programs at all anywhere. This will just make it easier to maintain and extend later. You still want to include "bu/fstring.h" and use Bu::FString in code. The other is kinda fun. I created a special format for unit tests, they use the extension .unit now and use the mkunit.sh script to convert them to c++ code. There are some nice features here too, maintaining unit tests is much, much easier, and we can have more features without making the code any harder to use. Also, it will be easier to have the unit tests generate reports and be run from a master program and the like. --- src/unit/hash.unit | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 src/unit/hash.unit (limited to 'src/unit/hash.unit') diff --git a/src/unit/hash.unit b/src/unit/hash.unit new file mode 100644 index 0000000..bd7da61 --- /dev/null +++ b/src/unit/hash.unit @@ -0,0 +1,86 @@ +// vim: syntax=cpp +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/fstring.h" +#include "bu/hash.h" + +#include + +typedef Bu::Hash StrIntHash; +typedef Bu::Hash StrStrHash; +typedef Bu::Hash IntStrHash; + +{=Init} + +{%probe1} +{ + StrIntHash h; + char buf[20]; + for(int i=1;i<10000;i++) + { + sprintf(buf,"%d",i); + Bu::FString sTmp(buf); + h[sTmp] = i; + unitTest( h.has(sTmp) ); + } +} + +{%insert1} +{ + StrIntHash h; + h["Hi"] = 42; + unitTest( h["Hi"] == 42 ); +} + +{%insert2} +{ + StrStrHash h; + h["Hi"] = "Yo"; + h["Bye"] = "Later"; + unitTest( h["Hi"].getValue() == "Yo" ); + + StrStrHash h2(h); + unitTest( h2["Hi"].getValue() = "Yo" ); + unitTest( h2["Bye"].getValue() = "Later" ); + + StrStrHash h3; + h3 = h; + unitTest( h3["Hi"].getValue() = "Yo" ); + unitTest( h3["Bye"].getValue() = "Later" ); +} + +{%insert3} +{ + IntStrHash h; + + for( unsigned int i=1; i<50; i++ ) + { + h[i] = "testing"; + unitTest( h.getSize() == i ); + } +} + +{%erase1} +{ + StrIntHash h; + h.insert("Number 1", 1 ); + h.insert("Number 2", 2 ); + h.insert("Number 3", 3 ); + h.erase("Number 2"); + h.get("Number 3"); + try { + h.get("Number 2"); + unitFailed("h.get(\"Number 2\") should have thrown an exception."); + } catch( Bu::HashException &e ) { } + +/* printf("\n"); + for( StrIntHash::iterator i = h.begin(); i != h.end(); i++ ) + { + printf(" - \"%s\" = %d\n", i.getKey().getStr(), i.getValue() ); + } */ +} -- cgit v1.2.3