summaryrefslogtreecommitdiff
path: root/src/unit/array.unit
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-05-15 07:44:10 +0000
committerMike Buland <eichlan@xagasoft.com>2010-05-15 07:44:10 +0000
commit306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68 (patch)
tree32c35f8507edb4ea403f4ebc4b625c1096f6f384 /src/unit/array.unit
parent11413d228bae2919fe69c83b74c7ff49209dd65a (diff)
downloadlibbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.tar.gz
libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.tar.bz2
libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.tar.xz
libbu++-306b80c1cf9ab490a83b36d3e7cf07e09f9e5d68.zip
mkunit.sh was a little dumb, it didn't handle a number of things correctly.
I've written a new program that basically does the same thing, only it's much more clever, and does many more of the translations and conversions better, including the #line directives. Also, I dropped nids, we don't need it anymore. But now I'm ready to write some serious tests for myriad.
Diffstat (limited to 'src/unit/array.unit')
-rw-r--r--src/unit/array.unit121
1 files changed, 61 insertions, 60 deletions
diff --git a/src/unit/array.unit b/src/unit/array.unit
index ad249ef..1493033 100644
--- a/src/unit/array.unit
+++ b/src/unit/array.unit
@@ -9,76 +9,77 @@
9#include "bu/hash.h" 9#include "bu/hash.h"
10#include "bu/array.h" 10#include "bu/array.h"
11 11
12{=Init} 12suite Array
13
14{%general}
15{ 13{
16 Bu::Array<int> ai; 14 test general
15 {
16 Bu::Array<int> ai;
17 17
18 ai.append( 5 ); 18 ai.append( 5 );
19 ai.append( 10 ); 19 ai.append( 10 );
20 unitTest( ai.getSize() == 2 ); 20 unitTest( ai.getSize() == 2 );
21 unitTest( ai.getCapacity() == 10 ); 21 unitTest( ai.getCapacity() == 10 );
22 unitTest( ai[0] == 5 ); 22 unitTest( ai[0] == 5 );
23 unitTest( ai[1] == 10 ); 23 unitTest( ai[1] == 10 );
24} 24 }
25 25
26{%iterate1} 26 test iterate1
27{ 27 {
28 Bu::Array<int> ai; 28 Bu::Array<int> ai;
29 for( int j = 0; j < 10; j++ ) 29 for( int j = 0; j < 10; j++ )
30 ai.append( j ); 30 ai.append( j );
31 31
32 int j = 0; 32 int j = 0;
33 for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) 33 for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ )
34 unitTest( (*i) == j++ ); 34 unitTest( (*i) == j++ );
35 unitTest( j == 10 ); 35 unitTest( j == 10 );
36 36
37 const Bu::Array<int> &ci = ai; 37 const Bu::Array<int> &ci = ai;
38 j = 0; 38 j = 0;
39 for( Bu::Array<int>::const_iterator i = ci.begin(); i; i++ ) 39 for( Bu::Array<int>::const_iterator i = ci.begin(); i; i++ )
40 unitTest( (*i) == j++ ); 40 unitTest( (*i) == j++ );
41 unitTest( j == 10 ); 41 unitTest( j == 10 );
42} 42 }
43 43
44{%iterate2} 44 test iterate2
45{ 45 {
46 Bu::Array<int> ai; 46 Bu::Array<int> ai;
47 for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ ) 47 for( Bu::Array<int>::iterator i = ai.begin(); i != ai.end(); i++ )
48 unitFailed("Empty lists shouldn't be iterated through."); 48 unitFailed("Empty lists shouldn't be iterated through.");
49 for( Bu::Array<int>::iterator i = ai.begin(); i; i++ ) 49 for( Bu::Array<int>::iterator i = ai.begin(); i; i++ )
50 unitFailed("Empty lists shouldn't be iterated through."); 50 unitFailed("Empty lists shouldn't be iterated through.");
51} 51 }
52 52
53{%copy} 53 test copy
54{ 54 {
55 typedef Bu::Hash<Bu::FString, Bu::FString> StrHash; 55 typedef Bu::Hash<Bu::FString, Bu::FString> StrHash;
56 typedef Bu::Array<StrHash> StrHashArray; 56 typedef Bu::Array<StrHash> StrHashArray;
57 57
58 StrHash h1; 58 StrHash h1;
59 h1["Hi"] = "Yo"; 59 h1["Hi"] = "Yo";
60 h1["Bye"] = "Later"; 60 h1["Bye"] = "Later";
61 61
62 StrHash h2; 62 StrHash h2;
63 h2["Test"] = "Bloop"; 63 h2["Test"] = "Bloop";
64 h2["Foo"] = "ooF"; 64 h2["Foo"] = "ooF";
65 65
66 StrHashArray a1; 66 StrHashArray a1;
67 a1.append( h1 ); 67 a1.append( h1 );
68 a1.append( h2 ); 68 a1.append( h2 );
69 69
70 StrHashArray a2(a1); 70 StrHashArray a2(a1);
71 71
72 unitTest( a2[0].get("Hi") == "Yo" ); 72 unitTest( a2[0].get("Hi") == "Yo" );
73 unitTest( a2[0].get("Bye") == "Later" ); 73 unitTest( a2[0].get("Bye") == "Later" );
74 unitTest( a2[1].get("Test") == "Bloop" ); 74 unitTest( a2[1].get("Test") == "Bloop" );
75 unitTest( a2[1].get("Foo") == "ooF" ); 75 unitTest( a2[1].get("Foo") == "ooF" );
76 76
77 StrHashArray a3; 77 StrHashArray a3;
78 a3 = a1; 78 a3 = a1;
79 79
80 unitTest( a3[0].get("Hi") == "Yo" ); 80 unitTest( a3[0].get("Hi") == "Yo" );
81 unitTest( a3[0].get("Bye") == "Later" ); 81 unitTest( a3[0].get("Bye") == "Later" );
82 unitTest( a3[1].get("Test") == "Bloop" ); 82 unitTest( a3[1].get("Test") == "Bloop" );
83 unitTest( a3[1].get("Foo") == "ooF" ); 83 unitTest( a3[1].get("Foo") == "ooF" );
84 }
84} 85}