aboutsummaryrefslogtreecommitdiff
path: root/src/unit/array.unit
blob: daedd5f2be9a7bcfe9c5a076d4b42cf0522e1490 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
// vim: syntax=cpp
/*
 * 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/hash.h"
#include "bu/array.h"

{=Init}

{%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 );
}

{%iterate1}
{
	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++ );
	unitTest( j == 10 );
	
	const Bu::Array<int> &ci = ai;
	j = 0;
	for( Bu::Array<int>::const_iterator i = ci.begin(); i; i++ )
		unitTest( (*i) == j++ );
	unitTest( j == 10 );
}

{%iterate2}
{
	Bu::Array<int> ai;
	for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ )
		unitFailed("Empty lists shouldn't be iterated through.");
	for( Bu::Array<int>::iterator i = ai.begin(); i; i++ )
		unitFailed("Empty lists shouldn't be iterated through.");
}

{%copy}
{
	typedef Bu::Hash<Bu::FString, Bu::FString> StrHash;
	typedef Bu::Array<StrHash> StrHashArray;

	StrHash h1;
	h1["Hi"] = "Yo";
	h1["Bye"] = "Later";

	StrHash h2;
	h2["Test"] = "Bloop";
	h2["Foo"] = "ooF";

	StrHashArray a1;
	a1.append( h1 );
	a1.append( h2 );

	StrHashArray a2(a1);

	unitTest( a2[0].get("Hi") == "Yo" );
	unitTest( a2[0].get("Bye") == "Later" );
	unitTest( a2[1].get("Test") == "Bloop" );
	unitTest( a2[1].get("Foo") == "ooF" );

	StrHashArray a3;
	a3 = a1;
	
	unitTest( a3[0].get("Hi") == "Yo" );
	unitTest( a3[0].get("Bye") == "Later" );
	unitTest( a3[1].get("Test") == "Bloop" );
	unitTest( a3[1].get("Foo") == "ooF" );
}