cmd/ugo/testdata/fibtc.ugo

Summary

Maintainability
Test Coverage
// Fibonacci test script
//
// runtime.Gosched() calls are required to test context
// cancellation/timeout and to abort VM execution

var fib
fib = func(n, a, b) {
    if n % 10 == 0 {
        Gosched()
    }
    if n == 0 {
        return a
    } else if n == 1 {
        return b
    }
    return fib(n-1, b, a+b)
}

try {
    if v := fib(35, 0, 1); v != int("9_227_465") {
        throw sprintf("fibonacci(35) result is wrong: %s", v)
    }
} catch err {
    // re-throw error for non-zero exit code
    throw sprintf("fibonacci test failed\n %+v\n", err)
} finally {
    if err == undefined {
        println("fibonacci test ok")
    }
}