Skip to content

Commit

Permalink
WIP test suite
Browse files Browse the repository at this point in the history
  • Loading branch information
tkers committed Jul 26, 2019
1 parent a5c4019 commit a5af221
Show file tree
Hide file tree
Showing 4 changed files with 115 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ all: examples
examples: \
examples/hello-world-asm/hello.gb \
examples/hello-world/hello.gb \
examples/ans-test-suite/ans-test-suite.gb \
examples/happy-birthday/happy-birthday.gb \
examples/sokoban/sokoban.gb \
examples/synth/synth.gb
Expand All @@ -44,6 +45,7 @@ tests: $(TEST_OBJS)
clean:
-rm -f examples/hello-world-asm/hello.gb
-rm -f examples/hello-world/hello.gb
-rm -f examples/ans-test-suite/ans-test-suite.gb
-rm -f examples/happy-birthday/happy-birthday.gb
-rm -f examples/sokoban/sokoban.gb
-rm -f examples/synth/synth.gb
Expand Down
94 changes: 94 additions & 0 deletions examples/ans-test-suite/ans-test-suite.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
title: ANSTESTSUITE
gamecode: ANSF

require ibm-font.fs
require logger.fs
require tester.fs

variable #total
: }T 1 #total +! }T ;

: .progress
scroll-to-bottom
#total ? ." completed..." cr ;


0 CONSTANT 0S
0 INVERT CONSTANT 1S

: GI1 IF 123 THEN ;
: GI2 IF 123 ELSE 234 THEN ;

: GI3 BEGIN DUP 5 < WHILE DUP 1+ REPEAT ;

: GI4 BEGIN DUP 1+ DUP 5 > UNTIL ;

: GI5 BEGIN DUP 2 >
WHILE DUP 5 < WHILE DUP 1+ REPEAT 123 ELSE 345 THEN ;

: run-tests
log" BOOLEANS: INVERT AND OR XOR"

T{ 0 0 AND -> 0 }T
T{ 0 1 AND -> 0 }T
T{ 1 0 AND -> 0 }T
T{ 1 1 AND -> 1 }T .progress

T{ 0 INVERT 1 AND -> 1 }T
T{ 1 INVERT 1 AND -> 0 }T

T{ 0S INVERT -> 1S }T
T{ 1S INVERT -> 0S }T

T{ 0S 0S AND -> 0S }T
T{ 0S 1S AND -> 0S }T
T{ 1S 0S AND -> 0S }T
T{ 1S 1S AND -> 1S }T .progress

T{ 0S 0S OR -> 0S }T
T{ 0S 1S OR -> 1S }T
T{ 1S 0S OR -> 1S }T
T{ 1S 1S OR -> 1S }T

T{ 0S 0S XOR -> 0S }T
T{ 0S 1S XOR -> 1S }T
T{ 1S 0S XOR -> 1S }T
T{ 1S 1S XOR -> 0S }T .progress

log" IF ELSE THEN BEGIN WHILE REPEAT UNTIL"

T{ 0 GI1 -> }T
T{ 1 GI1 -> 123 }T
T{ -1 GI1 -> 123 }T
T{ 0 GI2 -> 234 }T
T{ 1 GI2 -> 123 }T
T{ -1 GI1 -> 123 }T .progress

T{ 0 GI3 -> 0 1 2 3 4 5 }T
T{ 4 GI3 -> 4 5 }T
T{ 5 GI3 -> 5 }T
T{ 6 GI3 -> 6 }T

T{ 3 GI4 -> 3 4 5 6 }T .progress
T{ 5 GI4 -> 5 6 }T
T{ 6 GI4 -> 6 7 }T

T{ 1 GI5 -> 1 345 }T
T{ 2 GI5 -> 2 345 }T
T{ 3 GI5 -> 3 4 5 123 }T
T{ 4 GI5 -> 4 5 123 }T
T{ 5 GI5 -> 5 123 }T .progress
;

: main
install-font
init-term
init-tester
0 #total !
page
run-tests
log" --------------------"
log" Test suite completed" cr
#total @ 4 .r space ." total" cr
#errors @ 4 .r space ." failures"
cr scroll-to-bottom ;
2 changes: 1 addition & 1 deletion test/gbtest.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ module.exports = filename => {
},

get frameSha() {
return getSha(frame);
return frame && getSha(frame);
},

get depth() {
Expand Down
18 changes: 18 additions & 0 deletions test/test-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,21 @@ describe("hello-world-asm", () => {
);
});
});

describe("ans-test-suite", () => {
const gb = require("./gbtest")(
path.resolve(__dirname, "../examples/ans-test-suite/ans-test-suite.gb")
);

test("all tests pass", () => {
gb.steps(10);
gb.run();
gb.steps(100);
gb.saveFrame(
path.resolve(__dirname, "../examples/ans-test-suite/ans-test-suite.png")
);
expect(gb.frameSha).toBe(
"1dded7c5cbaaa4b94377fc76574deffb0869ee65e9b72dfafae0604304fbe365"
);
});
});

0 comments on commit a5af221

Please sign in to comment.