Class TestUtils

java.lang.Object
org.tudalgo.algoutils.reflect.TestUtils

public final class TestUtils extends Object
A utility class used for JUnit tests which provides reflective access to some properties and assertions.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
    static final int
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    assertModifier(int expected, int actual, String name)
    Tests whether the modifiers are correct.
    static void
    assertModifier(int expected, Class<?> clazz)
    Tests whether the modifiers of a class are correct.
    static void
    assertModifier(int expected, Constructor<?> constructor)
    Tests whether the modifiers of a constructor are correct.
    static void
    assertModifier(int expected, Field attribut)
    Tests whether the modifiers of a field are correct.
    static void
    assertModifier(int expected, Method method)
    Tests whether the modifiers of a method are correct.
    static int
    Calculates the similarity (a number within 0 and 1) between two strings.
    static Class<?>[]
    getClasses(String packageName)
    Scans all classes accessible from the context class loader which belong to the given package and subpackages.
    static boolean
    Returns true if TestCycleResolver.getTestCycle() does not return null.
    static double
    Calculates the similarity (a number within 0 and 1) between two strings.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Method Details

    • assertModifier

      public static void assertModifier(int expected, int actual, String name)
      Tests whether the modifiers are correct.
      Parameters:
      expected - the expected modifier count
      actual - the actual modifier count
      name - the name of the field to be checked
    • assertModifier

      public static void assertModifier(int expected, Class<?> clazz)
      Tests whether the modifiers of a class are correct.
      Parameters:
      expected - the expected modifier count
      clazz - the class to be checked
    • assertModifier

      public static void assertModifier(int expected, Method method)
      Tests whether the modifiers of a method are correct.
      Parameters:
      expected - the expected modifier count
      method - the method to be checked
    • assertModifier

      public static void assertModifier(int expected, Constructor<?> constructor)
      Tests whether the modifiers of a constructor are correct.
      Parameters:
      expected - the expected modifier count
      constructor - the constructor to be checked
    • assertModifier

      public static void assertModifier(int expected, Field attribut)
      Tests whether the modifiers of a field are correct.
      Parameters:
      expected - the expected modifier count
      attribut - the field to be checked
    • similarity

      public static double similarity(String s1, String s2)
      Calculates the similarity (a number within 0 and 1) between two strings.
      Parameters:
      s1 - the first string used for the calculation of the similarity
      s2 - the second string used for the calculation of the similarity
      Returns:
      the similarity
    • editDistance

      public static int editDistance(String s1, String s2)
      Calculates the similarity (a number within 0 and 1) between two strings.
      Parameters:
      s1 - the first string used for the calculation of the similarity
      s2 - the second string used for the calculation of the similarity
      Returns:
      the calculated similarity (a number within 0 and 1) between two strings.
      See Also:
    • getClasses

      public static Class<?>[] getClasses(String packageName) throws IOException
      Scans all classes accessible from the context class loader which belong to the given package and subpackages.
      Parameters:
      packageName - The base package name
      Returns:
      the found classes
      Throws:
      IOException - if an I/O Exception occurs
    • isAutograderRun

      public static boolean isAutograderRun()
      Returns true if TestCycleResolver.getTestCycle() does not return null.
      Returns:
      true if TestCycleResolver.getTestCycle() does not return null