aboutsummaryrefslogtreecommitdiff
path: root/src/unit/hash.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2009-01-07 15:59:57 +0000
committerMike Buland <eichlan@xagasoft.com>2009-01-07 15:59:57 +0000
commit45e065bc4fc93731ea9a0543462bc7cf9e6084d7 (patch)
treea9e8279fe00b9b01dc2393f59dc7f41b5e416b2a /src/unit/hash.cpp
parentd96fe229e79f9b1947cbd24ff52d6bf7bb9bf80d (diff)
downloadlibbu++-45e065bc4fc93731ea9a0543462bc7cf9e6084d7.tar.gz
libbu++-45e065bc4fc93731ea9a0543462bc7cf9e6084d7.tar.bz2
libbu++-45e065bc4fc93731ea9a0543462bc7cf9e6084d7.tar.xz
libbu++-45e065bc4fc93731ea9a0543462bc7cf9e6084d7.zip
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.
Diffstat (limited to 'src/unit/hash.cpp')
-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