aboutsummaryrefslogtreecommitdiff
path: root/src/unit
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/unit/array.cpp59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/unit/array.cpp b/src/unit/array.cpp
new file mode 100644
index 0000000..db29882
--- /dev/null
+++ b/src/unit/array.cpp
@@ -0,0 +1,59 @@
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/array.h"
10
11class Unit : public Bu::UnitSuite
12{
13public:
14 Unit()
15 {
16 setName("Array");
17 addTest( Unit::general );
18 addTest( Unit::iterate );
19 }
20
21 virtual ~Unit()
22 {
23 }
24
25 void general()
26 {
27 Bu::Array<int> ai;
28
29 ai.append( 5 );
30 ai.append( 10 );
31 unitTest( ai.getSize() == 2 );
32 unitTest( ai.getCapacity() == 10 );
33 unitTest( ai[0] == 5 );
34 unitTest( ai[1] == 10 );
35 }
36
37 void iterate()
38 {
39 Bu::Array<int> ai;
40 for( int j = 0; j < 10; j++ )
41 ai.append( j );
42
43 int j = 0;
44 for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ )
45 unitTest( (*i) == j++ );
46
47 const Bu::Array<int> &ci = ai;
48 j = 0;
49 for( Bu::Array<int>::const_iterator i = ci.begin(); i != ci.end(); i++ )
50 unitTest( (*i) == j++ );
51 }
52
53};
54
55int main( int argc, char *argv[] )
56{
57 return Unit().run( argc, argv );
58}
59