From 6119b465b19e9be095971a33c63b0fa9a0e8a224 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 24 Sep 2008 05:52:36 +0000 Subject: 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. --- src/unit/array.cpp | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/unit/array.cpp (limited to 'src/unit/array.cpp') 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 @@ +/* + * Copyright (C) 2007-2008 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include "bu/unitsuite.h" +#include "bu/array.h" + +class Unit : public Bu::UnitSuite +{ +public: + Unit() + { + setName("Array"); + addTest( Unit::general ); + addTest( Unit::iterate ); + } + + virtual ~Unit() + { + } + + void general() + { + Bu::Array ai; + + ai.append( 5 ); + ai.append( 10 ); + unitTest( ai.getSize() == 2 ); + unitTest( ai.getCapacity() == 10 ); + unitTest( ai[0] == 5 ); + unitTest( ai[1] == 10 ); + } + + void iterate() + { + Bu::Array ai; + for( int j = 0; j < 10; j++ ) + ai.append( j ); + + int j = 0; + for( Bu::Array::iterator i = ai.begin(); i != ai.end(); i++ ) + unitTest( (*i) == j++ ); + + const Bu::Array &ci = ai; + j = 0; + for( Bu::Array::const_iterator i = ci.begin(); i != ci.end(); i++ ) + unitTest( (*i) == j++ ); + } + +}; + +int main( int argc, char *argv[] ) +{ + return Unit().run( argc, argv ); +} + -- cgit v1.2.3