Skip to content

Instantly share code, notes, and snippets.

@jonluca
Last active March 15, 2018 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonluca/5ae6d0f34ae7848b360ba7e21b47b8b5 to your computer and use it in GitHub Desktop.
Save jonluca/5ae6d0f34ae7848b360ba7e21b47b8b5 to your computer and use it in GitHub Desktop.
Test Max Plus One
#define MAX_SET_TO_ONE 1000
int mVar = 0;
int mTimesSetToOne = 0;
void setVarToOne(int* mVar){
if(mVar && mTimesSetToOne < MAX_SET_TO_ONE){
*mVar = 1;
mTimesSetToOne++;
}
}
for(int i = 0; i < MAX_SET_TO_ONE; i++){
mVar = 0;
setVarToOne(&mVar);
ASSERTEQ(mVar,1); //true
}
mVar = 0;
setVarToOne(&mVar);
ASSERTEQ(mVar,0); //true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment