diff options
Diffstat (limited to 'src/unit/array.unit')
| -rw-r--r-- | src/unit/array.unit | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/src/unit/array.unit b/src/unit/array.unit new file mode 100644 index 0000000..d5fc573 --- /dev/null +++ b/src/unit/array.unit | |||
| @@ -0,0 +1,80 @@ | |||
| 1 | // vim: syntax=cpp | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2007-2008 Xagasoft, All rights reserved. | ||
| 4 | * | ||
| 5 | * This file is part of the libbu++ library and is released under the | ||
| 6 | * terms of the license contained in the file LICENSE. | ||
| 7 | */ | ||
| 8 | |||
| 9 | #include "bu/hash.h" | ||
| 10 | #include "bu/array.h" | ||
| 11 | |||
| 12 | {=Init} | ||
| 13 | |||
| 14 | {%general} | ||
| 15 | { | ||
| 16 | Bu::Array<int> ai; | ||
| 17 | |||
| 18 | ai.append( 5 ); | ||
| 19 | ai.append( 10 ); | ||
| 20 | unitTest( ai.getSize() == 2 ); | ||
| 21 | unitTest( ai.getCapacity() == 10 ); | ||
| 22 | unitTest( ai[0] == 5 ); | ||
| 23 | unitTest( ai[1] == 10 ); | ||
| 24 | } | ||
| 25 | |||
| 26 | {%iterate1} | ||
| 27 | { | ||
| 28 | Bu::Array<int> ai; | ||
| 29 | for( int j = 0; j < 10; j++ ) | ||
| 30 | ai.append( j ); | ||
| 31 | |||
| 32 | int j = 0; | ||
| 33 | for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) | ||
| 34 | unitTest( (*i) == j++ ); | ||
| 35 | |||
| 36 | const Bu::Array<int> &ci = ai; | ||
| 37 | j = 0; | ||
| 38 | for( Bu::Array<int>::const_iterator i = ci.begin(); i != ci.end(); i++ ) | ||
| 39 | unitTest( (*i) == j++ ); | ||
| 40 | } | ||
| 41 | |||
| 42 | {%iterate2} | ||
| 43 | { | ||
| 44 | Bu::Array<int> ai; | ||
| 45 | for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) | ||
| 46 | unitFailed("Empty lists shouldn't be iterated through."); | ||
| 47 | } | ||
| 48 | |||
| 49 | {%copy} | ||
| 50 | { | ||
| 51 | typedef Bu::Hash<Bu::FString, Bu::FString> StrHash; | ||
| 52 | typedef Bu::Array<StrHash> StrHashArray; | ||
| 53 | |||
| 54 | StrHash h1; | ||
| 55 | h1["Hi"] = "Yo"; | ||
| 56 | h1["Bye"] = "Later"; | ||
| 57 | |||
| 58 | StrHash h2; | ||
| 59 | h2["Test"] = "Bloop"; | ||
| 60 | h2["Foo"] = "ooF"; | ||
| 61 | |||
| 62 | StrHashArray a1; | ||
| 63 | a1.append( h1 ); | ||
| 64 | a1.append( h2 ); | ||
| 65 | |||
| 66 | StrHashArray a2(a1); | ||
| 67 | |||
| 68 | unitTest( a2[0].get("Hi") == "Yo" ); | ||
| 69 | unitTest( a2[0].get("Bye") == "Later" ); | ||
| 70 | unitTest( a2[1].get("Test") == "Bloop" ); | ||
| 71 | unitTest( a2[1].get("Foo") == "ooF" ); | ||
| 72 | |||
| 73 | StrHashArray a3; | ||
| 74 | a3 = a1; | ||
| 75 | |||
| 76 | unitTest( a3[0].get("Hi") == "Yo" ); | ||
| 77 | unitTest( a3[0].get("Bye") == "Later" ); | ||
| 78 | unitTest( a3[1].get("Test") == "Bloop" ); | ||
| 79 | unitTest( a3[1].get("Foo") == "ooF" ); | ||
| 80 | } | ||
