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.
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"$ ptc test fizzbuzz.pt
Recorded output of the real compiler
When a comparison assert fails, the error reports both operand values — no more "assertion failed" archaeology:
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]$ ptc test doubling.pt
Recorded output of the real compiler