Solution: Make the Unit Test Pass
This lesson provides a solution to the challenge given in the previous lesson.
We'll cover the following...
Solution
For demonstration purposes, let’s write an obviously incorrect implementation that passes the first test by accident. The following function simply returns a copy of the input:
D
dstring toFront(dstring str, dchar letter) {dstring result;foreach (c; str) {result ~= c;}return result;}unittest {immutable str = "hello"d;assert(toFront(str, 'h') == "hello");assert(toFront(str, 'o') == "ohell");assert(toFront(str, 'l') == "llheo");}void main() {}
Here is a correct ...