From a60d06233596b630fb59835cf764ed14edb40e69 Mon Sep 17 00:00:00 2001 From: TakeV Date: Sun, 26 May 2024 18:20:52 -0400 Subject: [PATCH] Add entity tests --- .gitignore | 1 + modules/ces/entity.scm | 1 + test/tests/entity-test.scm | 58 ++++++++++++++++++++++++++++++++++++++ watch-tests | 3 ++ 4 files changed, 63 insertions(+) create mode 100644 test/tests/entity-test.scm create mode 100755 watch-tests diff --git a/.gitignore b/.gitignore index d1ab642..5a44a5a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /game.wasm /game.zip +*.log diff --git a/modules/ces/entity.scm b/modules/ces/entity.scm index 16e4e43..f95bcf6 100644 --- a/modules/ces/entity.scm +++ b/modules/ces/entity.scm @@ -14,6 +14,7 @@ #:use-module (logging) #:export (game-entity? game-entity-id + game-entity-components create-entity copy-entity create-entity-generator diff --git a/test/tests/entity-test.scm b/test/tests/entity-test.scm new file mode 100644 index 0000000..82b894b --- /dev/null +++ b/test/tests/entity-test.scm @@ -0,0 +1,58 @@ +(import (srfi srfi-64) + (test-runner) + (scheme base) + (scheme write) + + (ces entity) + (lib ihashtable)) + + +(define-record-type + (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 + + diff --git a/watch-tests b/watch-tests new file mode 100755 index 0000000..d06c16f --- /dev/null +++ b/watch-tests @@ -0,0 +1,3 @@ +#!/bin/sh + +watchexec -w . -d 2000 make check