diff options
Diffstat (limited to '')
-rw-r--r-- | src/unit/array.unit | 174 |
1 files changed, 87 insertions, 87 deletions
diff --git a/src/unit/array.unit b/src/unit/array.unit index 6e985d8..ca85b4d 100644 --- a/src/unit/array.unit +++ b/src/unit/array.unit | |||
@@ -14,91 +14,91 @@ using Bu::sio; | |||
14 | 14 | ||
15 | suite Array | 15 | suite Array |
16 | { | 16 | { |
17 | test general | 17 | test general |
18 | { | 18 | { |
19 | Bu::Array<int> ai; | 19 | Bu::Array<int> ai; |
20 | 20 | ||
21 | ai.append( 5 ); | 21 | ai.append( 5 ); |
22 | ai.append( 10 ); | 22 | ai.append( 10 ); |
23 | unitTest( ai.getSize() == 2 ); | 23 | unitTest( ai.getSize() == 2 ); |
24 | unitTest( ai.getCapacity() == 10 ); | 24 | unitTest( ai.getCapacity() == 10 ); |
25 | unitTest( ai[0] == 5 ); | 25 | unitTest( ai[0] == 5 ); |
26 | unitTest( ai[1] == 10 ); | 26 | unitTest( ai[1] == 10 ); |
27 | } | 27 | } |
28 | 28 | ||
29 | test iterate1 | 29 | test iterate1 |
30 | { | 30 | { |
31 | Bu::Array<int> ai; | 31 | Bu::Array<int> ai; |
32 | for( int j = 0; j < 10; j++ ) | 32 | for( int j = 0; j < 10; j++ ) |
33 | ai.append( j ); | 33 | ai.append( j ); |
34 | 34 | ||
35 | int j = 0; | 35 | int j = 0; |
36 | for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) | 36 | for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) |
37 | unitTest( (*i) == j++ ); | 37 | unitTest( (*i) == j++ ); |
38 | unitTest( j == 10 ); | 38 | unitTest( j == 10 ); |
39 | 39 | ||
40 | const Bu::Array<int> &ci = ai; | 40 | const Bu::Array<int> &ci = ai; |
41 | j = 0; | 41 | j = 0; |
42 | for( Bu::Array<int>::const_iterator i = ci.begin(); i; i++ ) | 42 | for( Bu::Array<int>::const_iterator i = ci.begin(); i; i++ ) |
43 | unitTest( (*i) == j++ ); | 43 | unitTest( (*i) == j++ ); |
44 | unitTest( j == 10 ); | 44 | unitTest( j == 10 ); |
45 | } | 45 | } |
46 | 46 | ||
47 | test iterate2 | 47 | test iterate2 |
48 | { | 48 | { |
49 | Bu::Array<int> ai; | 49 | Bu::Array<int> ai; |
50 | for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) | 50 | for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) |
51 | unitFailed("Empty lists shouldn't be iterated through."); | 51 | unitFailed("Empty lists shouldn't be iterated through."); |
52 | for( Bu::Array<int>::iterator i = ai.begin(); i; i++ ) | 52 | for( Bu::Array<int>::iterator i = ai.begin(); i; i++ ) |
53 | unitFailed("Empty lists shouldn't be iterated through."); | 53 | unitFailed("Empty lists shouldn't be iterated through."); |
54 | } | 54 | } |
55 | 55 | ||
56 | test copy | 56 | test copy |
57 | { | 57 | { |
58 | typedef Bu::Hash<Bu::String, Bu::String> StrHash; | 58 | typedef Bu::Hash<Bu::String, Bu::String> StrHash; |
59 | typedef Bu::Array<StrHash> StrHashArray; | 59 | typedef Bu::Array<StrHash> StrHashArray; |
60 | 60 | ||
61 | StrHash h1; | 61 | StrHash h1; |
62 | h1["Hi"] = "Yo"; | 62 | h1["Hi"] = "Yo"; |
63 | h1["Bye"] = "Later"; | 63 | h1["Bye"] = "Later"; |
64 | 64 | ||
65 | StrHash h2; | 65 | StrHash h2; |
66 | h2["Test"] = "Bloop"; | 66 | h2["Test"] = "Bloop"; |
67 | h2["Foo"] = "ooF"; | 67 | h2["Foo"] = "ooF"; |
68 | 68 | ||
69 | StrHashArray a1; | 69 | StrHashArray a1; |
70 | a1.append( h1 ); | 70 | a1.append( h1 ); |
71 | a1.append( h2 ); | 71 | a1.append( h2 ); |
72 | 72 | ||
73 | StrHashArray a2(a1); | 73 | StrHashArray a2(a1); |
74 | 74 | ||
75 | unitTest( a2[0].get("Hi") == "Yo" ); | 75 | unitTest( a2[0].get("Hi") == "Yo" ); |
76 | unitTest( a2[0].get("Bye") == "Later" ); | 76 | unitTest( a2[0].get("Bye") == "Later" ); |
77 | unitTest( a2[1].get("Test") == "Bloop" ); | 77 | unitTest( a2[1].get("Test") == "Bloop" ); |
78 | unitTest( a2[1].get("Foo") == "ooF" ); | 78 | unitTest( a2[1].get("Foo") == "ooF" ); |
79 | 79 | ||
80 | StrHashArray a3; | 80 | StrHashArray a3; |
81 | a3 = a1; | 81 | a3 = a1; |
82 | 82 | ||
83 | unitTest( a3[0].get("Hi") == "Yo" ); | 83 | unitTest( a3[0].get("Hi") == "Yo" ); |
84 | unitTest( a3[0].get("Bye") == "Later" ); | 84 | unitTest( a3[0].get("Bye") == "Later" ); |
85 | unitTest( a3[1].get("Test") == "Bloop" ); | 85 | unitTest( a3[1].get("Test") == "Bloop" ); |
86 | unitTest( a3[1].get("Foo") == "ooF" ); | 86 | unitTest( a3[1].get("Foo") == "ooF" ); |
87 | } | 87 | } |
88 | 88 | ||
89 | test insert | 89 | test insert |
90 | { | 90 | { |
91 | Bu::Array<int> aInts; | 91 | Bu::Array<int> aInts; |
92 | aInts.insert( aInts.end(), 4 ); | 92 | aInts.insert( aInts.end(), 4 ); |
93 | aInts.insert( aInts.begin(), 1 ); | 93 | aInts.insert( aInts.begin(), 1 ); |
94 | aInts.insert( aInts.end(), 5 ); | 94 | aInts.insert( aInts.end(), 5 ); |
95 | aInts.insert( aInts.begin()+1, 3 ); | 95 | aInts.insert( aInts.begin()+1, 3 ); |
96 | aInts.insert( aInts.begin()+1, 2 ); | 96 | aInts.insert( aInts.begin()+1, 2 ); |
97 | aInts.insert( aInts.begin(), 0 ); | 97 | aInts.insert( aInts.begin(), 0 ); |
98 | 98 | ||
99 | for( int j = 0; j < 6; j++ ) | 99 | for( int j = 0; j < 6; j++ ) |
100 | { | 100 | { |
101 | unitTest( aInts[j] == j ); | 101 | unitTest( aInts[j] == j ); |
102 | } | 102 | } |
103 | } | 103 | } |
104 | } | 104 | } |