Ignore:
Timestamp:
Oct 1, 2023, 12:25:55 PM (9 months ago)
Author:
caparsons <caparson@…>
Branches:
master
Children:
7a925a41
Parents:
fd775ae
Message:

a bit of cleanup of the hotpotato tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/exceptions/hotpotato.cfa

    rfd775ae r26be854  
    3535ExceptionDecl( Explode );
    3636ExceptionDecl( Terminate, Player * victim; );
    37 ExceptionDecl( Election, Player * player; );
     37ExceptionDecl( Election );
    3838ExceptionDecl( cmd_error ); // convert(...) throws out_of_range or invalid_argument
    3939
     
    4747void countdown( Potato & potato ) with(potato) {
    4848        timer += 1;
    49         if ( timer == deadline ) throw ExceptionInst( Explode );
     49        if ( timer == deadline ) throwResume ExceptionInst( Explode );
    5050} // countdown
    5151
     
    8686void main( Player & player ) with(player) {
    8787    suspend;                                                                    // return immediately after establishing starter
    88    
    8988        try {
    9089        for ( ;; ) {
     
    9392            if ( partner[LEFT] == &player ) {                   // stop when only one player
    9493                sout | id | " wins the Match!";
    95                 break;
     94                return;
    9695            } // exit
    9796           
     
    112111                sout | "election";
    113112                sout | " -> " | id | nonl;
    114                 if ( id > getId( *election->player ) ) election->player = &player; // set umpire to highest id so far
     113                if ( id > getId( umpire ) ) &umpire = &player; // set umpire to highest id so far
    115114                vote( *partner[RIGHT], *election );
    116         } catch ( Explode * ) {
     115        } catchResume ( Explode * ) {
    117116        sout | id | " is eliminated";
    118117        if ( &player == &umpire ) {
    119118            id = -1;                                    // remove from election
    120             vote( *partner[RIGHT], ExceptionInst( Election, &player ) );                // start election
    121             try {
    122                 poll();
    123             } catchResume( Election * election ) {
    124                 &umpire = election->player;
    125                 sout | " : umpire " | getId( *election->player );
    126             }
     119            vote( *partner[RIGHT], ExceptionInst( Election ) );         // start election
     120            try { poll(); } catchResume( Election * election ) {} // handle end of election
     121            sout | " : umpire " | getId( umpire );
    127122        } // if
    128123        resumeAt( umpire, ExceptionInst( Terminate, &player ) );
Note: See TracChangeset for help on using the changeset viewer.