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/unit/array.cpp | 35 +++++++++++++++++++++++++++++++++++ src/unit/hash.cpp | 10 ++++++++++ 2 files changed, 45 insertions(+) (limited to 'src/unit') 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 @@ */ #include "bu/unitsuite.h" +#include "bu/hash.h" #include "bu/array.h" class Unit : public Bu::UnitSuite @@ -17,6 +18,7 @@ public: addTest( Unit::general ); addTest( Unit::iterate1 ); addTest( Unit::iterate2 ); + addTest( Unit::copy ); } virtual ~Unit() @@ -57,6 +59,39 @@ public: for( Bu::Array::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