Last active
June 8, 2024 01:42
-
-
Save harsh183/4941842ad71f0c0ce73adb995fb2b362 to your computer and use it in GitHub Desktop.
Java hacky test framework
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Also see