| 1 |
// test array.getKeys() |
| 2 |
|
| 3 |
true => int passing; |
| 4 |
|
| 5 |
int a[0]; |
| 6 |
string a_keys[0]; |
| 7 |
|
| 8 |
a.getKeys(a_keys); |
| 9 |
|
| 10 |
if( a_keys.size() != 0 ) |
| 11 |
{ |
| 12 |
<<< "key array should be empty" >>>; |
| 13 |
false => passing; |
| 14 |
} |
| 15 |
|
| 16 |
float b[0]; |
| 17 |
string b_keys[0]; |
| 18 |
["key1", "key2"] @=> string b_want[]; |
| 19 |
|
| 20 |
1 => b["key1"]; |
| 21 |
2 => b["key2"]; |
| 22 |
|
| 23 |
b.getKeys(b_keys); |
| 24 |
|
| 25 |
checkKeys(b_keys, b_want) && passing => passing; |
| 26 |
|
| 27 |
vec3 c[0]; |
| 28 |
string c_keys[0]; |
| 29 |
["key2"] @=> string c_want[]; |
| 30 |
|
| 31 |
@(0,0,0) => c["key1"]; |
| 32 |
@(0,0,1) => c["key2"]; |
| 33 |
@(0,0,2) => c["key1"]; |
| 34 |
@(0,0,3) => c["key1"]; |
| 35 |
c.erase("key1"); |
| 36 |
|
| 37 |
c.getKeys(c_keys); |
| 38 |
checkKeys(c_keys, c_want) && passing => passing; |
| 39 |
|
| 40 |
string c_keys2[0]; |
| 41 |
c.getKeys(c_keys2); |
| 42 |
checkKeys(c_keys2, c_want) && passing => passing; |
| 43 |
|
| 44 |
if( passing ) <<< "success" >>>; |
| 45 |
|
| 46 |
fun int checkKeys(string got[], string want[]) |
| 47 |
{ |
| 48 |
if( got.size() != want.size() ) |
| 49 |
{ |
| 50 |
printFailure(got, want); |
| 51 |
return false; |
| 52 |
} |
| 53 |
|
| 54 |
true => int passing; |
| 55 |
for( 0 => int i; i < want.size(); i++ ) |
| 56 |
{ |
| 57 |
false => int contains; |
| 58 |
for( 0 => int j; j < got.size(); j++ ) |
| 59 |
{ |
| 60 |
if (got[i] == want[j]) |
| 61 |
{ |
| 62 |
true => contains; |
| 63 |
} |
| 64 |
} |
| 65 |
if( !contains ) false => passing; |
| 66 |
} |
| 67 |
|
| 68 |
if (!passing) |
| 69 |
{ |
| 70 |
printFailure(got, want); |
| 71 |
return false; |
| 72 |
} |
| 73 |
|
| 74 |
return true; |
| 75 |
} |
| 76 |
|
| 77 |
fun void printFailure( string got[], string want[] ) |
| 78 |
{ |
| 79 |
<<< "failure in get_keys(), got:" >>>; |
| 80 |
for( 0 => int i; i < got.size(); i++ ) <<< got[i] >>>; |
| 81 |
<<< "want:" >>>; |
| 82 |
for( 0 => int i; i < want.size(); i++ ) <<< want[i] >>>; |
| 83 |
} |