Class LevenshteinSettings
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumSupported languages for assertion and feedback messages.static enumHow modifiers of the student's element that the test does not expect are treated. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intDefault number of decimals ofdoubleandfloatvalues in failure messages.static final intDefault threshold (percent) for all name deviations. -
Method Summary
Modifier and TypeMethodDescriptionstatic intstatic intstatic intstatic LevenshteinSettings.Languagestatic intstatic booleanstatic voidreset()Restores all defaults (German messages, 20 % for every threshold, getter/setter values compared by content, unexpected modifiers deviate, 2 decimals).static voidsetAttributeNameDeviationThreshold(int threshold) static voidsetClassNameDeviationThreshold(int threshold) static voidsetDecimals(int newDecimals) Sets the number of decimals ofdoubleandfloatvalues in failure messages, e.g.static voidsetGettersSettersRequireSameObject(boolean requireSameObject) Chooses howtestGettersSetterscompares the value it set with the value it reads back.static voidsetLanguage(LevenshteinSettings.Language newLanguage) static voidsetMethodNameDeviationThreshold(int threshold) static voidChooses how modifiers that the test does not expect are treated, seeLevenshteinSettings.UnexpectedModifiers.
-
Field Details
-
DEFAULT_THRESHOLD
public static final int DEFAULT_THRESHOLDDefault threshold (percent) for all name deviations.- See Also:
-
DEFAULT_DECIMALS
public static final int DEFAULT_DECIMALSDefault number of decimals ofdoubleandfloatvalues in failure messages.- See Also:
-
-
Method Details
-
getLanguage
- Returns:
- the language of messages shown to students (default
LevenshteinSettings.Language.DEUTSCH)
-
setLanguage
- 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
testGettersSettersrequires the getter/setter to keep the same object for reference values (defaultfalse: equal content is enough) - See Also:
-
setGettersSettersRequireSameObject
public static void setGettersSettersRequireSameObject(boolean requireSameObject) Chooses howtestGettersSetterscompares 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
- Returns:
- how unexpected modifiers are treated (default
LevenshteinSettings.UnexpectedModifiers.DEVIATE)
-
setUnexpectedModifiers
Chooses how modifiers that the test does not expect are treated, seeLevenshteinSettings.UnexpectedModifiers. Set it before the wrappers are checked, e.g. in a static initializer or@BeforeAll.- Parameters:
mode-LevenshteinSettings.UnexpectedModifiers.DEVIATE(default) orLevenshteinSettings.UnexpectedModifiers.IGNORE
-
getDecimals
public static int getDecimals()- Returns:
- the number of decimals of
doubleandfloatvalues in failure messages (default 2) - See Also:
-
setDecimals
public static void setDecimals(int newDecimals) Sets the number of decimals ofdoubleandfloatvalues in failure messages, e.g.2shows31.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).
-