From ca4c403e749250f32896a63cd5a166d56bea47b6 Mon Sep 17 00:00:00 2001 From: Johannes Barre Date: Fri, 22 Dec 2023 21:29:52 +0100 Subject: [PATCH] Indicator (Kennlicht) added --- src/signals/demo/aspect.cljs | 10 +- src/signals/demo/features.cljs | 17 ++- src/signals/hl.cljs | 31 +++-- src/signals/hv_light.cljs | 129 +++++++++++-------- src/signals/hv_semaphore.cljs | 88 ++++++------- src/signals/ks.cljs | 112 ++++++++++------- src/signals/signal.cljs | 24 ++-- src/signals/spec.cljs | 2 +- test/signals/hl_test.cljs | 218 +++++++++++++++++++++++++++++++++ test/signals/hv_test.cljs | 196 +++++++++++++++++++++++++++++ test/signals/ks_test.cljs | 174 +++++++++++++++++++++++++- 11 files changed, 836 insertions(+), 165 deletions(-) diff --git a/src/signals/demo/aspect.cljs b/src/signals/demo/aspect.cljs index 5ed44ba..8de3b36 100644 --- a/src/signals/demo/aspect.cljs +++ b/src/signals/demo/aspect.cljs @@ -40,4 +40,12 @@ "Deaktiviere das Zs7" "Stelle das Signal auf Halt und aktiviere das Zs7") :active? zs7-active? - :type "danger"} "Zs7")))))) + :type "danger"} "Zs7"))) + (when (and (:indicator? main-state) + (not= :hv-semaphore (:system state))) + ($ :div + ($ button {:on-click #(set-state! {:aspect :off}) + :title "Betrieblich abschalten" + :active? (= :off current-aspect) + :type "light"} + "Aus")))))) diff --git a/src/signals/demo/features.cljs b/src/signals/demo/features.cljs index 31f3a8e..097ffe2 100644 --- a/src/signals/demo/features.cljs +++ b/src/signals/demo/features.cljs @@ -37,6 +37,14 @@ :type "info" :active? zs7?} "Zs7"))))) +(defui indicator-btn [{:keys [state set-state!]}] + (when-not (= :hv-semaphore (:system state)) + (let [indicator? (-> state :main :indicator?)] + ($ button {:on-click #(set-state! (update-in state [:main :indicator?] not)) + :type "info" + :active? indicator?} + "Kennlicht")))) + (defui speed-limit-config-btns [{:keys [set-state! state]}] (let [slow-speed-lights (-> state :main :slow-speed-lights seq) active-40? (some #{40} slow-speed-lights) @@ -108,8 +116,7 @@ (defui base [{:keys [main set-main! distant set-distant! set-both!]}] ($ :<> - ($ feature-btns {:set-state! set-main! :state main}) - ($ :div - ($ shortened-break-path-btn {:set-state! set-distant! :state distant})) - ($ :div - ($ speed-limit-config-btns {:set-state! set-both! :state main})))) + ($ :div ($ feature-btns {:set-state! set-main! :state main})) + ($ :div ($ indicator-btn {:set-state! set-main! :state main})) + ($ :div ($ shortened-break-path-btn {:set-state! set-distant! :state distant})) + ($ :div ($ speed-limit-config-btns {:set-state! set-both! :state main})))) diff --git a/src/signals/hl.cljs b/src/signals/hl.cljs index ed897aa..18906ff 100644 --- a/src/signals/hl.cljs +++ b/src/signals/hl.cljs @@ -21,25 +21,37 @@ (s/def ::lights (s/keys :req-un [::top-yellow ::top-green ::top-white ::red ::bottom-white ::bottom-yellow ::replacement-red ::green-stripe ::yellow-stripe ::shortened-break-path?])) -(defn lights [{{main-aspect :aspect +(defn lights [{{main-aspect* :aspect main-slow-speed-lights :slow-speed-lights main-speed-limit :speed-limit sh1? :sh1? - zs1? :zs1?} :main - {distant-aspect :aspect + zs1? :zs1? + main-indicator? :indicator?} :main + {distant-aspect* :aspect distant-slow-speed-lights :slow-speed-lights distant-speed-limit :speed-limit - distant-addition :distant-addition} :distant + distant-addition :distant-addition + distant-indicator? :indicator?} :distant signal-type :type :as signal}] {:pre [(p/arg! ::spec/signal signal)] :post [(p/ret! ::lights %)]} - (let [distant? (= :distant signal-type) + (let [main-aspect (if (and (= :off main-aspect*) + (not main-indicator?)) + :stop + main-aspect*) + distant-aspect (if (and (= :off distant-aspect*) + (not distant-indicator?)) + :stop + distant-aspect*) + distant? (= :distant signal-type) main? (= :main signal-type) distant-40-or-60-limit? (and (some #{40 60} distant-slow-speed-lights) (#{40 60} distant-speed-limit))] {:top-yellow (cond main? nil + (= :off main-aspect) :off + (= :off distant-aspect) :off (stop-aspect? main-aspect) :off (stop-aspect? distant-aspect) :on distant-40-or-60-limit? :blinking @@ -47,7 +59,9 @@ :top-green (cond (or (stop-aspect? main-aspect) (stop-aspect? distant-aspect) - distant-40-or-60-limit?) :off + distant-40-or-60-limit? + (= :off main-aspect) + (= :off distant-aspect)) :off (and (some #{100} distant-slow-speed-lights) (= 100 distant-speed-limit)) :blinking :else :on) @@ -57,10 +71,13 @@ :else :off) :red (cond distant? nil + (= :off main-aspect) :off (stop-aspect? main-aspect) :on :else :off) :bottom-white (cond - (not (or sh1? zs1?)) nil + (not (or sh1? zs1? main-indicator? distant-indicator?)) nil + (= :off main-aspect) :on + (= :off distant-aspect) :on (and sh1? (= :stop+sh1 main-aspect)) :on (and zs1? (= :stop+zs1 main-aspect)) :blinking :else :off) diff --git a/src/signals/hv_light.cljs b/src/signals/hv_light.cljs index 2e47f0c..f53924c 100644 --- a/src/signals/hv_light.cljs +++ b/src/signals/hv_light.cljs @@ -27,70 +27,85 @@ (s/def ::lights (s/keys :req-un [::distant ::main])) -(defn lights [{{main-aspect :aspect +(defn lights [{{main-aspect* :aspect main-slow-speed-lights :slow-speed-lights main-speed-limit :speed-limit + main-indicator? :indicator? sh1? :sh1? zs1? :zs1? zs7? :zs7?} :main - {distant-aspect :aspect + {distant-aspect* :aspect distant-slow-speed-lights :slow-speed-lights distant-speed-limit :speed-limit - distant-addition :distant-addition} :distant + distant-addition :distant-addition + distant-indicator? :indicator?} :distant signal-type :type :as signal}] {:pre [(p/arg! ::spec/signal signal)] :post [(p/ret! ::lights %)]} - {:main (when-not (= :distant signal-type) - {:green (if (stop-aspect? main-aspect) :off :on) - :red (if (stop-aspect? main-aspect) :on :off) - :yellow (let [has-light? (some #{40} main-slow-speed-lights)] - (cond - (not has-light?) nil - (and (not (stop-aspect? main-aspect)) - main-speed-limit (>= 60 main-speed-limit)) :on - :else :off)) - :secondary-red (cond - (not sh1?) nil - (= :stop+sh1 main-aspect) :off - (stop-aspect? main-aspect) :on - :else :off) - :sh1 (cond - (not sh1?) nil - (= :stop+sh1 main-aspect) :on - :else :off) - :zs1 (cond - (not zs1?) nil - (= :stop+zs1 main-aspect) :on - :else :off) - :zs7 (cond - (not zs7?) nil - (= :stop+zs7 main-aspect) :on - :else :off)}) - :distant (when-not (= :main signal-type) - (let [slow-speed? (and (some #{40} distant-slow-speed-lights) - distant-speed-limit - (>= 60 distant-speed-limit))] - {:top-green (cond - (stop-aspect? main-aspect) :off - (stop-aspect? distant-aspect) :off - :else :on) - :top-yellow (cond - (stop-aspect? main-aspect) :off - (stop-aspect? distant-aspect) :on + (let [main-aspect (if (and (not main-indicator?) + (= :off main-aspect*)) :stop main-aspect*) + distant-aspect (if (and (not distant-indicator?) + (= :off distant-aspect*)) :stop distant-aspect*)] + {:main (when-not (= :distant signal-type) + {:green (if (or (stop-aspect? main-aspect) + (= :off main-aspect)) :off :on) + :red (if (stop-aspect? main-aspect) :on :off) + :yellow (let [has-light? (some #{40} main-slow-speed-lights)] + (cond + (not has-light?) nil + (and (not (stop-aspect? main-aspect)) + (not (= :off main-aspect)) + main-speed-limit (>= 60 main-speed-limit)) :on + :else :off)) + :secondary-red (cond + (not sh1?) nil + (= :stop+sh1 main-aspect) :off + (stop-aspect? main-aspect) :on :else :off) - :white (when distant-addition - (if (stop-aspect? main-aspect) :off :on)) - :bottom-green (cond + :indicator (cond + (not main-indicator?) nil + (= :off main-aspect) :on + :else :off) + :sh1 (cond + (not sh1?) nil + (= :stop+sh1 main-aspect) :on + :else :off) + :zs1 (cond + (not zs1?) nil + (= :stop+zs1 main-aspect) :on + :else :off) + :zs7 (cond + (not zs7?) nil + (= :stop+zs7 main-aspect) :on + :else :off)}) + :distant (when-not (= :main signal-type) + (let [slow-speed? (and (some #{40} distant-slow-speed-lights) + distant-speed-limit + (>= 60 distant-speed-limit))] + {:top-green (cond + (stop-aspect? main-aspect) :off + (stop-aspect? distant-aspect) :off + (= :off distant-aspect) :off + :else :on) + :top-yellow (cond (stop-aspect? main-aspect) :off - (stop-aspect? distant-aspect) :off - slow-speed? :off - :else :on) - :bottom-yellow (cond - (stop-aspect? main-aspect) :off - (stop-aspect? distant-aspect) :on - slow-speed? :on - :else :off)}))}) + (stop-aspect? distant-aspect) :on + :else :off) + :white (cond + distant-addition (if (stop-aspect? main-aspect) :off :on) + distant-indicator? (if (= :off distant-aspect) :on :off)) + :bottom-green (cond + (stop-aspect? main-aspect) :off + (stop-aspect? distant-aspect) :off + (= :off distant-aspect) :off + slow-speed? :off + :else :on) + :bottom-yellow (cond + (stop-aspect? main-aspect) :off + (stop-aspect? distant-aspect) :on + slow-speed? :on + :else :off)}))})) (defui zs1+zs7-view [{:keys [zs1 zs7]}] (when (or zs1 zs7) @@ -129,7 +144,7 @@ (defui view [{:keys [signal]}] {:pre [(p/arg! ::spec/signal signal)]} - (let [{{:keys [green red yellow secondary-red sh1] :as main} :main + (let [{{:keys [green red yellow secondary-red sh1 indicator] :as main} :main {:keys [top-green top-yellow white bottom-green bottom-yellow]} :distant} (lights signal)] ($ :<> (when main @@ -156,6 +171,11 @@ :size :big :x 65 :y 44}) + ($ lamp/lamp {:color :white + :state indicator + :size :small + :x 38 + :y 68}) ($ lamp/lamp {:color :white :state sh1 :size :small @@ -185,6 +205,11 @@ :size :big :x 43 :y 126}) + ($ lamp/lamp {:color :white + :state indicator + :size :small + :x 51.5 + :y 68}) ($ lamp/lamp {:color :green :state green :size :big diff --git a/src/signals/hv_semaphore.cljs b/src/signals/hv_semaphore.cljs index 8c8131b..41ce009 100644 --- a/src/signals/hv_semaphore.cljs +++ b/src/signals/hv_semaphore.cljs @@ -23,13 +23,13 @@ (s/def ::arms (s/keys :req-un [::distant ::main])) -(defn arms [{{main-aspect :aspect +(defn arms [{{main-aspect* :aspect main-slow-speed-lights :slow-speed-lights main-speed-limit :speed-limit sh1? :sh1? zs1? :zs1? zs7? :zs7?} :main - {distant-aspect :aspect + {distant-aspect* :aspect distant-slow-speed-lights :slow-speed-lights distant-speed-limit :speed-limit distant-addition :distant-addition} :distant @@ -37,47 +37,49 @@ :as signal}] {:pre [(p/arg! ::spec/signal signal)] :post [(p/ret! ::arms %)]} - {:main (when-not (= :distant signal-type) - {:top-arm (if (stop-aspect? main-aspect) :horizontal :inclined) - :lower-arm (cond - (not (some #{40} main-slow-speed-lights)) nil - (and (not (stop-aspect? main-aspect)) - main-speed-limit - (>= 60 main-speed-limit)) :inclined - :else :vertical) - :sh1 (cond - (not sh1?) nil - (#{:proceed :stop+sh1} main-aspect) :inclined - :else :horizontal) - :zs1 (cond - (not zs1?) nil - (= :stop+zs1 main-aspect) :on - :else :off) - :zs7 (cond - (not zs7?) nil - (= :stop+zs7 main-aspect) :on - :else :off)}) - :distant (when (and (not= :main signal-type) - (not= :repeater distant-addition)) - (let [has-slow-speed? (some #{40} distant-slow-speed-lights) - slow-speed? (and has-slow-speed? - (not (stop-aspect? main-aspect)) - (not (stop-aspect? distant-aspect)) - distant-speed-limit - (>= 60 distant-speed-limit))] - {:disk (if (or (stop-aspect? main-aspect) - (stop-aspect? distant-aspect) - slow-speed?) :vertical - :horizontal) - :arm (cond - (not has-slow-speed?) nil - slow-speed? :inclined - :else :vertical) - :right-lights (if (and (not (stop-aspect? main-aspect)) - (not (stop-aspect? distant-aspect))) - :inclined - :vertical) - :shortened-break-path? (= :shortened-break-path distant-addition)}))}) + (let [main-aspect (if (= :off main-aspect*) :stop main-aspect*) + distant-aspect (if (= :off distant-aspect*) :stop distant-aspect*)] + {:main (when-not (= :distant signal-type) + {:top-arm (if (stop-aspect? main-aspect) :horizontal :inclined) + :lower-arm (cond + (not (some #{40} main-slow-speed-lights)) nil + (and (not (stop-aspect? main-aspect)) + main-speed-limit + (>= 60 main-speed-limit)) :inclined + :else :vertical) + :sh1 (cond + (not sh1?) nil + (#{:proceed :stop+sh1} main-aspect) :inclined + :else :horizontal) + :zs1 (cond + (not zs1?) nil + (= :stop+zs1 main-aspect) :on + :else :off) + :zs7 (cond + (not zs7?) nil + (= :stop+zs7 main-aspect) :on + :else :off)}) + :distant (when (and (not= :main signal-type) + (not= :repeater distant-addition)) + (let [has-slow-speed? (some #{40} distant-slow-speed-lights) + slow-speed? (and has-slow-speed? + (not (stop-aspect? main-aspect)) + (not (stop-aspect? distant-aspect)) + distant-speed-limit + (>= 60 distant-speed-limit))] + {:disk (if (or (stop-aspect? main-aspect) + (stop-aspect? distant-aspect) + slow-speed?) :vertical + :horizontal) + :arm (cond + (not has-slow-speed?) nil + slow-speed? :inclined + :else :vertical) + :right-lights (if (and (not (stop-aspect? main-aspect)) + (not (stop-aspect? distant-aspect))) + :inclined + :vertical) + :shortened-break-path? (= :shortened-break-path distant-addition)}))})) (defui main-lights [{:keys [position top-color bottom-color]}] (let [colors {:red "#e64e54" diff --git a/src/signals/ks.cljs b/src/signals/ks.cljs index 60b0eb0..018c14e 100644 --- a/src/signals/ks.cljs +++ b/src/signals/ks.cljs @@ -18,64 +18,84 @@ (defn lights "Converts a signal definition into a list of lights and their state" - [{{main-aspect :aspect + [{{main-aspect* :aspect sh1? :sh1? zs1? :zs1? - zs7? :zs7?} :main - {distant-aspect :aspect + zs7? :zs7? + main-indicator? :indicator?} :main + {distant-aspect* :aspect distant-speed-limit :speed-limit distant-addition :distant-addition - zs3 :zs3} :distant + zs3 :zs3 + distant-indicator? :indicator?} :distant signal-type :type :as signal}] {:pre [(p/arg! ::signal/signal signal)] :post [(p/ret! ::lights %)]} - {:top-white (cond - (not= :shortened-break-path distant-addition) nil - (stop-aspect? main-aspect) :off - (or (stop-aspect? distant-aspect) - (and distant-speed-limit zs3)) :on - :else :off) - :red (cond - (= :distant signal-type) nil - (stop-aspect? main-aspect) :on - :else :off) - :green (cond - (stop-aspect? main-aspect) :off - (stop-aspect? distant-aspect) :off - (and distant-speed-limit zs3) :blinking - :else :on) - :yellow (cond - (= :main signal-type) nil - (stop-aspect? main-aspect) :off - (stop-aspect? distant-aspect) :on - :else :off) - :center-white (cond - (and (not sh1?) - (or (not zs1?) - (not= :main signal-type))) nil - (= :stop+sh1 main-aspect) :on - (and (= :main signal-type) - (= :stop+zs1 main-aspect)) :blinking - :else :off) - :zs7 (cond - (not zs7?) nil - (= :stop+zs7 main-aspect) :on - :else :off) - :bottom-white (if (= :distant signal-type) - (cond - (not= :repeater distant-addition) nil - (or (stop-aspect? distant-aspect) - (and distant-speed-limit zs3)) :on - :else :off) - (cond + (let [main-aspect (if (and (= :off main-aspect*) + (not main-indicator?)) + :stop + main-aspect*) + distant-aspect (if (and (= :off distant-aspect*) + (not distant-indicator?)) + :stop + distant-aspect*)] + {:top-white (cond + (= :shortened-break-path distant-addition) + (cond + (stop-aspect? main-aspect) :off + (or (stop-aspect? distant-aspect) + (and distant-speed-limit zs3)) :on + :else :off) + + distant-indicator? + (if (= :off distant-aspect) :on :off) + + main-indicator? + (if (= :off main-aspect) :on :off)) + :red (cond + (= :distant signal-type) nil + (stop-aspect? main-aspect) :on + :else :off) + :green (cond + (or (stop-aspect? main-aspect) + (stop-aspect? distant-aspect) + (= :off main-aspect) + (= :off distant-aspect)) :off + (and distant-speed-limit zs3) :blinking + :else :on) + :yellow (cond + (= :main signal-type) nil + (or (stop-aspect? main-aspect) + (= :off main-aspect)) :off + (stop-aspect? distant-aspect) :on + :else :off) + :center-white (cond (and (not sh1?) (or (not zs1?) - (not= :combination signal-type))) nil + (not= :main signal-type))) nil (= :stop+sh1 main-aspect) :on - (and (= :combination signal-type) + (and (= :main signal-type) (= :stop+zs1 main-aspect)) :blinking - :else :off))}) + :else :off) + :zs7 (cond + (not zs7?) nil + (= :stop+zs7 main-aspect) :on + :else :off) + :bottom-white (if (= :distant signal-type) + (cond + (not= :repeater distant-addition) nil + (or (stop-aspect? distant-aspect) + (and distant-speed-limit zs3)) :on + :else :off) + (cond + (and (not sh1?) + (or (not zs1?) + (not= :combination signal-type))) nil + (= :stop+sh1 main-aspect) :on + (and (= :combination signal-type) + (= :stop+zs1 main-aspect)) :blinking + :else :off))})) (defui view [{:keys [signal]}] {:pre [(p/arg! ::signal/signal signal)]} diff --git a/src/signals/signal.cljs b/src/signals/signal.cljs index a135ecd..d15b60e 100644 --- a/src/signals/signal.cljs +++ b/src/signals/signal.cljs @@ -79,8 +79,8 @@ (defn main "Constructor for a main signal" - [{:keys [aspect speed-limit slow-speed-lights sh1? zs1? zs3 zs7? system] - :or {aspect :stop sh1? false zs1? false zs3 nil zs7? false slow-speed-lights []}}] + [{:keys [aspect speed-limit slow-speed-lights sh1? zs1? zs3 zs7? indicator? system] + :or {aspect :stop sh1? false zs1? false zs7? false slow-speed-lights []}}] {:post [(p/ret! ::spec/signal %)]} {:system system :type :main @@ -90,12 +90,13 @@ :sh1? sh1? :zs1? zs1? :zs3 zs3 - :zs7? zs7?}}) + :zs7? zs7? + :indicator? indicator?}}) (defn distant "Constructor for a distant signal" - [{:keys [aspect speed-limit slow-speed-lights distant-addition zs3 system] - :or {aspect :stop zs3 nil slow-speed-lights []}}] + [{:keys [aspect speed-limit slow-speed-lights distant-addition zs3 indicator? system] + :or {aspect :stop slow-speed-lights []}}] {:post [(p/ret! ::spec/signal %)]} {:system system :type :distant @@ -103,21 +104,24 @@ :speed-limit speed-limit :distant-addition distant-addition :slow-speed-lights slow-speed-lights - :zs3 zs3}}) + :zs3 zs3 + :indicator? indicator?}}) (defn combination "Constructor for a combination of a main & distant signal" [{{distant-aspect :aspect distant-speed-limit :speed-limit distant-slow-speed-lights :slow-speed-lights + distant-indicator? :indicator? zs3v :zs3 :keys [distant-addition] :or {distant-aspect :stop distant-slow-speed-lights []}} :distant {main-aspect :aspect main-speed-limit :speed-limit main-slow-speed-lights :slow-speed-lights + main-indicator? :indicator? :keys [sh1? zs1? zs3 zs7?] - :or {main-aspect :stop sh1? false zs1? false zs3 nil zs7? false main-slow-speed-lights []}} :main + :or {main-aspect :stop sh1? false zs1? false zs7? false main-slow-speed-lights []}} :main system :system}] {:post [(p/ret! ::spec/signal %)]} {:system system @@ -126,11 +130,13 @@ :speed-limit distant-speed-limit :distant-addition distant-addition :slow-speed-lights distant-slow-speed-lights - :zs3 zs3v} + :zs3 zs3v + :indicator? distant-indicator?} :main {:aspect main-aspect :speed-limit main-speed-limit :slow-speed-lights main-slow-speed-lights :sh1? sh1? :zs1? zs1? :zs3 zs3 - :zs7? zs7?}}) + :zs7? zs7? + :indicator? main-indicator?}}) diff --git a/src/signals/spec.cljs b/src/signals/spec.cljs index 2bd2acb..e08e9c6 100644 --- a/src/signals/spec.cljs +++ b/src/signals/spec.cljs @@ -3,7 +3,7 @@ [cljs.spec.alpha :as s])) ;; Aspects -(s/def ::aspect #{:stop :proceed :stop+zs1 :stop+zs7 :stop+sh1}) +(s/def ::aspect #{:stop :proceed :stop+zs1 :stop+zs7 :stop+sh1 :off}) (s/def ::speed-limit (s/nilable (s/and int? pos?))) ;; Configuration diff --git a/test/signals/hl_test.cljs b/test/signals/hl_test.cljs index 3365b4e..5159066 100644 --- a/test/signals/hl_test.cljs +++ b/test/signals/hl_test.cljs @@ -208,6 +208,53 @@ :system :hl}) hl/lights))))) + (testing "off" + (testing "distant shows Hl10" + (is (= {:top-yellow :on + :top-green :off + :top-white nil + :red nil + :bottom-white nil + :bottom-yellow nil + :replacement-red nil + :green-stripe nil + :yellow-stripe nil + :shortened-break-path? false} + (-> (signal/distant {:aspect :off + :system :hl}) + hl/lights)))) + + (testing "combination shows Hp0" + (is (= {:top-yellow :off + :top-green :off + :top-white nil + :red :on + :bottom-white nil + :bottom-yellow nil + :replacement-red :off + :green-stripe nil + :yellow-stripe nil + :shortened-break-path? false} + (-> (signal/combination {:distant {:aspect :stop} + :main {:aspect :off} + :system :hl}) + hl/lights)))) + + (testing "main shows Hp0" + (is (= {:top-yellow nil + :top-green :off + :top-white nil + :red :on + :bottom-white nil + :bottom-yellow nil + :replacement-red :off + :green-stripe nil + :yellow-stripe nil + :shortened-break-path? false} + (-> (signal/main {:aspect :off + :system :hl}) + hl/lights))))) + (testing "proceed" (testing "distant shows Hl1" (is (= {:top-yellow :off @@ -549,6 +596,177 @@ :system :hl}) hl/lights)))))) + (testing "indicator" + (testing "stop" + (testing "distant shows Hl10" + (is (= {:top-yellow :on + :top-green :off + :top-white nil + :red nil + :bottom-white :off + :bottom-yellow nil + :replacement-red nil + :green-stripe nil + :yellow-stripe nil + :shortened-break-path? false} + (-> (signal/distant {:aspect :stop + :indicator? true + :system :hl}) + hl/lights)))) + + (testing "combination shows Hp0" + (is (= {:top-yellow :off + :top-green :off + :top-white nil + :red :on + :bottom-white :off + :bottom-yellow nil + :replacement-red :off + :green-stripe nil + :yellow-stripe nil + :shortened-break-path? false} + (-> (signal/combination {:distant {:aspect :stop} + :main {:aspect :stop + :indicator? true} + :system :hl}) + hl/lights)))) + + (testing "main shows Hp0" + (is (= {:top-yellow nil + :top-green :off + :top-white nil + :red :on + :bottom-white :off + :bottom-yellow nil + :replacement-red :off + :green-stripe nil + :yellow-stripe nil + :shortened-break-path? false} + (-> (signal/main {:aspect :stop + :indicator? true + :system :hl}) + hl/lights))))) + + (testing "off" + (testing "distant shows indicator" + (is (= {:top-yellow :off + :top-green :off + :top-white nil + :red nil + :bottom-white :on + :bottom-yellow nil + :replacement-red nil + :green-stripe nil + :yellow-stripe nil + :shortened-break-path? false} + (-> (signal/distant {:aspect :off + :indicator? true + :system :hl}) + hl/lights)))) + + (testing "combination shows indicator" + (is (= {:top-yellow :off + :top-green :off + :top-white nil + :red :off + :bottom-white :on + :bottom-yellow nil + :replacement-red :off + :green-stripe nil + :yellow-stripe nil + :shortened-break-path? false} + (-> (signal/combination {:distant {:aspect :stop} + :main {:aspect :off + :indicator? true} + :system :hl}) + hl/lights)))) + + (testing "main shows indicator" + (is (= {:top-yellow nil + :top-green :off + :top-white nil + :red :off + :bottom-white :on + :bottom-yellow nil + :replacement-red :off + :green-stripe nil + :yellow-stripe nil + :shortened-break-path? false} + (-> (signal/main {:aspect :off + :indicator? true + :system :hl}) + hl/lights)))) + + (testing "in combination with sh1" + (testing "combination shows indicator" + (is (= {:top-yellow :off + :top-green :off + :top-white :off + :red :off + :bottom-white :on + :bottom-yellow nil + :replacement-red :off + :green-stripe nil + :yellow-stripe nil + :shortened-break-path? false} + (-> (signal/combination {:distant {:aspect :stop} + :main {:aspect :off + :sh1? true + :indicator? true} + :system :hl}) + hl/lights)))) + + (testing "main shows indicator" + (is (= {:top-yellow nil + :top-green :off + :top-white :off + :red :off + :bottom-white :on + :bottom-yellow nil + :replacement-red :off + :green-stripe nil + :yellow-stripe nil + :shortened-break-path? false} + (-> (signal/main {:aspect :off + :sh1? true + :indicator? true + :system :hl}) + hl/lights)))))) + + (testing "proceed" + (testing "combination with stop+zs1 expected shows Hl10" + (is (= {:top-yellow :on + :top-green :off + :top-white nil + :red :off + :bottom-white :off + :bottom-yellow nil + :replacement-red :off + :green-stripe nil + :yellow-stripe nil + :shortened-break-path? false} + (-> (signal/combination {:distant {:aspect :stop+zs1} + :main {:aspect :proceed + :indicator? true} + :system :hl}) + hl/lights)))) + + (testing "main shows Hl1" + (is (= {:top-yellow nil + :top-green :on + :top-white nil + :red :off + :bottom-white :off + :bottom-yellow nil + :replacement-red :off + :green-stripe nil + :yellow-stripe nil + :shortened-break-path? false} + (-> (signal/main {:aspect :proceed + :indicator? true + :system :hl}) + hl/lights)))))) + (testing "slow-speed-lights" (testing "with 40" (testing "stop" diff --git a/test/signals/hv_test.cljs b/test/signals/hv_test.cljs index e6da6d4..0afbe69 100644 --- a/test/signals/hv_test.cljs +++ b/test/signals/hv_test.cljs @@ -10,6 +10,7 @@ :red :on :yellow nil :secondary-red nil + :indicator nil :sh1 nil :zs1 nil :zs7 nil}}) @@ -18,6 +19,7 @@ :red :off :yellow nil :secondary-red nil + :indicator nil :sh1 nil :zs1 nil :zs7 nil}}) @@ -26,6 +28,7 @@ :red :off :yellow :on :secondary-red nil + :indicator nil :sh1 nil :zs1 nil :zs7 nil}}) @@ -273,6 +276,42 @@ :system :hv-semaphore}) lights-or-arms))))) + (testing "off" + (testing "distant shows vr0" + (is (= (merge no-hp light-vr0) + (-> (signal/distant {:aspect :off + :system :hv-light}) + lights-or-arms))) + + (is (= (merge no-hp semaphore-vr0) + (-> (signal/distant {:aspect :off + :system :hv-semaphore}) + lights-or-arms)))) + + (testing "main shows hp0" + (is (= (merge light-hp0 no-vr) + (-> (signal/main {:aspect :off + :system :hv-light}) + lights-or-arms))) + + (is (= (merge semaphore-hp0 no-vr) + (-> (signal/main {:aspect :off + :system :hv-semaphore}) + lights-or-arms)))) + + (testing "combination shows hp0" + (is (= (merge light-hp0 light-vr-off) + (-> (signal/combination {:main {:aspect :off} + :distant {:aspect :off} + :system :hv-light}) + lights-or-arms))) + + (is (= (merge semaphore-hp0 semaphore-vr0) + (-> (signal/combination {:main {:aspect :off} + :distant {:aspect :off} + :system :hv-semaphore}) + lights-or-arms))))) + (testing "proceed" (testing "distant shows vr1" (is (= (merge no-hp light-vr1) @@ -1180,6 +1219,163 @@ :distant {:aspect :stop :slow-speed-lights [40]} :system :hv-semaphore}) + lights-or-arms))))))) + + (testing "indicator" + (testing "stop" + (testing "distant shows vr0" + (is (= (merge no-hp (add-to-distant light-vr0 {:white :off})) + (-> (signal/distant {:aspect :stop + :indicator? true + :system :hv-light}) + lights-or-arms)))) + + (testing "main shows hp0" + (is (= (merge (add-to-main light-hp0 {:yellow :off + :indicator :off}) + no-vr) + (-> (signal/main {:aspect :stop + :slow-speed-lights [40] + :indicator? true + :system :hv-light}) + lights-or-arms)))) + + (testing "combination shows hp0" + (is (= (merge (add-to-main light-hp0 {:yellow :off + :indicator :off}) + light-vr-off) + (-> (signal/combination {:main {:aspect :stop + :slow-speed-lights [40] + :indicator? true} + :distant {:aspect :stop} + :system :hv-light}) + lights-or-arms))) + + (is (= (merge (add-to-main light-hp0 {:yellow :off + :indicator :off}) + light-vr-off) + (-> (signal/combination {:main {:aspect :stop + :slow-speed-lights [40] + :indicator? true} + :distant {:aspect :proceed} + :system :hv-light}) + lights-or-arms))) + + (is (= (merge (add-to-main light-hp0 {:yellow :off}) + (add-to-distant light-vr-off {:white :off})) + (-> (signal/combination {:main {:aspect :stop + :slow-speed-lights [40]} + :distant {:aspect :stop + :indicator? true} + :system :hv-light}) + lights-or-arms))))) + + (testing "off" + (testing "semaphore" + (testing "distant shows vr0" + (is (= (merge no-hp semaphore-vr0) + (-> (signal/distant {:aspect :off + :indicator? true + :system :hv-semaphore}) + lights-or-arms)))) + + (testing "main shows hp0" + (is (= (merge semaphore-hp0 no-vr) + (-> (signal/main {:aspect :off + :indicator? true + :system :hv-semaphore}) + lights-or-arms)))) + + (testing "combination shows hp0" + (is (= (merge (add-to-main semaphore-hp0 {:lower-arm :vertical}) + semaphore-vr0) + (-> (signal/combination {:main {:aspect :off + :slow-speed-lights [40] + :indicator? true} + :distant {:aspect :stop} + :system :hv-semaphore}) + lights-or-arms))) + + (is (= (merge semaphore-hp0 semaphore-vr0) + (-> (signal/combination {:main {:aspect :stop} + :distant {:aspect :off + :indicator? true} + :system :hv-semaphore}) + lights-or-arms))))) + + (testing "light signal" + (testing "distant shows indicator" + (is (= (merge no-hp (add-to-distant light-vr-off {:white :on})) + (-> (signal/distant {:aspect :off + :indicator? true + :system :hv-light}) + lights-or-arms)))) + + (testing "main shows indicator" + (is (= (merge (add-to-main light-hp0 {:yellow :off + :red :off + :indicator :on}) + no-vr) + (-> (signal/main {:aspect :off + :slow-speed-lights [40] + :indicator? true + :system :hv-light}) + lights-or-arms)))) + + (testing "combination" + (testing "distant off" + (is (= (merge (add-to-main light-hp0 {:yellow :off}) + (add-to-distant light-vr-off {:white :on})) + (-> (signal/combination {:main {:aspect :stop + :slow-speed-lights [40]} + :distant {:aspect :off + :indicator? true} + :system :hv-light}) + lights-or-arms)))) + + (testing "main off" + (is (= (merge (add-to-main light-hp0 {:yellow :off + :red :off + :indicator :on}) + light-vr0) + (-> (signal/combination {:main {:aspect :off + :slow-speed-lights [40] + :indicator? true} + :distant {:aspect :stop} + :system :hv-light}) + lights-or-arms))) + + (is (= (merge (add-to-main light-hp0 {:yellow :off + :red :off + :indicator :on}) + light-vr1) + (-> (signal/combination {:main {:aspect :off + :slow-speed-lights [40] + :indicator? true} + :distant {:aspect :proceed} + :system :hv-light}) + lights-or-arms))))))) + + (testing "proceed" + (testing "main shows hp1" + (is (= (merge (add-to-main light-hp1 {:indicator :off}) + no-vr) + (-> (signal/main {:aspect :proceed + :indicator? true + :system :hv-light}) + lights-or-arms)))) + + (testing "combination" + (testing "with stop expected shows hp1 & vr0" + (is (= (merge (add-to-main light-hp1 {:yellow :off + :indicator :off}) + light-vr0) + (-> (signal/combination {:main {:aspect :proceed + :slow-speed-lights [40] + :indicator? true} + :distant {:aspect :stop + :slow-speed-lights [40]} + :system :hv-light}) lights-or-arms)))))))) (deftest speed-limit-available? diff --git a/test/signals/ks_test.cljs b/test/signals/ks_test.cljs index eb58946..9abc1df 100644 --- a/test/signals/ks_test.cljs +++ b/test/signals/ks_test.cljs @@ -182,6 +182,69 @@ :system :ks}) ks/lights))))) + (testing "off" + (testing "distant shows ks2" + (is (= {:top-white nil + :red nil + :green :off + :yellow :on + :center-white nil + :zs7 nil + :bottom-white nil} + (-> (signal/distant {:aspect :off + :system :ks}) + ks/lights)))) + + (testing "repeater shows ks2 & bottom white" + (is (= {:top-white nil + :red nil + :green :off + :yellow :on + :center-white nil + :zs7 nil + :bottom-white :on} + (-> (signal/distant {:aspect :off + :distant-addition :repeater + :system :ks}) + ks/lights)))) + + (testing "combination shows hp0" + (is (= {:top-white nil + :red :on + :green :off + :yellow :off + :center-white nil + :zs7 nil + :bottom-white nil} + (-> (signal/combination {:distant {:aspect :stop} + :main {:aspect :off} + :system :ks}) + ks/lights))) + + (is (= {:top-white nil + :red :on + :green :off + :yellow :off + :center-white nil + :zs7 nil + :bottom-white nil} + (-> (signal/combination {:distant {:aspect :off} + :main {:aspect :stop} + :system :ks}) + ks/lights)))) + + (testing "main shows hp0" + (is (= {:top-white nil + :red :on + :green :off + :yellow nil + :center-white nil + :zs7 nil + :bottom-white nil} + (-> (signal/main {:aspect :off + :system :ks}) + ks/lights))))) + (testing "proceed" (testing "distant shows ks1" (is (= {:top-white nil @@ -872,7 +935,116 @@ (-> (signal/main {:aspect :proceed :zs7? true :system :ks}) - ks/lights))))))) + ks/lights)))))) + + (testing "indicator" + (testing "stop" + (testing "distant shows ks2" + (is (= {:top-white :off + :red nil + :green :off + :yellow :on + :center-white nil + :zs7 nil + :bottom-white nil} + (-> (signal/distant {:aspect :stop + :system :ks + :indicator? true}) + ks/lights)))) + + (testing "combination shows hp0" + (is (= {:top-white :off + :red :on + :green :off + :yellow :off + :center-white nil + :zs7 nil + :bottom-white nil} + (-> (signal/combination {:distant {:aspect :stop} + :main {:aspect :stop + :indicator? true} + :system :ks}) + ks/lights))) + + (is (= {:top-white :off + :red :on + :green :off + :yellow :off + :center-white nil + :zs7 nil + :bottom-white nil} + (-> (signal/combination {:distant {:aspect :proceed} + :main {:aspect :stop + :indicator? true} + :system :ks}) + ks/lights))) + + (testing "main shows hp0" + (is (= {:top-white :off + :red :on + :green :off + :yellow nil + :center-white nil + :zs7 nil + :bottom-white nil} + (-> (signal/main {:aspect :stop + :indicator? true + :system :ks}) + ks/lights)))))) + + (testing "off" + (testing "distant shows indicator" + (is (= {:top-white :on + :red nil + :green :off + :yellow :off + :center-white nil + :zs7 nil + :bottom-white nil} + (-> (signal/distant {:aspect :off + :system :ks + :indicator? true}) + ks/lights)))) + + (testing "combination shows indicator" + (is (= {:top-white :on + :red :off + :green :off + :yellow :off + :center-white nil + :zs7 nil + :bottom-white nil} + (-> (signal/combination {:distant {:aspect :stop} + :main {:aspect :off + :indicator? true} + :system :ks}) + ks/lights))) + + (is (= {:top-white :on + :red :off + :green :off + :yellow :off + :center-white nil + :zs7 nil + :bottom-white nil} + (-> (signal/combination {:distant {:aspect :proceed} + :main {:aspect :off + :indicator? true} + :system :ks}) + ks/lights))) + + (testing "main shows indicator" + (is (= {:top-white :on + :red :off + :green :off + :yellow nil + :center-white nil + :zs7 nil + :bottom-white nil} + (-> (signal/main {:aspect :off + :indicator? true + :system :ks}) + ks/lights)))))))) (deftest speed-limit-available? (testing "without Zs3"