Back
max (clj)
(source)function
(max arg & args)
Find the latest of the given arguments. Callers should ensure that no
argument is nil.
Examples
tick
(ns tick.api-test
(:require
[clojure.test
:refer [deftest is testing run-tests]
:refer-macros [deftest is testing run-tests]]
[tick.core :as t]
[tick.locale-en-us]
[tick.protocols :as p]
[cljc.java-time.clock]
[cljc.java-time.instant]
[cljc.java-time.day-of-week]
[cljc.java-time.month]
[cljc.java-time.year]
#?@(:cljs [[java.time :refer [Instant]]]))
#?(:clj
(:import [java.time Instant])))
(deftest comparison-test
(let [point (t/truncate (t/instant) :millis)
later (t/>> point (t/new-duration 1 :millis))]
(testing "shifting inst"
(let [i (t/inst)]
(is (= i (-> i
(t/>> (t/new-duration 10 :seconds))
(t/<< (t/new-duration 10 :seconds)))))))
(testing "max-min"
(is (= later (t/max point later point later)))
(is (= point (t/min point later point later))))
(testing "max-min key"
(is (= {:foo later} (t/max-key :foo {:foo point} {:foo later} {:foo point} {:foo later})))
(is (= {:foo point} (t/min-key :foo {:foo point} {:foo later} {:foo point} {:foo later}))))
(testing "comparables not="
(doseq [point (point-in-time-comparable point)]
(testing "comparables ="
(is (apply t/= point (point-in-time-comparable point)))
(is (apply t/>= point (point-in-time-comparable point))))
(is (apply t/<= point (point-in-time-comparable later))))
(doseq [later (point-in-time-comparable later)]
(is (apply t/>= later (point-in-time-comparable point))))
tick
(ns tick.alpha.interval-test
(:require
[clojure.spec.alpha :as s]
[tick.core :as t]
[tick.protocols :as p]
[clojure.test
:refer [deftest is testing run-tests]
:refer-macros [deftest is testing run-tests]]
[tick.alpha.interval :as ti]
#?@(:cljs [[java.time :refer [Instant LocalDateTime LocalTime]]]))
#?(:clj
(:import [java.time LocalDateTime Instant LocalTime])))
(deftest complement-test
(testing "complement through max of type"
(is (= [(ti/new-interval (t/time "01:00") (t/max-of-type (t/time "00:00")))]
(ti/complement [(ti/new-interval (t/time "00:00") (t/time "01:00"))]))))
(testing "complement ordered disjoint intervals"
(is (= [(ti/new-interval (t/time "00:00") (t/time "01:00"))
(ti/new-interval (t/time "02:00") (t/time "03:00"))
(ti/new-interval (t/time "04:00") (t/max-of-type (t/time "00:00")))]
(ti/complement [(ti/new-interval (t/time "01:00") (t/time "02:00"))
(ti/new-interval (t/time "03:00") (t/time "04:00"))]))))
(testing "complement meeting intervals"
(is (= [(ti/new-interval (t/time "00:00") (t/time "01:00"))
(ti/new-interval (t/time "03:00") (t/max-of-type (t/time "00:00")))]
(ti/complement [(ti/new-interval (t/time "01:00") (t/time "02:00"))
(ti/new-interval (t/time "02:00") (t/time "03:00"))]))))
(testing "complement empty interval round trip"
(is (= [] (ti/complement (ti/complement []))))))