diff options
author | Mike Buland <eichlan@xagasoft.com> | 2010-05-15 07:44:10 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2010-05-15 07:44:10 +0000 |
commit | 306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68 (patch) | |
tree | 32c35f8507edb4ea403f4ebc4b625c1096f6f384 /src/unit/hash.unit | |
parent | 11413d228bae2919fe69c83b74c7ff49209dd65a (diff) | |
download | libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.tar.gz libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.tar.bz2 libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.tar.xz libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.zip |
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.
Diffstat (limited to 'src/unit/hash.unit')
-rw-r--r-- | src/unit/hash.unit | 113 |
1 files changed, 57 insertions, 56 deletions
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<Bu::FString, int> StrIntHash; | |||
15 | typedef Bu::Hash<Bu::FString, Bu::FString> StrStrHash; | 15 | typedef Bu::Hash<Bu::FString, Bu::FString> StrStrHash; |
16 | typedef Bu::Hash<int, Bu::FString> IntStrHash; | 16 | typedef Bu::Hash<int, Bu::FString> IntStrHash; |
17 | 17 | ||
18 | {=Init} | 18 | suite Hash |
19 | |||
20 | {%probe1} | ||
21 | { | 19 | { |
22 | StrIntHash h; | 20 | test probe1 |
23 | char buf[20]; | ||
24 | for(int i=1;i<10000;i++) | ||
25 | { | 21 | { |
26 | sprintf(buf,"%d",i); | 22 | StrIntHash h; |
27 | Bu::FString sTmp(buf); | 23 | char buf[20]; |
28 | h[sTmp] = i; | 24 | for(int i=1;i<10000;i++) |
29 | unitTest( h.has(sTmp) ); | 25 | { |
26 | sprintf(buf,"%d",i); | ||
27 | Bu::FString sTmp(buf); | ||
28 | h[sTmp] = i; | ||
29 | unitTest( h.has(sTmp) ); | ||
30 | } | ||
30 | } | 31 | } |
31 | } | ||
32 | |||
33 | {%insert1} | ||
34 | { | ||
35 | StrIntHash h; | ||
36 | h["Hi"] = 42; | ||
37 | unitTest( h["Hi"] == 42 ); | ||
38 | } | ||
39 | 32 | ||
40 | {%insert2} | 33 | test insert1 |
41 | { | 34 | { |
42 | StrStrHash h; | 35 | StrIntHash h; |
43 | h["Hi"] = "Yo"; | 36 | h["Hi"] = 42; |
44 | h["Bye"] = "Later"; | 37 | unitTest( h["Hi"] == 42 ); |
45 | unitTest( h["Hi"].getValue() == "Yo" ); | 38 | } |
46 | 39 | ||
47 | StrStrHash h2(h); | 40 | test insert2 |
48 | unitTest( h2["Hi"].getValue() == "Yo" ); | 41 | { |
49 | unitTest( h2["Bye"].getValue() == "Later" ); | 42 | StrStrHash h; |
43 | h["Hi"] = "Yo"; | ||
44 | h["Bye"] = "Later"; | ||
45 | unitTest( h["Hi"].getValue() == "Yo" ); | ||
50 | 46 | ||
51 | StrStrHash h3; | 47 | StrStrHash h2(h); |
52 | h3 = h; | 48 | unitTest( h2["Hi"].getValue() == "Yo" ); |
53 | unitTest( h3["Hi"].getValue() == "Yo" ); | 49 | unitTest( h2["Bye"].getValue() == "Later" ); |
54 | unitTest( h3["Bye"].getValue() == "Later" ); | ||
55 | } | ||
56 | 50 | ||
57 | {%insert3} | 51 | StrStrHash h3; |
58 | { | 52 | h3 = h; |
59 | IntStrHash h; | 53 | unitTest( h3["Hi"].getValue() == "Yo" ); |
54 | unitTest( h3["Bye"].getValue() == "Later" ); | ||
55 | } | ||
60 | 56 | ||
61 | for( unsigned int i=1; i<50; i++ ) | 57 | test insert3 |
62 | { | 58 | { |
63 | h[i] = "testing"; | 59 | IntStrHash h; |
64 | unitTest( h.getSize() == i ); | ||
65 | } | ||
66 | } | ||
67 | 60 | ||
68 | {%erase1} | 61 | for( unsigned int i=1; i<50; i++ ) |
69 | { | 62 | { |
70 | StrIntHash h; | 63 | h[i] = "testing"; |
71 | h.insert("Number 1", 1 ); | 64 | unitTest( h.getSize() == i ); |
72 | h.insert("Number 2", 2 ); | 65 | } |
73 | h.insert("Number 3", 3 ); | 66 | } |
74 | h.erase("Number 2"); | ||
75 | h.get("Number 3"); | ||
76 | try { | ||
77 | h.get("Number 2"); | ||
78 | unitFailed("h.get(\"Number 2\") should have thrown an exception."); | ||
79 | } catch( Bu::HashException &e ) { } | ||
80 | 67 | ||
81 | /* printf("\n"); | 68 | test erase1 |
82 | for( StrIntHash::iterator i = h.begin(); i != h.end(); i++ ) | ||
83 | { | 69 | { |
84 | printf(" - \"%s\" = %d\n", i.getKey().getStr(), i.getValue() ); | 70 | StrIntHash h; |
85 | } */ | 71 | h.insert("Number 1", 1 ); |
72 | h.insert("Number 2", 2 ); | ||
73 | h.insert("Number 3", 3 ); | ||
74 | h.erase("Number 2"); | ||
75 | h.get("Number 3"); | ||
76 | try { | ||
77 | h.get("Number 2"); | ||
78 | unitFailed("h.get(\"Number 2\") should have thrown an exception."); | ||
79 | } catch( Bu::HashException &e ) { } | ||
80 | |||
81 | /* printf("\n"); | ||
82 | for( StrIntHash::iterator i = h.begin(); i != h.end(); i++ ) | ||
83 | { | ||
84 | printf(" - \"%s\" = %d\n", i.getKey().getStr(), i.getValue() ); | ||
85 | } */ | ||
86 | } | ||
86 | } | 87 | } |