Skip to content

Instantly share code, notes, and snippets.

@harsh183
Created October 21, 2020 22:58
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 harsh183/4941842ad71f0c0ce73adb995fb2b362 to your computer and use it in GitHub Desktop.
Save harsh183/4941842ad71f0c0ce73adb995fb2b362 to your computer and use it in GitHub Desktop.
Java hacky test framework
// try this out on jeed playground at https://cs125.cs.illinois.edu/
interface TestCase {
boolean test();
}
// print title if case fails
void checkCase(String title, TestCase t) {
if (t.test() == false) {
System.out.println("Failed: " + title);
}
}
int add(int a, int b) {
return a + b;
}
checkCase("Adding nothing gives the same number", () -> add(5, 0) == 5);
checkCase("Adding 0 to 0 gives 0", () -> add(0, 0) == 0);
checkCase("Testing positive + positive", () -> add(1, 1) == 2);
checkCase("Testing positive + negative", () -> add(2, -1) == 1);
checkCase("Testing negative + negative", () -> add(-1, -1) == -2);
@harsh183
Copy link
Author

harsh183 commented Oct 21, 2020

MIT License

@harsh183
Copy link
Author

Also see

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment