Skip to content

Instantly share code, notes, and snippets.

@science
Forked from douglasnomizo/gist:6425124
Last active December 22, 2015 05:48
Show Gist options
  • Save science/6426042 to your computer and use it in GitHub Desktop.
Save science/6426042 to your computer and use it in GitHub Desktop.
import java.util.HashMap;
public class CodeRunner {
TestClass testClass = new TestClass();
String answer_format = "Test1: %s\nTest2: %s";
static String default_output_template = "Correct answers:\nTest1=%s\nTest2=%s\n";
public static void main(String[] args) {
CodeRunner code = new CodeRunner();
HashMap answers = code.tests();
System.out.printf(default_output_template, answers.get("1"), answers.get("2"));
}
public HashMap tests() {
HashMap answers = new HashMap();
answers.put("1", test_case1());
answers.put("2", test_case2());
return answers;
}
boolean test_case1() {
return testClass.main(1, 2) == 2;
}
boolean test_case2() {
return testClass.main(1, 2) == 3;
}
class TestClass {
public int main(int n1, int n2) {
return n1 + n2;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment