Class DiffHelper
This class identifies differences between a sample solution and a student solution class. It returns with a junit assertion error, if there were differences. The differences are returned as a DiffAssertionError, that contains detailed data on the differences.
The DiffHelper
class creates a DiffHelper.DiffProcessor
object, which is the core processing unit
for diff checking. There are four methods to create a DiffHelper.DiffProcessor
object:
compareStrings(String, String)
returns aDiffHelper.DiffProcessor
object comparing two strings.callMain()
returns aDiffHelper.DiffProcessor
object comparing the console output of two classes' main methods.callMethod(String, Object...)
returns aDiffHelper.DiffProcessor
object comparing the console output generated by the specified method of two different classes.executeRunnables(Runnable, Runnable)
returns aDiffHelper.DiffProcessor
object comparing the console output of the two runnable's run methods.
A typical call flow is
DiffHelper.callMethod("mymethod", a, b) .ofClasses(mypackage.Sample.class, studentClass) .pipeToSystemIn("console has\nsome input") .normalizeOutput(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_BLANK_LINES)) .normalizeOutputExcludedFromDiffSynopsis(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_ALL_WHITESPACE_AND_NEWLINES)) .includeExplanationInDiffSynopsis("let's explain, what went wrong with your solution...") .start();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
This error is thrown, whenDiffHelper.DiffProcessor
detects a difference.static class
This class realizes a fluent interface when instrumenting the Diff with information used when diffing. -
Method Summary
Modifier and TypeMethodDescriptionstatic DiffHelper.DiffProcessor
callMain()
This method searches for console output differences between an expected and an observed class when calling the main method for each class.static DiffHelper.DiffProcessor
This method searches for console output differences between an expected and an observed class when calling the main method for each class.static DiffHelper.DiffProcessor
callMethod
(String methodName, Object... params) This method searches for console output differences between an expected and an observed class when calling a method for each class.static DiffHelper.DiffProcessor
compareObjects
(Object expected, Object observed) This method searches for differences between an expected and an observed object after being converted to strings (seecompareStrings(String, String)
.static DiffHelper.DiffProcessor
compareStrings
(String expected, String observed) This method searches for differences between an expected and an observed string.static DiffHelper.DiffProcessor
executeRunnables
(Runnable teacher, Runnable student) This method searches for output differences between a runnable instance provided by the teacher and a runnable instance provided by a student.
-
Method Details
-
callMain
This method searches for console output differences between an expected and an observed class when calling the main method for each class.
A typical call flow is
DiffHelper.callMain() .ofClasses(mypackage.Sample.class, studentClass) .pipeToSystemIn("console has\nsome input") .normalizeOutput(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_BLANK_LINES)) .normalizeOutputExcludedFromDiffSynopsis(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_ALL_WHITESPACE_AND_NEWLINES)) .includeExplanationInDiffSynopsis("let's explain, what went wrong with your solution...") .start();
-
callMain
This method searches for console output differences between an expected and an observed class when calling the main method for each class.
A typical call flow is
DiffHelper.callMain(args) .ofClasses(mypackage.Sample.class, studentClass) .pipeToSystemIn("console has\nsome input") .normalizeOutput(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_BLANK_LINES)) .normalizeOutputExcludedFromDiffSynopsis(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_ALL_WHITESPACE_AND_NEWLINES)) .includeExplanationInDiffSynopsis("let's explain, what went wrong with your solution...") .start();
-
callMethod
This method searches for console output differences between an expected and an observed class when calling a method for each class.
A typical call flow is
DiffHelper.callMethod("mymethod", a, b) .ofClasses(mypackage.Sample.class, studentClass) .pipeToSystemIn("console has\nsome input") .normalizeOutput(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_BLANK_LINES)) .normalizeOutputExcludedFromDiffSynopsis(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_ALL_WHITESPACE_AND_NEWLINES)) .includeExplanationInDiffSynopsis("let's explain, what went wrong with your solution...") .start();
- Parameters:
methodName
- name of static method to callparams
- parameters for method call
-
executeRunnables
This method searches for output differences between a runnable instance provided by the teacher and a runnable instance provided by a student.
A typical call flow is
DiffHelper.executeRunnables(rt, rs) .pipeToSystemIn("console has\nsome input") .normalizeOutput(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_BLANK_LINES)) .normalizeOutputExcludedFromDiffSynopsis(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_ALL_WHITESPACE_AND_NEWLINES)) .includeExplanationInDiffSynopsis("let's explain, what went wrong with your solution...") .start();
- Parameters:
teacher
- a Runnable instance that executes teacher codestudent
- a Runnable instance that executes student code
-
compareStrings
This method searches for differences between an expected and an observed string. A typical call flow is
DiffHelper.compareStrings(e, o) .normalizeOutput(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_BLANK_LINES)) .normalizeOutputExcludedFromDiffSynopsis(new StringNormalizer(StringNormalizer.StandardRule.OPT_IGNORE_ALL_WHITESPACE_AND_NEWLINES)) .includeExplanationInDiffSynopsis("let's explain, what went wrong with your solution...") .start();
- Parameters:
expected
- expected stringobserved
- observed string
-
compareObjects
This method searches for differences between an expected and an observed object after being converted to strings (see
compareStrings(String, String)
.- Parameters:
expected
- expected objectobserved
- observed object
-