From 306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 15 May 2010 07:44:10 +0000 Subject: mkunit.sh was a little dumb, it didn't handle a number of things correctly. I've written a new program that basically does the same thing, only it's much more clever, and does many more of the translations and conversions better, including the #line directives. Also, I dropped nids, we don't need it anymore. But now I'm ready to write some serious tests for myriad. --- src/unit/hash.unit | 113 +++++++++++++++++++++++++++-------------------------- 1 file changed, 57 insertions(+), 56 deletions(-) (limited to 'src/unit/hash.unit') diff --git a/src/unit/hash.unit b/src/unit/hash.unit index c0a10e3..e3d7e42 100644 --- a/src/unit/hash.unit +++ b/src/unit/hash.unit @@ -15,72 +15,73 @@ typedef Bu::Hash StrIntHash; typedef Bu::Hash StrStrHash; typedef Bu::Hash IntStrHash; -{=Init} - -{%probe1} +suite Hash { - StrIntHash h; - char buf[20]; - for(int i=1;i<10000;i++) + test probe1 { - sprintf(buf,"%d",i); - Bu::FString sTmp(buf); - h[sTmp] = i; - unitTest( h.has(sTmp) ); + 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" ); + test insert1 + { + StrIntHash h; + h["Hi"] = 42; + unitTest( h["Hi"] == 42 ); + } - StrStrHash h2(h); - unitTest( h2["Hi"].getValue() == "Yo" ); - unitTest( h2["Bye"].getValue() == "Later" ); + test insert2 + { + StrStrHash h; + h["Hi"] = "Yo"; + h["Bye"] = "Later"; + unitTest( h["Hi"].getValue() == "Yo" ); - StrStrHash h3; - h3 = h; - unitTest( h3["Hi"].getValue() == "Yo" ); - unitTest( h3["Bye"].getValue() == "Later" ); -} + StrStrHash h2(h); + unitTest( h2["Hi"].getValue() == "Yo" ); + unitTest( h2["Bye"].getValue() == "Later" ); -{%insert3} -{ - IntStrHash h; + StrStrHash h3; + h3 = h; + unitTest( h3["Hi"].getValue() == "Yo" ); + unitTest( h3["Bye"].getValue() == "Later" ); + } - for( unsigned int i=1; i<50; i++ ) + test insert3 { - h[i] = "testing"; - unitTest( h.getSize() == i ); - } -} + IntStrHash h; -{%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 ) { } + for( unsigned int i=1; i<50; i++ ) + { + h[i] = "testing"; + unitTest( h.getSize() == i ); + } + } -/* printf("\n"); - for( StrIntHash::iterator i = h.begin(); i != h.end(); i++ ) + test erase1 { - printf(" - \"%s\" = %d\n", i.getKey().getStr(), i.getValue() ); - } */ + 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