Class Autograder

  • Direct Known Subclasses:
    DrawingAutograder, PictureAutograder

    public class Autograder
    extends java.lang.Object
    Classs representing an autograder. It's main method is the running of the autograder and instances can be made to store all important information.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String CHECKSTYLE_JAR
      The location of the checkstyle Jar.
      static java.lang.String CHECKSTYLE_LISTEN_XML  
      static java.lang.String CHECKSTYLE_XML
      The location of the checkstyle xml.
      protected int diffNum
      The current test number we are on.
      protected double maxScore
      The value of each test.
      protected java.lang.String visibility
      The 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 void addConverter​(brandon.convert.ClassConverter c)
      Method to add a user written converter to the autograder.
      void addTestResult​(java.lang.String name, boolean success, java.lang.String extraOutput)
      Method to add a seperately made test to the results.
      void addTestResult​(jh61b.grader.TestResult t)
      Method to add a seperately made test to the results.
      boolean classDoesNotHaveMultipleScanners​(java.lang.String name)
      Runs a test to make sure that the student code does not use multiple Scanners..
      boolean classDoesNotUseArrayList​(java.lang.String name)
      Runs a test to make sure that the student code does not use ArrayLists.
      boolean classDoesNotUsePackages​(java.lang.String name)
      Runs a test to make sure that the student code does not use package declarations.
      void comparisonTest​(java.lang.String programName, java.lang.String input, java.lang.Object caller)
      Runs a single test comparing the output of a method..
      void comparisonTests​(java.lang.String programName, int testCount, java.lang.Object caller)
      Runs all the comparison tests for a specific file.
      int compile​(java.lang.String fileName)
      Method to compile a java file for you.
      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.
      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.
      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.
      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.
      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.
      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.
      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.
      double currentScore()
      A method to get the current single test score.
      boolean diffFiles​(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.Method getMethod​(java.lang.String programName, java.lang.String methodName, java.lang.Class<?>... paramTypes)
      Method to get a method.
      static java.lang.reflect.Method getMethod​(java.lang.String programName, java.lang.String methodName, java.lang.String[] argTypes)
      Method to get a method.
      static int getModifiers​(java.lang.String[] mods)
      Method to take a list of string modifiers and turn them into a representative integer.
      java.lang.String getVisibility()
      A method to get the current visibility.
      boolean hasConstructorTest​(java.lang.String className, java.lang.Class<?>[] argTypes, int modifiers, boolean checkModifiers)
      Method to test whether a specific constructor exists.
      boolean hasConstructorTest​(java.lang.String className, java.lang.String[] argTypes, java.lang.String[] modifiers, boolean checkModifiers)
      Method to test whether a specific constructor exists.
      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..
      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..
      boolean hasMethodsTest​(java.lang.String className, java.lang.String interfaceName, boolean matchModifiers)
      Test to check whether a class complies with an interface.
      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.
      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.
      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.
      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.
      void junitTests​(java.lang.String programName)
      This is a method to run a set of junit tests on a class.
      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.
      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.
      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.
      java.lang.Object runMethodWithTimeout​(java.lang.reflect.Method m, java.lang.Object caller, java.lang.Object... args)  
      void setScore​(double score)
      A method to set the point value of the tests.
      void setTimeout​(long timeout)
      Setter for the amount of time to wait before timing out while running student code.
      void setVisibility​(int choice)
      Setter of the visibility of the tests.
      static java.lang.String stackTraceToString​(java.lang.Exception es)  
      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.
      void stdOutDiffTests​(java.lang.String name, int count, boolean sampleFile, boolean ignoreWhitespace)
      Runs all the diff tests for a specific file.
      void stdOutDiffTests​(java.lang.String name, int count, boolean sampleFile, boolean ignoreWhitespace, int numVisible)
      Runs all the diff tests for a specific file.
      void testCheckstyle​(java.lang.String programName)
      Checks if checkstyle passed.
      boolean testCompiles​(java.lang.String programName)
      Function to test if a class compiles.
      boolean testConstructorCount​(java.lang.String programName, java.lang.Integer quantity)
      Runs a test to make sure that the student submitted enough constructors.
      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.
      boolean testPublicInstanceVariables​(java.lang.String programName)
      Runs a test to make sure that the student code has no public instace variables.
      void testRunFinished()
      This is the wrap-up code of the autograder.
      void testRunFinished​(java.lang.String filename)
      This is the wrap-up code of the autograder.
      void testSortedCheckstyle​(java.lang.String programName, double errValue, boolean perType)
      A test that runs a checkstyle test sorting the output.
      boolean testSourceExists​(java.lang.String programName)
      Test to check if source file exists.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 see setvisibility
        score - 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 see PictureAutograder
        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. See ClassConverter.
        Parameters:
        c - The converter to add to the autograder
      • testRunFinished

        public void testRunFinished()
                             throws java.lang.Exception
        This 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.Exception
        This 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 one
        errValue - the number of points lost per type of checkstyle error
        perType - 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 on
        count - the number of diffs to perform
        sampleFile - 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 on
        count - the number of diffs to perform
        sampleFile - true if using a sample program false if just comparing to a file.
        ignoreWhitespace - true if want to ignore whitespace false otherwise
        numVisible - 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 on
        inFile - the name of the test input file to use without an extension
        sampleFile - 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 use logFileDiffTest with a loop to modify the filename before calling each run.
        Parameters:
        name - the name of the program to do diff tests on
        count - the number of diffs to perform
        logFile - the filename of the file the students code writes to and should be compared
        sampleLogFile - the filename that the sample code writes to and should be used for comparison
        ignoreWhitespace - 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 use logFileDiffTest with a loop to modify the filename before calling each run.
        Parameters:
        name - the name of the program to do diff tests on
        count - the number of diffs to perform
        numVisible - The number of tests that should be shown to students (count - numVisible) = numHidden
        logFile - the filename of the file the students code writes to and should be compared
        sampleLogFile - the filename that the sample code writes to and should be used for comparison
        ignoreWhitespace - 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 on
        logFile - the filename of the file the students code writes to and should be compared
        sampleLogFile - the filename that the sample code writes to and should be used for comparison
        inFile - the name of the test input file to use without an extension
        ignoreWhitespace - 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 compare
        secondFile - 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 test
        m - The method to test use getMethod to get the method
        ret - The expect output from the method
        caller - 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 test
        m - The method to test use getMethod to get the method
        ret - The expect output from the method
        caller - 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 test
        m - The method to test use getMethod to get the method
        ret - The expect output from the method
        caller - 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 test
        m - The method to test use getMethod to get the method
        ret - The expect output from the method
        caller - 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 test
        m - The method to test use getMethod to get the method
        ret - The expect output from the method
        caller - 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 test
        m - The method to test use getMethod to get the method
        ret - The expect output from the method
        caller - 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 test
        m - The method to test use getMethod to get the method
        ret - The expect output from the method
        caller - 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.String[] argTypes)
        Method to get a method.
        Parameters:
        programName - the name of the java class
        methodName - the name of the method
        argTypes - 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 test
        interfaceName - the name of the java interface that the class must follow
        matchModifiers - 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, see getModifiers for a list of acceptable modifiers.
        Parameters:
        programName - the name of the java class
        methodName - the name of the method
        argTypes - the argument classes (in string form) that the method takes in
        returnType - the expected return type of the method
        checkReturn - whether to check the return type of the method
        modifiers - the expected modifiers for the method
        checkModifiers - 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, see getModifiers to easily get the desired modifiers for the method. Also See java.lang.reflect.Modifiers for more information.
        Parameters:
        programName - the name of the java class
        methodName - the name of the method
        argTypes - the argument classes (in string form) that the method takes in
        returnType - the expected return type of the method
        checkReturn - whether to check the return type of the method
        modifiers - the expected modifiers for the method
        checkModifiers - 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, see getModifiers to easily get the desired modifiers for the method. Also See java.lang.reflect.Modifiers for more information.
        Parameters:
        programName - the name of the java class
        methodName - the name of the method
        argTypes - the argument classes (in string form) that the method takes in
        returnType - the expected return type of the method
        checkReturn - whether to check the return type of the method
        modifiers - the expected modifiers for the method
        checkModifiers - 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, see getModifiers for a list of acceptable modifiers.
        Parameters:
        programName - the name of the java class
        methodName - the name of the method
        argTypes - the argument classes (in string form) that the method takes in
        returnType - the expected return type of the method
        checkReturn - whether to check the return type of the method
        modifiers - the expected modifiers for the method
        checkModifiers - 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, see getModifiers for a list of acceptable modifiers.
        Parameters:
        className - the name of the java class
        argTypes - the argument classes (in string form) that the constructor takes in
        modifiers - the expected modifiers for the method
        checkModifiers - 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, see getModifiers to easily get the desired modifiers for the method. Also See java.lang.reflect.Modifiers for more information.
        Parameters:
        className - the name of the java class
        argTypes - the argument classes that the constructor takes in
        modifiers - the expected modifiers for the method
        checkModifiers - 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 a compTest but 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 on
        testCount - the number of tests to perform
        caller - 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 a compTest but 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 on
        input - the filename of the file containing the comparison test information
        caller - 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 class
        quantity - the number of methods the class needs.
        modifiers - the Modifier that we are only looking for
        modify - whether to use the access modifier or to look for all methods
        atLeast - 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 class
        quantity - 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 class
        fieldName - the name of the field to check for
        fieldType - the expected type of the field. Ignored if null.
        modifiers - the modifiers to check for
        checkModifiers - 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 class
        fieldName - the name of the field to check for
        fieldType - the expected type of the field. Ignored if null.
        modifiers - the modifiers to check for
        checkModifiers - 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 test
        success - whether the student passed the test
        extraOutput - 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.TimeoutException
        java.util.concurrent.ExecutionException
        java.lang.InterruptedException
        java.lang.IllegalAccessException
        java.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