Tasks
Task 6.4.1
-
The
tasks/task6_4_1subdirectory of your repository is a Gradle project containing some Kotest unit tests similar to the examples discussed in Section 6.3.In a terminal window, move into this subdirectory and run the tests for the project using the Gradle wrapper1:
./gradlew testYou should see output in the terminal window, indicating that 1 out of 3 tests has failed.
-
In your browser, access the test report. Click through to the details of the failed test. You should see something like this:

You can ignore the vast majority of the lengthy exception traceback here. The pertinent information is in the first few lines.
Notice that four useful things are displayed here:
- The clue associated with the failed assertion
- The value that was expected to be returned by
grade() - The value that was actually returned by
grade() - The location of the failed assertion (line 11 of the test source code)
-
Using this information, identify the problem in
Grade.ktand fix it. Rerun the tests to check that they all pass. -
There are only three tests here, but the written specification of
grade()shown earlier suggests that there are five equivalence partitions. Add two more tests, one for each of these partitions. Run the tests to check that they all pass. -
Optional: try rewriting the tests in a more fine-grained style, without clues and with only one assertion per test. Again, run the tests to check that they all pass.
Task 6.4.2
Previously, we set you the task of writing an infix function that checks whether two strings are anagrams of each other. This task involves writing unit tests for that function.
We have provided a solution to that earlier exercise as a Gradle project,
in the tasks/task6_4_2 subdirectory of your repository.
-
In a terminal window, go to this subdirectory, then compile and run the anagram checking program with
./gradlew run -
Here is a specification of how
anagramOf()is supposed to behave:-
Two strings of different lengths are not anagrams
-
An empty string is not an anagram of itself
-
A non-empty string is an anagram of itself
-
Two strings are anagrams if they contain the same characters in a different order
-
Letter case is disregarded when comparing character sequences, i.e., the lowercase and uppercase forms of a character are considered to be equivalent
Locate the file
AnagramTest.ktin the project source code. Add a set of unit tests to this file to verify that the function behaves in the manner specified above. -
-
Run the tests. If the test results indicate any deviation from the specification given above, modify the implementation of
anagramOf()to fix the issue.
-
If you are using the IntelliJ IDE, you can open the
task6_4_1subdirectory as a project. After project setup is complete, you will be able to access thetesttask in the Gradle tool window of the IDE. Double-click on it to run it. IntelliJ will create a run configuration, which can subsequently be accessed in the toolbar in order to rerun the tests. ↩