Created
August 13, 2011 14:15
-
-
Save draftcode/1143894 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fib := method(n, | |
| if (n == 1 or n == 2, return 1) | |
| p1 := 1 | |
| p2 := 1 | |
| for (i, 3, n, | |
| temp := p1 | |
| p1 := p1 + p2 | |
| p2 := temp) | |
| return p1 | |
| ) | |
| assert := method( | |
| actual := call sender doMessage(call message argAt(0)) | |
| expect := call sender doMessage(call message argAt(1)) | |
| if (actual != expect, Exception raise("Assertion failed: Expect #{expect} but got #{actual}" interpolate)) | |
| ) | |
| assert(fib(1), 1) | |
| assert(fib(2), 1) | |
| assert(fib(3), 2) | |
| assert(fib(4), 3) | |
| assert(fib(5), 5) | |
| assert(fib(6), 8) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fib := method(n, | |
| myself := call activated | |
| if (n == 1 or n == 2, 1, myself(n-1) + myself(n-2)) | |
| ) | |
| assert := method( | |
| actual := call sender doMessage(call message argAt(0)) | |
| expect := call sender doMessage(call message argAt(1)) | |
| if (actual != expect, Exception raise("Assertion failed: Expect #{expect} but got #{actual}" interpolate)) | |
| ) | |
| assert(fib(1), 1); | |
| assert(fib(2), 1); | |
| assert(fib(3), 2); | |
| assert(fib(4), 3); | |
| assert(fib(5), 5); | |
| assert(fib(6), 8); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment