Skip to content
Xen / docs

Search documentation

English · v0.1.0-demo.3

Type to search the documentation.

    한국어
    Xen / coding-class v0.1.0-demo.3

    Testing your code · Coding Class

    Apply the chapter in three steps: an exercise, a program project, and a debugging task. Implement first, then consult the hints and completion criteria. Use a separate file or working directory for each task.

    Run the chapter’s testing.xen, rerun with the doubles filter, then use an unmatched filter and inspect the exit status.

    Completion: Two tests pass without a filter, one with doubles; an unmatched filter fails.

    Hint: Use xen test testing.xen --filter doubles.

    2. Build a program · Build word-count regression tests

    Section titled “2. Build a program · Build word-count regression tests”

    Extract count_words(text: String) -> Int from file reading and add separate tests for an empty string, whitespace only, and one two three.

    Completion: Expected counts are 0, 0, 3; all three tests pass without external files.

    Hint: Separating the calculation lets tests pass input directly.

    Run the failing test below. Keep the expectation 10 and fix the range bug in the function. Add tests with limits 0 and 1.

    fn sum_to(limit: Int) -> Int {
    let mut total = 0;
    for n in 1..limit { total = total + n; }
    return total;
    }
    test fn includes_limit() { assert(sum_to(4) == 10); }
    Terminal window
    xen test sum_to.xen

    Completion: All three tests pass, summing from 1 through limit inclusive.

    Hint: A range excludes its endpoint.

    Use xen check file.xen followed by xen run file.xen for ordinary programs; use xen test file.xen for test-only files. Record the original error, its cause, and the corrected result, then rerun every input in the completion criteria.