summaryrefslogtreecommitdiff
path: root/src/unit/array.cpp
blob: db2988254640b4e420603f8a78b95a10eb55f178 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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<int> 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<int> ai;
		for( int j = 0; j < 10; j++ )
			ai.append( j );

		int j = 0;
		for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ )
			unitTest( (*i) == j++ );
		
		const Bu::Array<int> &ci = ai;
		j = 0;
		for( Bu::Array<int>::const_iterator i = ci.begin(); i != ci.end(); i++ )
			unitTest( (*i) == j++ );
	}
	
};

int main( int argc, char *argv[] )
{
	return Unit().run( argc, argv );
}