mirror of
https://github.com/KarolS/millfork.git
synced 2024-12-29 02:31:45 +00:00
Create independent test suite
This commit is contained in:
parent
078b22869a
commit
017019ef5a
@ -37,6 +37,8 @@ If you are using a release version of the compiler, consider browsing the older
|
||||
|
||||
* [Life](crossplatform/life.mfk) (C64/C16/Atari/ZX Spectrum) – Conway's game of life
|
||||
|
||||
* [Test suite](tests) (C64/ZX Spectrum) – the semi-official test-suite for Millfork
|
||||
|
||||
## Commodore 64 examples
|
||||
|
||||
### Graphical examples
|
||||
|
41
examples/tests/framework.mfk
Normal file
41
examples/tests/framework.mfk
Normal file
@ -0,0 +1,41 @@
|
||||
import stdio
|
||||
import keyboard
|
||||
|
||||
pointer current_suite_name
|
||||
byte current_test_number
|
||||
word failure_count = 0
|
||||
|
||||
void start_suite(pointer suite_name) {
|
||||
putstrz("Running "z)
|
||||
putstrz(suite_name)
|
||||
new_line()
|
||||
current_suite_name = suite_name
|
||||
current_test_number = 0
|
||||
}
|
||||
|
||||
void print_failure() {
|
||||
putstrz("Test failed: "z)
|
||||
putstrz(current_suite_name)
|
||||
putstrz(" #"z)
|
||||
putword(current_test_number)
|
||||
new_line()
|
||||
failure_count += 1
|
||||
}
|
||||
|
||||
void assert_equal(word expected, word actual) {
|
||||
if actual != expected {
|
||||
print_failure()
|
||||
putstrz("Expected:"z)
|
||||
putword(expected)
|
||||
putstrz("Actual:"z)
|
||||
putword(actual)
|
||||
new_line()
|
||||
readkey()
|
||||
}
|
||||
}
|
||||
|
||||
void begin_test() {
|
||||
|
||||
}
|
||||
|
||||
void byte
|
8
examples/tests/main.mfk
Normal file
8
examples/tests/main.mfk
Normal file
@ -0,0 +1,8 @@
|
||||
import test_fibonacci
|
||||
|
||||
void main() {
|
||||
ensure_mixedcase()
|
||||
test_fibonacci()
|
||||
putstrz("Total failures: "z)
|
||||
putword(failure_count)
|
||||
}
|
18
examples/tests/test_fibonacci.mfk
Normal file
18
examples/tests/test_fibonacci.mfk
Normal file
@ -0,0 +1,18 @@
|
||||
import framework
|
||||
|
||||
word fib(byte n) {
|
||||
stack byte i
|
||||
i = n
|
||||
if i < 2 { return 1 }
|
||||
return fib(i-1) + fib(i-2)
|
||||
}
|
||||
|
||||
void test_fibonacci() {
|
||||
start_suite("Fibonacci"z)
|
||||
|
||||
assert_equal(1, fib(0))
|
||||
assert_equal(1, fib(1))
|
||||
assert_equal(2, fib(2))
|
||||
assert_equal(3, fib(3))
|
||||
assert_equal(5, fib(4))
|
||||
}
|
Loading…
Reference in New Issue
Block a user