(ns minibaldur.ecs-test (:require [clojure.test :refer :all] [minibaldur.ecs :refer :all])) (defcomponent age) (defcomponent name) (defentity (name "Cole") (age 26)) (defentity (name "Dane") (age 27)) (defn age-up [entity] (age entity (inc (age entity)))) (deftest basic (run-e age-up :age) (is (= 28 (age (find-by :name "Dane"))))) (defcomponent alignment) (defcomponent health) (defentity (name "Goblin") (alignment :evil) (health 10)) (defentity (name "Fey") (alignment :good) (health 2)) ;; Good alignment, will not be attacked (defentity (name "Evil Bystander") (alignment :evil)) ;; No health, will not be attacked (defn damage-evil-creatures [entity dmg] (when (= (alignment entity) :evil) (health entity (max 0 (- (health entity) dmg))))) (deftest full (run-e damage-evil-creatures [:alignment :health] 2) (is (= 2 (health (find-by :name "Fey")))) (is (= 8 (health (find-by :name "Goblin")))))