t27.aiEnglish

Тест говорит да или нет

Вы узнаете

Как тест сравнивает то, что дал код, с ответом, который вы записали заранее, и почему да значит только то, о чём тест спросил.

Вы просите агента написать функцию, которая даёт большее из двух чисел. Код пока не читайте: сначала запишите ответ, который ждёте для 3 и 9, это 9. Тест запускает код, а судья сравнивает: да, если вышло 9, нет, если что-то другое. Судья видит только ответ, поэтому да значит лишь одно: для этих входов код согласен с вами. Вторая версия функции с ошибкой, которая всегда отдаёт левое число, даёт 3, и судья говорит нет.

Попробуйте

Запишите свой ответ для 3 и 9, запустите обе версии и прочитайте, что судья говорит каждой. Потом попробуйте 9 и 3 и посмотрите, какая версия всё равно получит да.

Открыть интерактивный урок →

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;
}

Открыть спеку урока в плеере ↗

Все уроки