POLYTONE — the AI-native programming language

Guide

Testing

Tests are a language construct, not a library. Code carries its own verification — write the test next to the function and run ptc test.

fizzbuzz.pt
fn fizzbuzz(n: Int) -> Text:
    if n % 15 == 0:
        return "FizzBuzz"
    elif n % 3 == 0:
        return "Fizz"
    elif n % 5 == 0:
        return "Buzz"
    return "{n}"

test "multiples of three say Fizz":
    assert fizzbuzz(9) == "Fizz"

test "fifteen says FizzBuzz":
    assert fizzbuzz(15) == "FizzBuzz"

test "other numbers pass through":
    assert fizzbuzz(7) == "7"

When a comparison assert fails, the error reports both operand values — no more "assertion failed" archaeology:

doubling.pt
fn double(x: Int) -> Int = x + x

test "doubling four":
    assert double(4) == 8

test "this expectation is wrong":
    let xs = [1, 2].map(fn(x: Int) -> Int = double(x))
    assert xs == [2, 5]