diff options
author | Mike Buland <eichlan@xagasoft.com> | 2008-09-24 05:52:36 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2008-09-24 05:52:36 +0000 |
commit | 6119b465b19e9be095971a33c63b0fa9a0e8a224 (patch) | |
tree | 3dafeb91d18290790417477939179526a27de38b /src/unit/array.cpp | |
parent | 5aec71241c874a2249c14025a7df1eddc1c14654 (diff) | |
download | libbu++-6119b465b19e9be095971a33c63b0fa9a0e8a224.tar.gz libbu++-6119b465b19e9be095971a33c63b0fa9a0e8a224.tar.bz2 libbu++-6119b465b19e9be095971a33c63b0fa9a0e8a224.tar.xz libbu++-6119b465b19e9be095971a33c63b0fa9a0e8a224.zip |
Wow, I realized that the Bu::Array class wasn't finished, and went ahead and
wrote it, it's pretty feature complete, index, append, iterators. You can't
delete anything yet, exactly, but that's tricky in an array anyway, basically
you just want to be able to remove elements from the end, and that's halfway
there.
Also, fixed some documentation and minor issues in Bu::Set, and made the
Bu::Archive include fewer other classes while still defining archive oprators
for them. I think I may yet move those into the headers for the classes that
are being stored instead, makes a little more sense.
I also would like to move the Exception classes out of the exceptions.h file
and into the appropriate class' files'. There still should probably be a
couple of general ones in there, or maybe just in exceptionbase.h, we'll see.
Diffstat (limited to 'src/unit/array.cpp')
-rw-r--r-- | src/unit/array.cpp | 59 |
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 | |||
11 | class Unit : public Bu::UnitSuite | ||
12 | { | ||
13 | public: | ||
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 | |||
55 | int main( int argc, char *argv[] ) | ||
56 | { | ||
57 | return Unit().run( argc, argv ); | ||
58 | } | ||
59 | |||