Created
September 18, 2016 18:31
-
-
Save jkeesh/c26a2c3837b8c2a3b8514609611e17cb to your computer and use it in GitHub Desktop.
SnackPack Grader
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
import java.util.*; | |
public class Grader | |
{ | |
public static void runInputTest(Autograder grader, String[] inputs, String message) | |
{ | |
// Create a student program | |
SnackPack studentProgram = new SnackPack(); | |
// Create a solution program | |
SnackPackSolution solutionProgram = new SnackPackSolution(); | |
// Set the inputs to our string array for both programs | |
studentProgram.setInputs(inputs); | |
solutionProgram.setInputs(inputs); | |
// Run both programs | |
studentProgram.run(); | |
solutionProgram.run(); | |
// Save the output arraylist for later | |
ArrayList<String> studentOutputList = grader.getOutputArrayList("SnackPack"); | |
ArrayList<String> solutionOutputList = grader.getOutputArrayList("SnackPackSolution"); | |
// Get the string output from the student and reference solution | |
String studentOutput = grader.getOutput("SnackPack"); | |
String solutionOutput = grader.getOutput("SnackPackSolution"); | |
// Add a test to the grader | |
grader.assertEqual(message, studentOutput, solutionOutput, "Great!", "Not quite."); | |
grader.clearOutput(); | |
} | |
public static void main(String [] args) | |
{ | |
Autograder grader = new Autograder(); | |
runInputTest(grader, new String[]{"0","0","0","0","0"}, "Input: 0,0,0,0,0"); | |
runInputTest(grader, new String[]{"0","1","0","0","0"}, "Input: 0,1,0,0,0"); | |
runInputTest(grader, new String[]{"3","2","1","1","1"}, "Input: 3,2,1,1,1"); | |
System.out.println(grader); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment