From f5b9d8d923822c31b98b39ba0fabae24fadc6d9c Mon Sep 17 00:00:00 2001 From: David Date: Tue, 11 Nov 2008 01:06:28 +0000 Subject: david - added operator= and copy constructor to Bu::Array, and updated unit tests to test it --- src/array.h | 11 +++++++++++ src/unit/array.cpp | 35 +++++++++++++++++++++++++++++++++++ src/unit/hash.cpp | 10 ++++++++++ 3 files changed, 56 insertions(+) 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 iSize( 0 ), iCapacity( 0 ) { + *this = src; } Array( long iSetCap ) : @@ -57,6 +58,16 @@ namespace Bu clear(); } + MyType &operator=( const MyType &src ) + { + clear(); + setCapacity( src.iCapacity ); + long iTop=src.getSize(); + for( long i=0; i::iterator i = ai.begin(); i != ai.end(); i++ ) unitFailed("Empty lists shouldn't be iterated through."); } + + void copy() + { + typedef Bu::Hash StrHash; + typedef Bu::Array StrHashArray; + + StrHash h1; + h1["Hi"] = "Yo"; + h1["Bye"] = "Later"; + + StrHash h2; + h2["Test"] = "Bloop"; + h2["Foo"] = "ooF"; + + StrHashArray a1; + a1.append( h1 ); + a1.append( h2 ); + + StrHashArray a2(a1); + + unitTest( a2[0].get("Hi") == "Yo" ); + unitTest( a2[0].get("Bye") == "Later" ); + unitTest( a2[1].get("Test") == "Bloop" ); + unitTest( a2[1].get("Foo") == "ooF" ); + + StrHashArray a3; + a3 = a1; + + unitTest( a3[0].get("Hi") == "Yo" ); + unitTest( a3[0].get("Bye") == "Later" ); + unitTest( a3[1].get("Test") == "Bloop" ); + unitTest( a3[1].get("Foo") == "ooF" ); + } }; int 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: { StrStrHash h; h["Hi"] = "Yo"; + h["Bye"] = "Later"; unitTest( h["Hi"].getValue() == "Yo" ); + + StrStrHash h2(h); + unitTest( h2["Hi"].getValue() = "Yo" ); + unitTest( h2["Bye"].getValue() = "Later" ); + + StrStrHash h3; + h3 = h; + unitTest( h3["Hi"].getValue() = "Yo" ); + unitTest( h3["Bye"].getValue() = "Later" ); } }; -- cgit v1.2.3