Changeset 26be854 for tests/exceptions


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

a bit of cleanup of the hotpotato tests

Location:
tests/exceptions
Files:
2 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 ) );
  • tests/exceptions/hotpotato_checked.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
     
    9696            if ( partner[LEFT] == &player ) {                   // stop when only one player
    9797                sout | id | " wins the Match!";
    98                 break;
     98                return;
    9999            } // exit
    100100
     
    116116                sout | "election";
    117117                sout | " -> " | id | nonl;
    118                 if ( id > getId( *election->player ) ) election->player = &player; // set umpire to highest id so far
     118                if ( id > getId( umpire ) ) &umpire = &player; // set umpire to highest id so far
    119119        resumeAt( *partner[RIGHT], *election );
    120120        disable_ehm();              // disable ehm since we can't handle execption thrown in vote here and want to poll later
    121121                vote( *partner[RIGHT] );
    122122        enable_ehm();               // enable after vote
    123         } catch ( Explode * ) {
     123        } catchResume( Explode * ) {
    124124        sout | id | " is eliminated";
    125125        if ( &player == &umpire ) {
    126126            try {
    127127                id = -1;                                        // remove from election
    128                 resumeAt( *partner[RIGHT], ExceptionInst( Election, &player ) );
     128                resumeAt( *partner[RIGHT], ExceptionInst( Election ) );
    129129                vote( *partner[RIGHT] );                // start election
    130130                checked_poll();
    131131            } catchResume( Election * election ) {
    132                 &umpire = election->player;
    133                 sout | " : umpire " | getId( *election->player );
     132                sout | " : umpire " | getId( umpire );
    134133            } // try
    135134        } // if
Note: See TracChangeset for help on using the changeset viewer.