Skip to content

Instantly share code, notes, and snippets.

@jbranchaud
Created March 12, 2013 15:53
Show Gist options
  • Save jbranchaud/5144062 to your computer and use it in GitHub Desktop.
Save jbranchaud/5144062 to your computer and use it in GitHub Desktop.
Verifying Fibonacci with Microsoft's Dafny
function method Fibonacci(n: int): int
requires n >= 0;
decreases n;
{
if n < 2 then n else Fibonacci(n-2) + Fibonacci(n-1)
}
method Testing() {
assert 0 == Fibonacci(0);
assert 1 == Fibonacci(1);
assert 1 == Fibonacci(2);
assert 2 == Fibonacci(3);
assert 3 == Fibonacci(4);
assert 5 == Fibonacci(5);
assert 8 == Fibonacci(6);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment