aboutsummaryrefslogtreecommitdiff
path: root/src/unit/hash.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/unit/hash.cpp109
1 files changed, 0 insertions, 109 deletions
diff --git a/src/unit/hash.cpp b/src/unit/hash.cpp
deleted file mode 100644
index e04a656..0000000
--- a/src/unit/hash.cpp
+++ /dev/null
@@ -1,109 +0,0 @@
1/*
2 * Copyright (C) 2007-2008 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#include "bu/fstring.h"
9#include "bu/hash.h"
10#include "bu/unitsuite.h"
11
12#include <stdio.h>
13
14class Unit : public Bu::UnitSuite
15{
16private:
17 typedef Bu::Hash<Bu::FString, int> StrIntHash;
18 typedef Bu::Hash<Bu::FString, Bu::FString> StrStrHash;
19 typedef Bu::Hash<int, Bu::FString> IntStrHash;
20
21public:
22 Unit()
23 {
24 setName("Hash");
25 addTest( Unit::insert1 );
26 addTest( Unit::insert2 );
27 addTest( Unit::insert3 );
28 addTest( Unit::probe1 );
29 addTest( Unit::erase1 );
30 }
31
32 virtual ~Unit()
33 {
34 }
35
36 void probe1()
37 {
38 StrIntHash h;
39 char buf[20];
40 for(int i=1;i<10000;i++)
41 {
42 sprintf(buf,"%d",i);
43 Bu::FString sTmp(buf);
44 h[sTmp] = i;
45 unitTest( h.has(sTmp) );
46 }
47 }
48
49 void insert1()
50 {
51 StrIntHash h;
52 h["Hi"] = 42;
53 unitTest( h["Hi"] == 42 );
54 }
55
56 void insert2()
57 {
58 StrStrHash h;
59 h["Hi"] = "Yo";
60 h["Bye"] = "Later";
61 unitTest( h["Hi"].getValue() == "Yo" );
62
63 StrStrHash h2(h);
64 unitTest( h2["Hi"].getValue() = "Yo" );
65 unitTest( h2["Bye"].getValue() = "Later" );
66
67 StrStrHash h3;
68 h3 = h;
69 unitTest( h3["Hi"].getValue() = "Yo" );
70 unitTest( h3["Bye"].getValue() = "Later" );
71 }
72
73 void insert3()
74 {
75 IntStrHash h;
76
77 for( unsigned int i=1; i<50; i++ )
78 {
79 h[i] = "testing";
80 unitTest( h.getSize() == i );
81 }
82 }
83
84 void erase1()
85 {
86 StrIntHash h;
87 h.insert("Number 1", 1 );
88 h.insert("Number 2", 2 );
89 h.insert("Number 3", 3 );
90 h.erase("Number 2");
91 h.get("Number 3");
92 try {
93 h.get("Number 2");
94 unitFailed("h.get(\"Number 2\") should have thrown an exception.");
95 } catch( Bu::HashException &e ) { }
96
97 /* printf("\n");
98 for( StrIntHash::iterator i = h.begin(); i != h.end(); i++ )
99 {
100 printf(" - \"%s\" = %d\n", i.getKey().getStr(), i.getValue() );
101 } */
102 }
103};
104
105int main( int argc, char *argv[] )
106{
107 return Unit().run( argc, argv );
108}
109