| 1 |
// validate that Shred.parent() correctly gets the parent shred |
| 2 |
// through multiple layers of recursion. |
| 3 |
|
| 4 |
0 => int count; // count the number of recursive calls |
| 5 |
|
| 6 |
fun void validateParent( int want_parent, int depth ) |
| 7 |
{ |
| 8 |
count++; |
| 9 |
me.parent().id() => int got_parent; |
| 10 |
|
| 11 |
if( want_parent != got_parent ) |
| 12 |
{ |
| 13 |
<<< "FAILURE, spork~ validateParent(...)'s parent shred is not matching" >>>; |
| 14 |
me.exit(); |
| 15 |
} |
| 16 |
|
| 17 |
if( depth > 1 ) |
| 18 |
{ |
| 19 |
spork~ validateParent( me.id(), depth-1 ); |
| 20 |
} |
| 21 |
samp => now; |
| 22 |
} |
| 23 |
|
| 24 |
// this should be the top-level shred (and has no parent) |
| 25 |
if( me.parent() != null ) |
| 26 |
{ |
| 27 |
<<< "FAILURE, the top-level shred should have no parent" >>>; |
| 28 |
me.exit(); |
| 29 |
} |
| 30 |
|
| 31 |
100 => int recursive_calls; |
| 32 |
spork~ validateParent( me.id(), recursive_calls ); |
| 33 |
|
| 34 |
// pass time (or yield) to let children shreds run |
| 35 |
samp => now; |
| 36 |
|
| 37 |
// check count |
| 38 |
if( count != recursive_calls ) |
| 39 |
{ |
| 40 |
<<< "FAILURE: incorrect number of recursive calls made. got:", |
| 41 |
count, "want:", recursive_calls >>>; |
| 42 |
me.exit(); |
| 43 |
} |
| 44 |
|
| 45 |
// done |
| 46 |
<<< "success" >>>; |
| 47 |
|