aboutsummaryrefslogtreecommitdiff
path: root/src/unit/hash.unit
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/unit/hash.unit113
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;
15typedef Bu::Hash<Bu::FString, Bu::FString> StrStrHash; 15typedef Bu::Hash<Bu::FString, Bu::FString> StrStrHash;
16typedef Bu::Hash<int, Bu::FString> IntStrHash; 16typedef Bu::Hash<int, Bu::FString> IntStrHash;
17 17
18{=Init} 18suite 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}