aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid <david@xagasoft.com>2008-11-11 01:06:28 +0000
committerDavid <david@xagasoft.com>2008-11-11 01:06:28 +0000
commitf5b9d8d923822c31b98b39ba0fabae24fadc6d9c (patch)
tree34cdea37633298b7b4e95a5d4df6b451d7dd3a69
parent4bbeb6208ac33f71a09701cc5251f0412977946e (diff)
downloadlibbu++-f5b9d8d923822c31b98b39ba0fabae24fadc6d9c.tar.gz
libbu++-f5b9d8d923822c31b98b39ba0fabae24fadc6d9c.tar.bz2
libbu++-f5b9d8d923822c31b98b39ba0fabae24fadc6d9c.tar.xz
libbu++-f5b9d8d923822c31b98b39ba0fabae24fadc6d9c.zip
david - added operator= and copy constructor to Bu::Array, and updated unit tests to test it
-rw-r--r--src/array.h11
-rw-r--r--src/unit/array.cpp35
-rw-r--r--src/unit/hash.cpp10
3 files changed, 56 insertions, 0 deletions
diff --git a/src/array.h b/src/array.h
index 30d281a..1f11cd9 100644
--- a/src/array.h
+++ b/src/array.h
@@ -42,6 +42,7 @@ namespace Bu
42 iSize( 0 ), 42 iSize( 0 ),
43 iCapacity( 0 ) 43 iCapacity( 0 )
44 { 44 {
45 *this = src;
45 } 46 }
46 47
47 Array( long iSetCap ) : 48 Array( long iSetCap ) :
@@ -57,6 +58,16 @@ namespace Bu
57 clear(); 58 clear();
58 } 59 }
59 60
61 MyType &operator=( const MyType &src )
62 {
63 clear();
64 setCapacity( src.iCapacity );
65 long iTop=src.getSize();
66 for( long i=0; i<iTop; ++i )
67 append( src[i] );
68 return *this;
69 }
70
60 /** 71 /**
61 * Clear the array. 72 * Clear the array.
62 */ 73 */
diff --git a/src/unit/array.cpp b/src/unit/array.cpp
index 57d6c03..f7dc0ae 100644
--- a/src/unit/array.cpp
+++ b/src/unit/array.cpp
@@ -6,6 +6,7 @@
6 */ 6 */
7 7
8#include "bu/unitsuite.h" 8#include "bu/unitsuite.h"
9#include "bu/hash.h"
9#include "bu/array.h" 10#include "bu/array.h"
10 11
11class Unit : public Bu::UnitSuite 12class Unit : public Bu::UnitSuite
@@ -17,6 +18,7 @@ public:
17 addTest( Unit::general ); 18 addTest( Unit::general );
18 addTest( Unit::iterate1 ); 19 addTest( Unit::iterate1 );
19 addTest( Unit::iterate2 ); 20 addTest( Unit::iterate2 );
21 addTest( Unit::copy );
20 } 22 }
21 23
22 virtual ~Unit() 24 virtual ~Unit()
@@ -57,6 +59,39 @@ public:
57 for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) 59 for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ )
58 unitFailed("Empty lists shouldn't be iterated through."); 60 unitFailed("Empty lists shouldn't be iterated through.");
59 } 61 }
62
63 void copy()
64 {
65 typedef Bu::Hash<Bu::FString, Bu::FString> StrHash;
66 typedef Bu::Array<StrHash> StrHashArray;
67
68 StrHash h1;
69 h1["Hi"] = "Yo";
70 h1["Bye"] = "Later";
71
72 StrHash h2;
73 h2["Test"] = "Bloop";
74 h2["Foo"] = "ooF";
75
76 StrHashArray a1;
77 a1.append( h1 );
78 a1.append( h2 );
79
80 StrHashArray a2(a1);
81
82 unitTest( a2[0].get("Hi") == "Yo" );
83 unitTest( a2[0].get("Bye") == "Later" );
84 unitTest( a2[1].get("Test") == "Bloop" );
85 unitTest( a2[1].get("Foo") == "ooF" );
86
87 StrHashArray a3;
88 a3 = a1;
89
90 unitTest( a3[0].get("Hi") == "Yo" );
91 unitTest( a3[0].get("Bye") == "Later" );
92 unitTest( a3[1].get("Test") == "Bloop" );
93 unitTest( a3[1].get("Foo") == "ooF" );
94 }
60}; 95};
61 96
62int main( int argc, char *argv[] ) 97int main( int argc, char *argv[] )
diff --git a/src/unit/hash.cpp b/src/unit/hash.cpp
index b869bdd..de4edd1 100644
--- a/src/unit/hash.cpp
+++ b/src/unit/hash.cpp
@@ -54,7 +54,17 @@ public:
54 { 54 {
55 StrStrHash h; 55 StrStrHash h;
56 h["Hi"] = "Yo"; 56 h["Hi"] = "Yo";
57 h["Bye"] = "Later";
57 unitTest( h["Hi"].getValue() == "Yo" ); 58 unitTest( h["Hi"].getValue() == "Yo" );
59
60 StrStrHash h2(h);
61 unitTest( h2["Hi"].getValue() = "Yo" );
62 unitTest( h2["Bye"].getValue() = "Later" );
63
64 StrStrHash h3;
65 h3 = h;
66 unitTest( h3["Hi"].getValue() = "Yo" );
67 unitTest( h3["Bye"].getValue() = "Later" );
58 } 68 }
59}; 69};
60 70