Class LevenshteinSettings

java.lang.Object
io.github.valentinherrmann.levenshtein.LevenshteinSettings

public final class LevenshteinSettings extends Object
Runtime configuration of the Levenshtein Testing Framework.

All values are read when they are needed, never inlined at compile time, so an exam repository configures the framework from its own test code, typically in a static initializer or a @BeforeAll method of the test class. Do not change them inside a test method or @BeforeEach: LevenshteinTest looks up the attribute wrappers before each test (see StaticStateReset), and every wrapper looks up its element only once.

static {
    LevenshteinSettings.setLanguage(LevenshteinSettings.Language.ENGLISH);
    LevenshteinSettings.setMethodNameDeviationThreshold(15);
}

Levenshtein distance thresholds

Thresholds are percentages (0-100) of the length of the longer name. A name is accepted as a deviation when distance * 100 / max(expected.length(), actual.length()) <= threshold.

// threshold 20:
"price"          vs "pric"           -> 1 * 100 / 5  = 20.0 %  -> DEVIATES
"calculateCost"  vs "calculateCots"  -> 2 * 100 / 13 = 15.4 %  -> DEVIATES
"Car"            vs "Cra"            -> 2 * 100 / 3  = 66.7 %  -> MISSING
  • 0 - no tolerance, exact names required
  • 10 - strict, single typos in long names only
  • 20 - moderate (default)
  • 30+ - lenient, may bind unrelated members

Timeouts

Timeouts are not configured here. LevenshteinTest carries a default @StrictTimeout; put an explicit @StrictTimeout on the test class or method to override it.

  • Field Details

    • DEFAULT_THRESHOLD

      public static final int DEFAULT_THRESHOLD
      Default threshold (percent) for all name deviations.
      See Also:
    • DEFAULT_DECIMALS

      public static final int DEFAULT_DECIMALS
      Default number of decimals of double and float values in failure messages.
      See Also:
  • Method Details

    • getLanguage

      public static LevenshteinSettings.Language getLanguage()
      Returns:
      the language of messages shown to students (default LevenshteinSettings.Language.DEUTSCH)
    • setLanguage

      public static void setLanguage(LevenshteinSettings.Language newLanguage)
      Parameters:
      newLanguage - the language of messages shown to students
    • getClassNameDeviationThreshold

      public static int getClassNameDeviationThreshold()
      Returns:
      maximum deviation (percent) accepted for class names
    • setClassNameDeviationThreshold

      public static void setClassNameDeviationThreshold(int threshold)
      Parameters:
      threshold - maximum deviation (percent, 0-100) accepted for class names
    • getMethodNameDeviationThreshold

      public static int getMethodNameDeviationThreshold()
      Returns:
      maximum deviation (percent) accepted for method names
    • setMethodNameDeviationThreshold

      public static void setMethodNameDeviationThreshold(int threshold)
      Parameters:
      threshold - maximum deviation (percent, 0-100) accepted for method names
    • getAttributeNameDeviationThreshold

      public static int getAttributeNameDeviationThreshold()
      Returns:
      maximum deviation (percent) accepted for attribute names
    • setAttributeNameDeviationThreshold

      public static void setAttributeNameDeviationThreshold(int threshold)
      Parameters:
      threshold - maximum deviation (percent, 0-100) accepted for attribute names
    • isGettersSettersRequireSameObject

      public static boolean isGettersSettersRequireSameObject()
      Returns:
      whether testGettersSetters requires the getter/setter to keep the same object for reference values (default false: equal content is enough)
      See Also:
    • setGettersSettersRequireSameObject

      public static void setGettersSettersRequireSameObject(boolean requireSameObject)
      Chooses how testGettersSetters compares the value it set with the value it reads back. false (default): equal content is enough (Objects.deepEquals(Object, Object)), so a getter or setter may store or return a copy, e.g. of an array. true: for reference values the very same object is required (==), so a copy fails. Primitives, their wrappers, strings and enums are always compared by value.
      Parameters:
      requireSameObject - whether the same object is required for reference values
    • getUnexpectedModifiers

      public static LevenshteinSettings.UnexpectedModifiers getUnexpectedModifiers()
      Returns:
      how unexpected modifiers are treated (default LevenshteinSettings.UnexpectedModifiers.DEVIATE)
    • setUnexpectedModifiers

      public static void setUnexpectedModifiers(LevenshteinSettings.UnexpectedModifiers mode)
      Chooses how modifiers that the test does not expect are treated, see LevenshteinSettings.UnexpectedModifiers. Set it before the wrappers are checked, e.g. in a static initializer or @BeforeAll.
      Parameters:
      mode - LevenshteinSettings.UnexpectedModifiers.DEVIATE (default) or LevenshteinSettings.UnexpectedModifiers.IGNORE
    • getDecimals

      public static int getDecimals()
      Returns:
      the number of decimals of double and float values in failure messages (default 2)
      See Also:
    • setDecimals

      public static void setDecimals(int newDecimals)
      Sets the number of decimals of double and float values in failure messages, e.g. 2 shows 31.25. The decimal separator is always a dot, as in Java code.
      Parameters:
      newDecimals - the number of decimals (0-15)
      See Also:
    • reset

      public static void reset()
      Restores all defaults (German messages, 20 % for every threshold, getter/setter values compared by content, unexpected modifiers deviate, 2 decimals).