Add entity tests

This commit is contained in:
TakeV 2024-05-26 18:20:52 -04:00
parent 7238a4b33b
commit a60d062335
Signed by: TakeV
GPG key ID: A64F41345C7400AF
4 changed files with 63 additions and 0 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
/game.wasm
/game.zip
*.log

View file

@ -14,6 +14,7 @@
#:use-module (logging)
#:export (game-entity?
game-entity-id
game-entity-components
create-entity
copy-entity
create-entity-generator

View 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
View file

@ -0,0 +1,3 @@
#!/bin/sh
watchexec -w . -d 2000 make check