summaryrefslogtreecommitdiff
path: root/src/unit/array.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/unit/array.cpp101
1 files changed, 0 insertions, 101 deletions
diff --git a/src/unit/array.cpp b/src/unit/array.cpp
deleted file mode 100644
index f7dc0ae..0000000
--- a/src/unit/array.cpp
+++ /dev/null
@@ -1,101 +0,0 @@
1/*
2 * Copyright (C) 2007-2008 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#include "bu/unitsuite.h"
9#include "bu/hash.h"
10#include "bu/array.h"
11
12class Unit : public Bu::UnitSuite
13{
14public:
15 Unit()
16 {
17 setName("Array");
18 addTest( Unit::general );
19 addTest( Unit::iterate1 );
20 addTest( Unit::iterate2 );
21 addTest( Unit::copy );
22 }
23
24 virtual ~Unit()
25 {
26 }
27
28 void general()
29 {
30 Bu::Array<int> ai;
31
32 ai.append( 5 );
33 ai.append( 10 );
34 unitTest( ai.getSize() == 2 );
35 unitTest( ai.getCapacity() == 10 );
36 unitTest( ai[0] == 5 );
37 unitTest( ai[1] == 10 );
38 }
39
40 void iterate1()
41 {
42 Bu::Array<int> ai;
43 for( int j = 0; j < 10; j++ )
44 ai.append( j );
45
46 int j = 0;
47 for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ )
48 unitTest( (*i) == j++ );
49
50 const Bu::Array<int> &ci = ai;
51 j = 0;
52 for( Bu::Array<int>::const_iterator i = ci.begin(); i != ci.end(); i++ )
53 unitTest( (*i) == j++ );
54 }
55
56 void iterate2()
57 {
58 Bu::Array<int> ai;
59 for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ )
60 unitFailed("Empty lists shouldn't be iterated through.");
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 }
95};
96
97int main( int argc, char *argv[] )
98{
99 return Unit().run( argc, argv );
100}
101