Add entity tests
This commit is contained in:
parent
7238a4b33b
commit
a60d062335
4 changed files with 63 additions and 0 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,2 +1,3 @@
|
|||
/game.wasm
|
||||
/game.zip
|
||||
*.log
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#:use-module (logging)
|
||||
#:export (game-entity?
|
||||
game-entity-id
|
||||
game-entity-components
|
||||
create-entity
|
||||
copy-entity
|
||||
create-entity-generator
|
||||
|
|
58
test/tests/entity-test.scm
Normal file
58
test/tests/entity-test.scm
Normal file
|
@ -0,0 +1,58 @@
|
|||
(import (srfi srfi-64)
|
||||
(test-runner)
|
||||
(scheme base)
|
||||
(scheme write)
|
||||
|
||||
(ces entity)
|
||||
(lib ihashtable))
|
||||
|
||||
|
||||
(define-record-type <test-component>
|
||||
(make-test-component v1 v2)
|
||||
test-component?
|
||||
(v1 val-one)
|
||||
(v2 val-two))
|
||||
|
||||
;; We are using this id as our control
|
||||
(define control-id 333)
|
||||
(define control-component-name 'test-component)
|
||||
(define control-component-value (create-ihashtable))
|
||||
|
||||
;; te = test-entity
|
||||
(define te (create-entity control-id))
|
||||
(define te-with-components (create-entity (+ 1 control-id) control-component-value))
|
||||
(define entity-generator (create-entity-generator))
|
||||
|
||||
(test-runner-factory game-engine-test-runner)
|
||||
|
||||
(test-begin "test-entities")
|
||||
|
||||
(test-assert (integer? (game-entity-id te)))
|
||||
(test-assert (integer? (game-entity-id te-with-components)))
|
||||
(test-assert (ihashtable? (game-entity-components te)))
|
||||
(test-assert (ihashtable? (game-entity-components te-with-components)))
|
||||
|
||||
(test-assert (procedure? entity-generator))
|
||||
|
||||
(let ((generated-entity (entity-generator)))
|
||||
(test-assert (game-entity? generated-entity))
|
||||
(test-eqv 0 (game-entity-id generated-entity))
|
||||
(test-assert (ihashtable? (game-entity-components generated-entity))))
|
||||
|
||||
(let ((generated-entity (entity-generator)))
|
||||
(test-assert (game-entity? generated-entity))
|
||||
(test-eqv 1 (game-entity-id generated-entity))
|
||||
(test-assert (ihashtable? (game-entity-components generated-entity))))
|
||||
|
||||
(let* ((copied-entity (copy-entity te))
|
||||
(new-id (game-entity-id copied-entity))
|
||||
(new-components (game-entity-components copied-entity)))
|
||||
(test-assert (game-entity? copied-entity))
|
||||
(test-eqv control-id new-id)
|
||||
(test-assert (ihashtable? new-components)))
|
||||
|
||||
(test-end "test-entities")
|
||||
|
||||
#t
|
||||
|
||||
|
3
watch-tests
Executable file
3
watch-tests
Executable file
|
@ -0,0 +1,3 @@
|
|||
#!/bin/sh
|
||||
|
||||
watchexec -w . -d 2000 make check
|
Loading…
Reference in a new issue