11(ns witch-clock.core-test
22 (:require
33 [clojure.string :as string]
4- [clojure.test :refer [deftest is testing]]
4+ [clojure.test :refer [is testing deftest ]]
55 [witch-clock.calendar :as calendar]))
66
77(deftest witch-clock-sanity-test
8- (testing " Works for one hundred years."
9- (doseq [[latitude longitude]
10- [[45.5761 -122.6881 ] ; north america
11- [25.2744 133.7751 ] ; australia
12- ]]
13- (doseq [i (range 100 )
14- :let [greg-year (+ calendar/FIRST-CYCLE-YEAR i -50 )
15- {:keys [nth-cycle months seasons conclusion cycle-end days]}
16- (calendar/from-gregorian-year greg-year latitude longitude)]]
17- (is (number? nth-cycle))
18- (doseq [month calendar/MONTHS
19- :when (get months month)
20- :let [i (inc (.indexOf calendar/MONTHS month))
21- next-month (nth calendar/MONTHS i nil )
22- [new-moon waxing-moon full-moon waning-moon] (map :date (get months month))]]
23- (is (calendar/is-before new-moon waxing-moon full-moon waning-moon))
24- (if (get months next-month)
25- (let [next-new-moon (-> months next-month first :date )]
26- (is (calendar/is-before waning-moon next-new-moon)))
27- (is (calendar/is-before waning-moon cycle-end))))
28- (doseq [season calendar/SEASONS
29- :let [next-season (get calendar/NEXT-SEASON season)]]
30- (is (calendar/is-before (get seasons season) (get seasons next-season))))
31- (is (calendar/is-before conclusion cycle-end))
32- (doseq [[day next-day] (zipmap (drop-last 1 days) (drop 1 days))]
33- (is (calendar/is-before (:dawn day) (:dusk day) (:dawn next-day) (:dusk next-day))
34- (->> [(:dawn day) (:dusk day) (:dawn next-day) (:dusk next-day)]
35- (map #(.toLocaleString %))
36- (string/join " , " ))))))))
8+ (doseq [greg-year (map #(+ calendar/FIRST-CYCLE-YEAR % -5 ) (range 10 ))
9+ [latitude longitude]
10+ [[45.5761 -122.6881 ] ; north america
11+ [25.2744 133.7751 ] ; australia
12+ ]]
13+ (let [{:keys [nth-cycle months seasons conclusion cycle-end days]
14+ :as witchy-year}
15+ (calendar/from-gregorian-year greg-year latitude longitude)]
16+ (println (str " Testing: " (string/join " ; " [greg-year latitude longitude])))
17+ (is (number? nth-cycle))
18+ (doseq [month calendar/MONTHS
19+ :when (get months month)
20+ :let [i (inc (.indexOf calendar/MONTHS month))
21+ next-month (nth calendar/MONTHS i nil )
22+ [new-moon waxing-moon full-moon waning-moon] (map :date (get months month))]]
23+ (is (calendar/is-before new-moon waxing-moon full-moon waning-moon))
24+ (if (get months next-month)
25+ (let [next-new-moon (-> months next-month first :date )]
26+ (is (calendar/is-before waning-moon next-new-moon)))
27+ (is (calendar/is-before waning-moon cycle-end))))
28+ (doseq [season calendar/SEASONS
29+ :let [next-season (get calendar/NEXT-SEASON season)]]
30+ (is (calendar/is-before (get seasons season) (get seasons next-season))))
31+ (is (calendar/is-before conclusion cycle-end))
32+ (doseq [[day next-day] (zipmap (drop-last 1 days) (drop 1 days))
33+ :let [date (calendar/get-date witchy-year (:dawn day))
34+ next-date (calendar/get-date witchy-year (:dawn next-day))]]
35+ (is (calendar/is-before (:dawn day) (:dusk day) (:dawn next-day) (:dusk next-day))
36+ (->> [(:dawn day) (:dusk day) (:dawn next-day) (:dusk next-day)]
37+ (map #(.toLocaleString %))
38+ (string/join " , " )))
39+ (is (apply calendar/is-or-before (concat (:day date) (:day next-date))))
40+ (let [[month _month-dt month-i :as today-month] (:month date)
41+ [tmrw-month _tmrw-month-dt tmrw-month-i :as tmrw-month*] (:month next-date)]
42+ (if (= month tmrw-month)
43+ (is (= (inc month-i) tmrw-month-i)
44+ (str [today-month tmrw-month*]))
45+ (is (= 1 tmrw-month-i)
46+ (str tmrw-month*))))
47+ (let [[phase _phase-dt phase-i :as today-phase] (:phase date)
48+ [tmrw-phase _tmrw-phase-dt tmrw-phase-i :as tmrw-phase*] (:phase next-date)]
49+ (if (= phase tmrw-phase)
50+ (is (= (inc phase-i) tmrw-phase-i)
51+ (str [today-phase tmrw-phase*]))
52+ (is (= 1 tmrw-phase-i)
53+ (str tmrw-phase*))))
54+ (let [[season _season-dt season-i :as today-season] (:season date)
55+ [tmrw-season _tmrw-season-dt tmrw-season-i :as tmrw-season*] (:season next-date)]
56+ (if (= season tmrw-season)
57+ (is (= (inc season-i) tmrw-season-i)
58+ (str [today-season tmrw-season*]))
59+ (is (= 1 tmrw-season-i)
60+ (str tmrw-season*))))))))
0 commit comments