diff options
| author | Gene Pasquet <dev@etenil.net> | 2026-04-08 01:57:20 +0100 |
|---|---|---|
| committer | Gene Pasquet <dev@etenil.net> | 2026-04-08 01:57:20 +0100 |
| commit | 9e8b75f9949259ef01942cd3717b79b044efddf7 (patch) | |
| tree | c6b71291ade57f0560a9bbf0db9f5b66bab65cb3 /tests/world-test.scm | |
| parent | 84840ede6646ed793b61cdd889d3f57ab05e9311 (diff) | |
Refactor update pipelines
Diffstat (limited to 'tests/world-test.scm')
| -rw-r--r-- | tests/world-test.scm | 42 |
1 files changed, 25 insertions, 17 deletions
diff --git a/tests/world-test.scm b/tests/world-test.scm index 1b368c0..48f492a 100644 --- a/tests/world-test.scm +++ b/tests/world-test.scm @@ -154,8 +154,8 @@ '(a b c) (map entity-type (scene-entities scene))))) -;; Test: scene-update-entities applies function to all entities -(test-group "scene-update-entities" +;; Test: scene-map-entities applies function to all entities +(test-group "scene-map-entities" (let* ((e1 '(#:type player #:x 100 #:y 100)) (e2 '(#:type enemy #:x 200 #:y 200)) (scene (make-scene entities: (list e1 e2) tilemap: #f camera-target: #f)) @@ -164,7 +164,7 @@ (y (entity-ref entity #:y)) (type (entity-ref entity #:type))) (list #:type type #:x (+ x 10) #:y y)))) - (scene2 (scene-update-entities scene move-right))) + (scene2 (scene-map-entities scene move-right))) (test-equal "original scene unchanged" 100 @@ -179,12 +179,12 @@ 100 (entity-ref (car (scene-entities scene2)) #:y)))) -;; Test: scene-update-entities with identity function -(test-group "scene-update-entities-identity" +;; Test: scene-map-entities with identity function +(test-group "scene-map-entities-identity" (let* ((e1 '(#:type player #:x 100)) (e2 '(#:type enemy #:x 200)) (scene (make-scene entities: (list e1 e2) tilemap: #f camera-target: #f)) - (scene2 (scene-update-entities scene (lambda (e) e)))) + (scene2 (scene-map-entities scene (lambda (e) e)))) (test-equal "entity count unchanged" 2 (length (scene-entities scene2))) (test-equal "first entity unchanged" @@ -199,7 +199,7 @@ (test-equal "entity added" 1 (length (scene-entities scene))) - (let ((scene (scene-update-entities scene + (let ((scene (scene-map-entities scene (lambda (e) (let ((x (entity-ref e #:x)) (y (entity-ref e #:y)) @@ -274,7 +274,7 @@ (test-equal "returns all friendly entities" 2 (length (scene-find-all-tagged s 'friendly))) (test-equal "returns empty list when none match" '() (scene-find-all-tagged s 'boss)))) - (test-group "scene-sync-groups" + (test-group "sync-groups" (let* ((gid 'g1) (origin (list #:type 'group-origin #:group-origin? #t #:group-id gid #:x 100 #:y 200 #:width 0 #:height 0)) @@ -282,14 +282,22 @@ #:x 0 #:y 0 #:width 8 #:height 8)) (m2 (list #:type 'part #:group-id gid #:group-local-x 0 #:group-local-y 7 #:x 0 #:y 0 #:width 8 #:height 8)) - (s (make-scene entities: (list origin m1 m2) tilemap: #f - camera: (make-camera x: 0 y: 0) tileset-texture: #f camera-target: #f)) - (s2 (scene-sync-groups s))) - (test-equal "original scene members unchanged" 0 (entity-ref (list-ref (scene-entities s) 1) #:x)) - (let ((es (scene-entities s2))) - (test-equal "member 1 follows origin" 105 (entity-ref (list-ref es 1) #:x)) - (test-equal "member 1 y" 200 (entity-ref (list-ref es 1) #:y)) - (test-equal "member 2 x" 100 (entity-ref (list-ref es 2) #:x)) - (test-equal "member 2 y" 207 (entity-ref (list-ref es 2) #:y))))) + (entities (list origin m1 m2)) + (result (sync-groups entities))) + (test-equal "original list unchanged" 0 (entity-ref (list-ref entities 1) #:x)) + (test-equal "member 1 follows origin" 105 (entity-ref (list-ref result 1) #:x)) + (test-equal "member 1 y" 200 (entity-ref (list-ref result 1) #:y)) + (test-equal "member 2 x" 100 (entity-ref (list-ref result 2) #:x)) + (test-equal "member 2 y" 207 (entity-ref (list-ref result 2) #:y)))) + + (test-group "scene-transform-entities" + (let* ((e1 '(#:type a #:x 1)) + (e2 '(#:type b #:x 2)) + (scene (make-scene entities: (list e1 e2) tilemap: #f camera-target: #f)) + (scene2 (scene-transform-entities scene reverse))) + (test-equal "transforms entity list" 'b + (entity-type (car (scene-entities scene2)))) + (test-equal "original scene unchanged" 'a + (entity-type (car (scene-entities scene)))))) (test-end "world-module") |
