t27.aiРусский

A test says yes or no

You will learn

How a test compares what the code gave with the answer you wrote down first, and why a yes means only what the test asked.

You ask an agent for a function that gives the larger of two numbers. Do not read its code yet: first write down the answer you expect for 3 and 9, which is 9. A test runs the code and the judge compares: yes if it gave 9, no if it gave anything else. The judge sees only the answer, so a yes means the code agrees with you for those inputs and nothing more. A second version of the function with a slip in it, always giving the leading number, gives 3, and the judge says no.

Try it

Write down your answer for 3 and 9, run both versions, and read what the judge says to each. Then try 9 and 3 and see which version still gets a yes.

Open the interactive lesson →

Vibecoding 16: a test says yes or no ↗

Write down the answer you expect, run two versions of a function, and watch the judge say yes to one and no to the other. Lesson 16 of the vibecoding course.

specs/vibecoding/test_judge.t27

// SPDX-License-Identifier: Apache-2.0
; specs/vibecoding/test_judge.t27 -- vibecoding lesson: a test says yes or no
; You ask an agent for a function that returns the larger of two numbers. You do not read
; every line it wrote. You write down the answer you expect and let a test judge: the
; judge says yes when what the code gave equals what you wanted, and no when it does not.
; larger is what the agent should write. larger_wrong is a plausible answer with a slip in
; it: it always returns the first number. The constants below are what each one gives for
; the inputs 3 and 9; the tests are the judge. The last test is the negative control: the
; judge must say no to the slip.
; phi^2 + 1/phi^2 = 3 | TRINITY

module vibecoding_test_judge;

pub fn larger(a: u8, b: u8) -> u8 {
    if (a > b) {
        return a;
    }
    return b;
}

pub fn larger_wrong(a: u8, b: u8) -> u8 {
    return a;
}

; What I expect for larger(3, 9), written down before I run anything.
pub const WANT : u8 = 9;
; What larger(3, 9) gives: 3 is not above 9, so it returns b.
pub const GOT : u8 = 9;
; What larger_wrong(3, 9) gives: its first argument.
pub const GOT_WRONG : u8 = 3;

test the_judge_says_yes_to_working_code {
    assert GOT == WANT;
}

test the_judge_does_not_see_inside_only_the_answer {
    assert GOT >= 3;
    assert GOT >= 9;
}

test negative_control_the_judge_says_no_to_the_slip {
    assert GOT_WRONG != WANT;
    assert GOT_WRONG < WANT;
}

Open the lesson's spec in the player ↗

All lessons