Class Autograder
- java.lang.Object
-
- Autograder
-
- Direct Known Subclasses:
DrawingAutograder,PictureAutograder
public class Autograder extends java.lang.ObjectClasss representing an autograder. It's main method is the running of the autograder and instances can be made to store all important information.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classAutograder.CallableMethodA Class representing a method that can be called.classAutograder.StopExitSecurityManager
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringCHECKSTYLE_JARThe location of the checkstyle Jar.static java.lang.StringCHECKSTYLE_LISTEN_XMLstatic java.lang.StringCHECKSTYLE_XMLThe location of the checkstyle xml.protected intdiffNumThe current test number we are on.protected doublemaxScoreThe value of each test.protected java.lang.StringvisibilityThe visibilty for the current gradescope test.
-
Constructor Summary
Constructors Constructor Description Autograder()The Autograder class constructor.Autograder(int visible, double score)The Autograder class constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static voidaddConverter(brandon.convert.ClassConverter c)Method to add a user written converter to the autograder.voidaddTestResult(java.lang.String name, boolean success, java.lang.String extraOutput)Method to add a seperately made test to the results.voidaddTestResult(jh61b.grader.TestResult t)Method to add a seperately made test to the results.booleanclassDoesNotHaveMultipleScanners(java.lang.String name)Runs a test to make sure that the student code does not use multiple Scanners..booleanclassDoesNotUseArrayList(java.lang.String name)Runs a test to make sure that the student code does not use ArrayLists.booleanclassDoesNotUsePackages(java.lang.String name)Runs a test to make sure that the student code does not use package declarations.voidcomparisonTest(java.lang.String programName, java.lang.String input, java.lang.Object caller)Runs a single test comparing the output of a method..voidcomparisonTests(java.lang.String programName, int testCount, java.lang.Object caller)Runs all the comparison tests for a specific file.intcompile(java.lang.String fileName)Method to compile a java file for you.voidcompTest(java.lang.String programName, java.lang.reflect.Method m, boolean ret, java.lang.Object caller, java.lang.Object... args)Method to do a test comparing the ouptut of the students method against an expected value.voidcompTest(java.lang.String programName, java.lang.reflect.Method m, char ret, java.lang.Object caller, java.lang.Object... args)Method to do a test comparing the ouptut of the students method against an expected value.voidcompTest(java.lang.String programName, java.lang.reflect.Method m, double ret, java.lang.Object caller, java.lang.Object... args)Method to do a test comparing the ouptut of the students method against an expected value.voidcompTest(java.lang.String programName, java.lang.reflect.Method m, float ret, java.lang.Object caller, java.lang.Object... args)Method to do a test comparing the ouptut of the students method against an expected value.voidcompTest(java.lang.String programName, java.lang.reflect.Method m, int ret, java.lang.Object caller, java.lang.Object... args)Method to do a test comparing the ouptut of the students method against an expected value.voidcompTest(java.lang.String programName, java.lang.reflect.Method m, long ret, java.lang.Object caller, java.lang.Object... args)Method to do a test comparing the ouptut of the students method against an expected value.voidcompTest(java.lang.String programName, java.lang.reflect.Method m, java.lang.Object ret, java.lang.Object caller, java.lang.String stdinput, java.lang.Object... args)Method to do a test comparing the ouptut of the students method against an expected value.doublecurrentScore()A method to get the current single test score.booleandiffFiles(java.lang.String firstFile, java.lang.String secondFile)Test to compare two files.static java.lang.Class<?>[]getClasses(java.lang.String[] args)Method to convert the string paramaters to Class<?>[].static java.lang.reflect.MethodgetMethod(java.lang.String programName, java.lang.String methodName, java.lang.Class<?>... paramTypes)Method to get a method.static java.lang.reflect.MethodgetMethod(java.lang.String programName, java.lang.String methodName, java.lang.String[] argTypes)Method to get a method.static intgetModifiers(java.lang.String[] mods)Method to take a list of string modifiers and turn them into a representative integer.java.lang.StringgetVisibility()A method to get the current visibility.booleanhasConstructorTest(java.lang.String className, java.lang.Class<?>[] argTypes, int modifiers, boolean checkModifiers)Method to test whether a specific constructor exists.booleanhasConstructorTest(java.lang.String className, java.lang.String[] argTypes, java.lang.String[] modifiers, boolean checkModifiers)Method to test whether a specific constructor exists.booleanhasFieldTest(java.lang.String programName, java.lang.String fieldName, java.lang.Class<?> fieldType, int modifiers, boolean checkModifiers)Runs a test to make sure that the student has an expected field..booleanhasFieldTest(java.lang.String programName, java.lang.String fieldName, java.lang.String fieldType, java.lang.String[] modifiers, boolean checkModifiers)Runs a test to make sure that the student has an expected field..booleanhasMethodsTest(java.lang.String className, java.lang.String interfaceName, boolean matchModifiers)Test to check whether a class complies with an interface.booleanhasMethodTest(java.lang.String programName, java.lang.String methodName, java.lang.Class<?>[] argTypes, java.lang.Class<?> returnType, boolean checkReturn, int modifiers, boolean checkModifiers)Method to test whether a method exists.booleanhasMethodTest(java.lang.String programName, java.lang.String methodName, java.lang.String[] argTypes, java.lang.String returnType, boolean checkReturn, java.lang.String[] modifiers, boolean checkModifiers)Method to test whether a method exists.booleanhasOverriddenMethodTest(java.lang.String programName, java.lang.String methodName, java.lang.Class<?>[] argTypes, java.lang.Class<?> returnType, boolean checkReturn, int modifiers, boolean checkModifiers)Method to test whether a overriden method exists.booleanhasOverriddenMethodTest(java.lang.String programName, java.lang.String methodName, java.lang.String[] argTypes, java.lang.String returnType, boolean checkReturn, java.lang.String[] modifiers, boolean checkModifiers)Method to test whether an overriden method exists.voidjunitTests(java.lang.String programName)This is a method to run a set of junit tests on a class.voidlogFileDiffTest(java.lang.String name, java.lang.String logFile, java.lang.String sampleLogFile, java.lang.String inFile, boolean ignoreWhitespace)Runs a diff test for a specific java program comparing resulting file output.voidlogFileDiffTests(java.lang.String name, int count, int numVisible, java.lang.String logFile, java.lang.String sampleLogFile, boolean ignoreWhitespace)Runs all the diff tests for a specific java program comparing resulting file output.voidlogFileDiffTests(java.lang.String name, int count, java.lang.String logFile, java.lang.String sampleLogFile, boolean ignoreWhitespace)Runs all the diff tests for a specific java program comparing resulting file output.java.lang.ObjectrunMethodWithTimeout(java.lang.reflect.Method m, java.lang.Object caller, java.lang.Object... args)voidsetScore(double score)A method to set the point value of the tests.voidsetTimeout(long timeout)Setter for the amount of time to wait before timing out while running student code.voidsetVisibility(int choice)Setter of the visibility of the tests.static java.lang.StringstackTraceToString(java.lang.Exception es)voidstdOutDiffTest(java.lang.String name, java.lang.String inFile, boolean sampleFile, boolean ignoreWhitespace)Runs a diff test on the std output of a specific java program.voidstdOutDiffTests(java.lang.String name, int count, boolean sampleFile, boolean ignoreWhitespace)Runs all the diff tests for a specific file.voidstdOutDiffTests(java.lang.String name, int count, boolean sampleFile, boolean ignoreWhitespace, int numVisible)Runs all the diff tests for a specific file.voidtestCheckstyle(java.lang.String programName)Checks if checkstyle passed.booleantestCompiles(java.lang.String programName)Function to test if a class compiles.booleantestConstructorCount(java.lang.String programName, java.lang.Integer quantity)Runs a test to make sure that the student submitted enough constructors.booleantestMethodCount(java.lang.String programName, java.lang.Integer quantity, int modifiers, boolean modify, boolean atLeast)Runs a test to make sure that the student submitted enough methods.booleantestPublicInstanceVariables(java.lang.String programName)Runs a test to make sure that the student code has no public instace variables.voidtestRunFinished()This is the wrap-up code of the autograder.voidtestRunFinished(java.lang.String filename)This is the wrap-up code of the autograder.voidtestSortedCheckstyle(java.lang.String programName, double errValue, boolean perType)A test that runs a checkstyle test sorting the output.booleantestSourceExists(java.lang.String programName)Test to check if source file exists.
-
-
-
Field Detail
-
maxScore
protected double maxScore
The value of each test.
-
diffNum
protected int diffNum
The current test number we are on.
-
visibility
protected java.lang.String visibility
The visibilty for the current gradescope test.
-
CHECKSTYLE_JAR
public static final java.lang.String CHECKSTYLE_JAR
The location of the checkstyle Jar.- See Also:
- Constant Field Values
-
CHECKSTYLE_XML
public static final java.lang.String CHECKSTYLE_XML
The location of the checkstyle xml.- See Also:
- Constant Field Values
-
CHECKSTYLE_LISTEN_XML
public static final java.lang.String CHECKSTYLE_LISTEN_XML
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Autograder
public Autograder(int visible, double score)The Autograder class constructor. Initializes the list of all tests.- Parameters:
visible- The visibility of the result to students seesetvisibilityscore- The amount of points a test is worth
-
Autograder
public Autograder()
The Autograder class constructor. Initializes the list of all tests. Also sets the visibility to hidden and the score to 0.1
-
-
Method Detail
-
addTestResult
public void addTestResult(jh61b.grader.TestResult t)
Method to add a seperately made test to the results. This allows for people to make child classes of the autograder if they need tests that dont currently exist that they would prefer to avoid adding to this class. For an example seePictureAutograder- Parameters:
t- the test to be added to the output
-
addConverter
public static void addConverter(brandon.convert.ClassConverter c)
Method to add a user written converter to the autograder. Converters are used for the comp tests. This allows you to make comp tests that work with parameters and returns other than the base primitive types and string. A converter takes a string of text and turns it into the desired object and performs the reverse operation as well. SeeClassConverter.- Parameters:
c- The converter to add to the autograder
-
testRunFinished
public void testRunFinished() throws java.lang.ExceptionThis is the wrap-up code of the autograder. Must be the last line of the main method. It prints all of the results in a JSON format to standard out.- Throws:
java.lang.Exception- fails to create json for a test
-
testRunFinished
public void testRunFinished(java.lang.String filename) throws java.lang.ExceptionThis is the wrap-up code of the autograder. Must be the last line of the main method. It prints all of the results in a JSON format to a specified file.- Parameters:
filename- the file to write the output to- Throws:
java.lang.Exception- fails to create json for a test
-
testSourceExists
public boolean testSourceExists(java.lang.String programName)
Test to check if source file exists. Will output whether the file exists as well as add a junit test for it.- Parameters:
programName- the program name (can include or not include the .java)- Returns:
- whether or not the source exists
-
compile
public int compile(java.lang.String fileName)
Method to compile a java file for you. NOTE: This is not a test This just compiles a file. It is useful for when you need a test file but dont want to compile it until you know with certainty that the base file compiles.- Parameters:
fileName- The filename of the file to compile- Returns:
- the int result of the java compiler 0 for success, nonzero otherwise
-
testCompiles
public boolean testCompiles(java.lang.String programName)
Function to test if a class compiles. Outputs whether the file compiles as well as adds an additional gradescope test for it. If the program fails due to unmappable characters, the test will automatically be made visible as this is a problem created on gradescope and might not be a problem that a student will see on their own device.- Parameters:
programName- the name of the java file to test (without the .java)- Returns:
- whether the class compiled
-
testCheckstyle
public void testCheckstyle(java.lang.String programName)
Checks if checkstyle passed. Creates a gradescope test with the results from checkstyle and gives the output to the grader. Relies on having the checkstyle files (the jar and xml) in the location of CHECKSTYLE_JAR and CHECKSTYLE_XML. Please change those to match the location for your class. This also assumes that the java files is in the source folder of the autograder when uploaded to gradescope.- Parameters:
programName- the java class name (without the .java)
-
testSortedCheckstyle
public void testSortedCheckstyle(java.lang.String programName, double errValue, boolean perType)A test that runs a checkstyle test sorting the output. This test takes off for either each type of mistake or each mistake that a student has. It also formats the output for easy grading by hand. It shows each type of error and all the lines on which that error occurs. To use this test you need the CHECKSTYLE_LISTEN_XML to match the location of the xml file you use and this xml file has to have the listener configured as specified in the README.- Parameters:
programName- the classname of the java file to run the test oneerrValue- the number of points lost per type of checkstyle errorperType- true if taking off per type of mistake, false if per mistake
-
stdOutDiffTests
public void stdOutDiffTests(java.lang.String name, int count, boolean sampleFile, boolean ignoreWhitespace)Runs all the diff tests for a specific file. This runs count diff tests each one using the naming convetion on the next line for the name of the input file. All input files are named: {Program_Name}_Diff_#.in The diff test have the option of not using a sample program and instead using already made output files. This approach is good if there is a sample run created. The expected output should be named: {program_Name}_#.expected- Parameters:
name- the name of the program to do diff tests oncount- the number of diffs to performsampleFile- true if using a sample program false if just comparing to a file.ignoreWhitespace- true if want to ignore whitespace false otherwise
-
stdOutDiffTests
public void stdOutDiffTests(java.lang.String name, int count, boolean sampleFile, boolean ignoreWhitespace, int numVisible)Runs all the diff tests for a specific file. This runs count diff tests each one using the naming convetion on the next line for the name of the input file. All input files are named: {Program_Name}_Diff_#.in The diff test have the option of not using a sample program and instead using already made output files. This approach is good if there is a sample run created. The expected output should be named: {program_Name}_#.expected This version allows for a certain amount to be forced to be hidden.- Parameters:
name- the name of the program to do diff tests oncount- the number of diffs to performsampleFile- true if using a sample program false if just comparing to a file.ignoreWhitespace- true if want to ignore whitespace false otherwisenumVisible- The number of tests that should be visible instead of what visibility is set to (count - numVisible) = numHidden
-
stdOutDiffTest
public void stdOutDiffTest(java.lang.String name, java.lang.String inFile, boolean sampleFile, boolean ignoreWhitespace)Runs a diff test on the std output of a specific java program. This test runs one diff test comparing the output of the java program against either a sampole implementation or a hand written file. These tests rely on redirecting input from a file to standard input. These tests will not work as expected if the student opens multiple Scanners to read from standard input. inFile should be a filename without an extension. Thsi test auto-appends extensions onto the filename. The input file should end in .in, the expected output file should end in .expected and the program will always create the students output file which will end in .out.- Parameters:
name- the name of the java program to do diff tests oninFile- the name of the test input file to use without an extensionsampleFile- true if using a sample program false if just comparing to a file.ignoreWhitespace- true if want to ignore whitespace false otherwise
-
logFileDiffTests
public void logFileDiffTests(java.lang.String name, int count, java.lang.String logFile, java.lang.String sampleLogFile, boolean ignoreWhitespace)Runs all the diff tests for a specific java program comparing resulting file output. This runs count diff tests each one using the naming convetion on the next line for the name of the input file. All input files are named: {Program_Name}_Diff_#.in For this method to work correctly, the sample implementation and the student submission should always write to the same file. If you need different filenames for each run, you should uselogFileDiffTestwith a loop to modify the filename before calling each run.- Parameters:
name- the name of the program to do diff tests oncount- the number of diffs to performlogFile- the filename of the file the students code writes to and should be comparedsampleLogFile- the filename that the sample code writes to and should be used for comparisonignoreWhitespace- true if want to ignore whitespace false otherwise
-
logFileDiffTests
public void logFileDiffTests(java.lang.String name, int count, int numVisible, java.lang.String logFile, java.lang.String sampleLogFile, boolean ignoreWhitespace)Runs all the diff tests for a specific java program comparing resulting file output. This runs count diff tests each one using the naming convetion on the next line for the name of the input file. All input files are named: {Program_Name}_Diff_#.in For this method to work correctly, the sample implementation and the student submission should always write to the same file. If you need different filenames for each run, you should uselogFileDiffTestwith a loop to modify the filename before calling each run.- Parameters:
name- the name of the program to do diff tests oncount- the number of diffs to performnumVisible- The number of tests that should be shown to students (count - numVisible) = numHiddenlogFile- the filename of the file the students code writes to and should be comparedsampleLogFile- the filename that the sample code writes to and should be used for comparisonignoreWhitespace- true if want to ignore whitespace false otherwise
-
logFileDiffTest
public void logFileDiffTest(java.lang.String name, java.lang.String logFile, java.lang.String sampleLogFile, java.lang.String inFile, boolean ignoreWhitespace)Runs a diff test for a specific java program comparing resulting file output. This test runs a student and sample implementation then compares the results left in specified output files. The parameter inFile should be the name of a file contianing all the std input that needs to be passed to the program. This file name should be passed without an extension. The program autoappends .in to the filename so all input files should be named {inFile}.in.- Parameters:
name- the name of the program to do diff tests onlogFile- the filename of the file the students code writes to and should be comparedsampleLogFile- the filename that the sample code writes to and should be used for comparisoninFile- the name of the test input file to use without an extensionignoreWhitespace- true if want to ignore whitespace false otherwise
-
diffFiles
public boolean diffFiles(java.lang.String firstFile, java.lang.String secondFile)Test to compare two files. This will run a diff test on two files. It compares the files and displays the difference between the two files as a test. Will give no credit if either file did not exist.- Parameters:
firstFile- the filename of the first file to comparesecondFile- the filename of the other file to compare- Returns:
- true if files match, false otherwise
-
compTest
public void compTest(java.lang.String programName, java.lang.reflect.Method m, java.lang.Object ret, java.lang.Object caller, java.lang.String stdinput, java.lang.Object... args)Method to do a test comparing the ouptut of the students method against an expected value. Basically this method runs the students code and calls .equals() method of the return to compare it to the expected value. It also will work if both methods are supposed to return null. If the method fails or gives the wrong output, the test result will include the information about the method call and potentially the stack trace if the method crashed.- Parameters:
programName- the name of the java class to testm- The method to test usegetMethodto get the methodret- The expect output from the methodcaller- An object the method should be called on (null if a static method)stdinput- the file to treat as standard input. If null use the default.args- Any arguments that need to be passed into the method, can be an array of objects
-
stackTraceToString
public static java.lang.String stackTraceToString(java.lang.Exception es)
-
compTest
public void compTest(java.lang.String programName, java.lang.reflect.Method m, int ret, java.lang.Object caller, java.lang.Object... args)Method to do a test comparing the ouptut of the students method against an expected value. Will wrap the int in its object type (Integer) and then call the object version- Parameters:
programName- the name of the java class to testm- The method to test usegetMethodto get the methodret- The expect output from the methodcaller- An object the method should be called on (null if a static method)args- Any arguments that need to be passed into the method, can be an array of objects- See Also:
compTest(String, Method, Object, Object, String, Object...)
-
compTest
public void compTest(java.lang.String programName, java.lang.reflect.Method m, boolean ret, java.lang.Object caller, java.lang.Object... args)Method to do a test comparing the ouptut of the students method against an expected value. Will wrap the boolean in its object type (Boolean) and then call the object version- Parameters:
programName- the name of the java class to testm- The method to test usegetMethodto get the methodret- The expect output from the methodcaller- An object the method should be called on (null if a static method)args- Any arguments that need to be passed into the method, can be an array of objects- See Also:
compTest(String, Method, Object, Object, String, Object...)
-
compTest
public void compTest(java.lang.String programName, java.lang.reflect.Method m, char ret, java.lang.Object caller, java.lang.Object... args)Method to do a test comparing the ouptut of the students method against an expected value. Will wrap the char in its object type (Character) and then call the object version- Parameters:
programName- the name of the java class to testm- The method to test usegetMethodto get the methodret- The expect output from the methodcaller- An object the method should be called on (null if a static method)args- Any arguments that need to be passed into the method, can be an array of objects- See Also:
compTest(String, Method, Object, Object, String, Object...)
-
compTest
public void compTest(java.lang.String programName, java.lang.reflect.Method m, double ret, java.lang.Object caller, java.lang.Object... args)Method to do a test comparing the ouptut of the students method against an expected value. Will wrap the double in its object type (Double) and then call the object version- Parameters:
programName- the name of the java class to testm- The method to test usegetMethodto get the methodret- The expect output from the methodcaller- An object the method should be called on (null if a static method)args- Any arguments that need to be passed into the method, can be an array of objects- See Also:
compTest(String, Method, Object, Object, String, Object...)
-
compTest
public void compTest(java.lang.String programName, java.lang.reflect.Method m, long ret, java.lang.Object caller, java.lang.Object... args)Method to do a test comparing the ouptut of the students method against an expected value. Will wrap the long in its object type (Long) and then call the object version- Parameters:
programName- the name of the java class to testm- The method to test usegetMethodto get the methodret- The expect output from the methodcaller- An object the method should be called on (null if a static method)args- Any arguments that need to be passed into the method, can be an array of objects- See Also:
compTest(String, Method, Object, Object, String, Object...)
-
compTest
public void compTest(java.lang.String programName, java.lang.reflect.Method m, float ret, java.lang.Object caller, java.lang.Object... args)Method to do a test comparing the ouptut of the students method against an expected value. Will wrap the float in its object type (Float) and then call the object version- Parameters:
programName- the name of the java class to testm- The method to test usegetMethodto get the methodret- The expect output from the methodcaller- An object the method should be called on (null if a static method)args- Any arguments that need to be passed into the method, can be an array of objects- See Also:
compTest(String, Method, Object, Object, String, Object...)
-
getMethod
public static java.lang.reflect.Method getMethod(java.lang.String programName, java.lang.String methodName, java.lang.Class<?>... paramTypes)Method to get a method.- Parameters:
programName- the name of the java classmethodName- the name of the methodparamTypes- the argument classes that the method takes in- Returns:
- an object representing the method, null if the method does not exist
- See Also:
compTest This method takes in the name of the method and class and gets the method to use with the compTest.
-
getMethod
public static java.lang.reflect.Method getMethod(java.lang.String programName, java.lang.String methodName, java.lang.String[] argTypes)Method to get a method.- Parameters:
programName- the name of the java classmethodName- the name of the methodargTypes- the argument classes (in string form) that the method takes in- Returns:
- an object representing the method, null if the method does not exist
- See Also:
compTest This method takes in the name of the method and class and gets the method to use with the compTest.
-
hasMethodsTest
public boolean hasMethodsTest(java.lang.String className, java.lang.String interfaceName, boolean matchModifiers)Test to check whether a class complies with an interface. This method checks that a java class has all the methods found in a provided interface. This method is particualary useful in a introductory class where methods are specified but students are not asked to specifcally implement certain methods. This method also allows for checking constructors which an interface traditionally does not allow. Just create a method that has the same name as the class and any return type and this method will interpret it as a constructor. It can also check the modifiers of the method (public, private, static...). This will return false if either java files does not compile, in addition to if any method is missing.- Parameters:
className- the java className to testinterfaceName- the name of the java interface that the class must followmatchModifiers- whether to check modifiers in this test- Returns:
- true if all methods found, false otherwise
-
getModifiers
public static int getModifiers(java.lang.String[] mods)
Method to take a list of string modifiers and turn them into a representative integer. Java uses integers to store information about a method/field/class's modifiers. This method takes in an array of strings and turns it into its representive integer for other tests. This method is Case-INSensitive. The following are possible modfiers handled by this method: abstract, final, interface, native, private, protected, public, static, strict, synchronized, transient, volatile.- Parameters:
mods- a list of modifiers needed (case-insensitive)- Returns:
- an integer containing the information of all the modifiers
-
hasMethodTest
public boolean hasMethodTest(java.lang.String programName, java.lang.String methodName, java.lang.String[] argTypes, java.lang.String returnType, boolean checkReturn, java.lang.String[] modifiers, boolean checkModifiers)Method to test whether a method exists. This method takes in the name of the method and class and checks if a method exists. It then adds a TestResult of whether the method exists. NOTE: Void is a TYPE. If you are checking the return it should never be null. To check for a void method. Pass in the string void. NOTE: For modifiers, seegetModifiersfor a list of acceptable modifiers.- Parameters:
programName- the name of the java classmethodName- the name of the methodargTypes- the argument classes (in string form) that the method takes inreturnType- the expected return type of the methodcheckReturn- whether to check the return type of the methodmodifiers- the expected modifiers for the methodcheckModifiers- whether to check the modifiers of the method- Returns:
- true if the method exists, false otherwise
-
hasMethodTest
public boolean hasMethodTest(java.lang.String programName, java.lang.String methodName, java.lang.Class<?>[] argTypes, java.lang.Class<?> returnType, boolean checkReturn, int modifiers, boolean checkModifiers)Method to test whether a method exists. This method takes in the name of the method and class and checks if a method exists. It then adds a TestResult of whether the method exists. NOTE: Void is a TYPE. If you are checking the return it should never be null. To check for a void method. Pass in void.class. NOTE: For modifiers, seegetModifiersto easily get the desired modifiers for the method. Also See java.lang.reflect.Modifiers for more information.- Parameters:
programName- the name of the java classmethodName- the name of the methodargTypes- the argument classes (in string form) that the method takes inreturnType- the expected return type of the methodcheckReturn- whether to check the return type of the methodmodifiers- the expected modifiers for the methodcheckModifiers- whether to check the modifiers of the method- Returns:
- true if the method exists, false otherwise
-
hasOverriddenMethodTest
public boolean hasOverriddenMethodTest(java.lang.String programName, java.lang.String methodName, java.lang.Class<?>[] argTypes, java.lang.Class<?> returnType, boolean checkReturn, int modifiers, boolean checkModifiers)Method to test whether a overriden method exists. This method takes in the name of the method and class and checks if the class overrides a method. It then adds a TestResult of whether the method exists. NOTE: Void is a TYPE. If you are checking the return it should never be null. To check for a void method. Pass in void.class. NOTE: For modifiers, seegetModifiersto easily get the desired modifiers for the method. Also See java.lang.reflect.Modifiers for more information.- Parameters:
programName- the name of the java classmethodName- the name of the methodargTypes- the argument classes (in string form) that the method takes inreturnType- the expected return type of the methodcheckReturn- whether to check the return type of the methodmodifiers- the expected modifiers for the methodcheckModifiers- whether to check the modifiers of the method- Returns:
- true if the method exists, false otherwise
-
hasOverriddenMethodTest
public boolean hasOverriddenMethodTest(java.lang.String programName, java.lang.String methodName, java.lang.String[] argTypes, java.lang.String returnType, boolean checkReturn, java.lang.String[] modifiers, boolean checkModifiers)Method to test whether an overriden method exists. This method takes in the name of the method and class and checks if the class overrides a method. It then adds a TestResult of whether the method exists. NOTE: Void is a TYPE. If you are checking the return it should never be null. To check for a void method. Pass in the string void. NOTE: For modifiers, seegetModifiersfor a list of acceptable modifiers.- Parameters:
programName- the name of the java classmethodName- the name of the methodargTypes- the argument classes (in string form) that the method takes inreturnType- the expected return type of the methodcheckReturn- whether to check the return type of the methodmodifiers- the expected modifiers for the methodcheckModifiers- whether to check the modifiers of the method- Returns:
- true if the method exists, false otherwise
-
hasConstructorTest
public boolean hasConstructorTest(java.lang.String className, java.lang.String[] argTypes, java.lang.String[] modifiers, boolean checkModifiers)Method to test whether a specific constructor exists. This method takes in the name of the class and a list of expected parameters and checks if the expected constructor exists. It then adds a TestResult of whether the constructor exists. NOTE: For modifiers, seegetModifiersfor a list of acceptable modifiers.- Parameters:
className- the name of the java classargTypes- the argument classes (in string form) that the constructor takes inmodifiers- the expected modifiers for the methodcheckModifiers- whether to check the modifiers of the method- Returns:
- true if the constructor exists, false otherwise
-
hasConstructorTest
public boolean hasConstructorTest(java.lang.String className, java.lang.Class<?>[] argTypes, int modifiers, boolean checkModifiers)Method to test whether a specific constructor exists. This method takes in the name of the class and a list of expected parameters and checks if the expected constructor exists. It then adds a TestResult of whether the constructor exists. NOTE: For modifiers, seegetModifiersto easily get the desired modifiers for the method. Also See java.lang.reflect.Modifiers for more information.- Parameters:
className- the name of the java classargTypes- the argument classes that the constructor takes inmodifiers- the expected modifiers for the methodcheckModifiers- whether to check the modifiers of the method- Returns:
- true if the constructor exists, false otherwise
-
getClasses
public static java.lang.Class<?>[] getClasses(java.lang.String[] args)
Method to convert the string paramaters to Class<?>[]. Some rules for the string format. Basically take the name that would be in front of an object of that type and that is a string. Order matters as it has to be the same order that you want it to be in for the method.- Parameters:
args- the list of parameter types- Returns:
- a list of parameter types as a list of classes
-
comparisonTests
public void comparisonTests(java.lang.String programName, int testCount, java.lang.Object caller)Runs all the comparison tests for a specific file. A comparison test is similar to acompTestbut it is comparing the output of the students program to the output of the same method for a sample program. This method will compile the sample program for you. The sample programs named: {Program_Name}Sample.java All input files are named: {Program_Name}_Comp_#.in- Parameters:
programName- the program to do comparison tests ontestCount- the number of tests to performcaller- the object the method should be called on (if an instance method)
-
comparisonTest
public void comparisonTest(java.lang.String programName, java.lang.String input, java.lang.Object caller)Runs a single test comparing the output of a method.. A comparison test is similar to acompTestbut it is comparing the output of the students program to the output of the same method for a sample program. This method will compile the sample program for you. The sample programs named: {Program_Name}Sample.java All input files are named: {something}.in. If you are using stdinput in the method, you need to name the file containing the stdinput as {something}.input. The name of the file should be the same as the .in file just with a different extension.- Parameters:
programName- the program to do comparison tests oninput- the filename of the file containing the comparison test informationcaller- the object the method should be called on (if an instance method)
-
junitTests
public void junitTests(java.lang.String programName)
This is a method to run a set of junit tests on a class. This method will run the junits and give points for every junit passed and give the faliure if the method failed. The test file is named: {Program_Name}Test.java- Parameters:
programName- the name of the class to test
-
testMethodCount
public boolean testMethodCount(java.lang.String programName, java.lang.Integer quantity, int modifiers, boolean modify, boolean atLeast)Runs a test to make sure that the student submitted enough methods. This has two particular uses. First in Gateway we sometimes ask for them to use a minimum number of helper methods in their code in order to get them to break their code up into chunks. In addition this has the ability to put in an access modifier to be able to check that the method is public or private ensuring that a student created all the public methods asked and nothing more. In java, access modifiers are represented as ints. The Modifier class has all of the possibiliites stored as constants.- Parameters:
programName- the name of the java classquantity- the number of methods the class needs.modifiers- the Modifier that we are only looking formodify- whether to use the access modifier or to look for all methodsatLeast- true: as least quantity methods, false: exactly quantity methods- Returns:
- whether the class has enough methods
- See Also:
java.lang.reflect.Modifier This method only looks at declaredMethods not constructors and inherited methods.
-
testConstructorCount
public boolean testConstructorCount(java.lang.String programName, java.lang.Integer quantity)Runs a test to make sure that the student submitted enough constructors. This would allow a professor to ensure that a student created multiple constructors if the project description requested it.- Parameters:
programName- the name of the java classquantity- the number of methods the class needs.- Returns:
- whether the class has enough constructors
-
testPublicInstanceVariables
public boolean testPublicInstanceVariables(java.lang.String programName)
Runs a test to make sure that the student code has no public instace variables. This method counts the number of fields in the class that are public and gives credit if the user has no public fields and takes off if they do.- Parameters:
programName- the name of the java class- Returns:
- whether the class has no public fields
-
hasFieldTest
public boolean hasFieldTest(java.lang.String programName, java.lang.String fieldName, java.lang.String fieldType, java.lang.String[] modifiers, boolean checkModifiers)Runs a test to make sure that the student has an expected field.. This method checks whether the student submission has a field that matches the name provided. If a type is given, It will also check that the field, if found, is of the expected type. .- Parameters:
programName- the name of the java classfieldName- the name of the field to check forfieldType- the expected type of the field. Ignored if null.modifiers- the modifiers to check forcheckModifiers- whether to check the modifiers- Returns:
- whether the class has the expected field
-
hasFieldTest
public boolean hasFieldTest(java.lang.String programName, java.lang.String fieldName, java.lang.Class<?> fieldType, int modifiers, boolean checkModifiers)Runs a test to make sure that the student has an expected field.. This method checks whether the student submission has a field that matches the name provided. If a type is given, It will also check that the field, if found, is of the expected type. .- Parameters:
programName- the name of the java classfieldName- the name of the field to check forfieldType- the expected type of the field. Ignored if null.modifiers- the modifiers to check forcheckModifiers- whether to check the modifiers- Returns:
- whether the class has the expected field
-
classDoesNotHaveMultipleScanners
public boolean classDoesNotHaveMultipleScanners(java.lang.String name)
Runs a test to make sure that the student code does not use multiple Scanners.. While this is not a problem for the average student, this blocks any possible redirection based testing that the autograder can do (like all the diff tests). This test is designed to show the test automatically if they redeclare scanners but follows the autograders visibility otherwise.- Parameters:
name- the name of the java class- Returns:
- whether multiple scanners are declared or not
-
classDoesNotUseArrayList
public boolean classDoesNotUseArrayList(java.lang.String name)
Runs a test to make sure that the student code does not use ArrayLists. This method goes line by line and checks if any line includes an ArrayList.- Parameters:
name- the name of the java class- Returns:
- whether the class declares an ArrayList
-
classDoesNotUsePackages
public boolean classDoesNotUsePackages(java.lang.String name)
Runs a test to make sure that the student code does not use package declarations. This method goes line by line and checks if any line includes a package declaration.- Parameters:
name- the name of the java class- Returns:
- whether the class declares a package
-
addTestResult
public void addTestResult(java.lang.String name, boolean success, java.lang.String extraOutput)Method to add a seperately made test to the results. This allows for people to make child classes of the autograder if they need tests that dont currently exist that they would prefer to avoid adding to this class.- Parameters:
name- the name of the testsuccess- whether the student passed the testextraOutput- any additional information to display
-
runMethodWithTimeout
public java.lang.Object runMethodWithTimeout(java.lang.reflect.Method m, java.lang.Object caller, java.lang.Object... args) throws java.util.concurrent.TimeoutException, java.util.concurrent.ExecutionException, java.lang.InterruptedException, java.lang.IllegalAccessException, java.lang.reflect.InvocationTargetException- Throws:
java.util.concurrent.TimeoutExceptionjava.util.concurrent.ExecutionExceptionjava.lang.InterruptedExceptionjava.lang.IllegalAccessExceptionjava.lang.reflect.InvocationTargetException
-
setVisibility
public void setVisibility(int choice)
Setter of the visibility of the tests. This method updates the current visibility for any future tests. That visibility is set until updated upon a future call to this method. This method takes in an int from 0-3 where they represent the following:- 0 = visible
- 1 = hidden
- 2 = after_due_date
- 3 = after_published
- Parameters:
choice- the int representing the desired visibility
-
getVisibility
public java.lang.String getVisibility()
A method to get the current visibility. This method returns the visibility as a string.- Returns:
- the current visibility
-
setScore
public void setScore(double score)
A method to set the point value of the tests. This method updates the points awarded for passing a test and the amount the test is worth. This autograder only works in pass fail as it breaks each test to be the smallest possible component. The results will stay at this score until changed by calling this method again. A score must be positive. If the input is not positive then the score will automatically be set to 0.1- Parameters:
score- the new score value of a test
-
currentScore
public double currentScore()
A method to get the current single test score. This returns the number of points that a test is worth.- Returns:
- the point value of passing a test
-
setTimeout
public void setTimeout(long timeout)
Setter for the amount of time to wait before timing out while running student code. The default timeout is 15 seconds.- Parameters:
timeout- the amount of time
-
-