Back
inc (clj)
(source)function
(inc t)
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 coincidence-test
(let [int-beginning (t/instant "2020-02-02T00:00:00Z")
int-end (t/>> int-beginning (t/of-hours 2))
interval {:tick/beginning int-beginning
:tick/end int-end}]
(is (t/coincident? interval (t/>> int-beginning (t/of-hours 1))))
(is (not (t/coincident? interval (t/<< int-beginning (t/of-hours 1)))))
(is (t/coincident? interval int-beginning))
(is (t/coincident? interval int-end))
(is (t/coincident? interval interval))
(is (not (t/coincident? interval (-> interval
(update :tick/end #(t/>> % (t/of-nanos 1))))))))
(testing "non-interval coincidence"
(doseq [[start-f new-amount] [[t/date t/of-days] [t/date-time t/of-hours]]]
(let [start (start-f)
end (t/>> start (new-amount 2))]
(is (t/coincident? start end (t/>> start (new-amount 1))))
(is (not (t/coincident? start end (t/<< start (new-amount 1)))))
(is (t/coincident? start end start))
(is (t/coincident? start end end))))))
(is (= (t/of-hours 24) (t/duration (t/date))))
(is (= (t/of-days 1) (t/duration {:tick/beginning (t/date)
:tick/end (t/inc (t/date))}))))
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 basic-relations-test
(is (= (count ti/basic-relations) 13))
(is (distinct? ti/basic-relations)))
;; Distinct: because no pair of definite intervals can be related by more than one of the relationships.
;; From [ALSPAUGH-2009]
(deftest distinct-test
(is
(= [1] ; Each interval should have just one relation that is true
(distinct
(let [f (apply juxt ti/basic-relations)]
(for [x1 instants
x2 instants
y1 instants
y2 instants
:when (t/< x1 x2)
:when (t/< y1 y2)
:let [x (ti/new-interval x1 x2)
y (ti/new-interval y1 y2)]]
;; For each combination, count how many relations are true
;; (should be just one each time)
(count (filter true? (f x y)))))))))
;; Exhaustive: because any pair of definite intervals are described by one of the relations.
(deftest exhaustive-test []
(is
(= 13 ; Thirteen basic relations
(count
(distinct
(for [x1 instants
x2 instants
y1 instants
y2 instants
:when (t/< x1 x2)
:when (t/< y1 y2)
:let [x (ti/new-interval x1 x2)
y (ti/new-interval y1 y2)]]
;; For each combination, count how many relations are true
;; (should be just one each time)
(ti/relation x y)))))))
;; TODO: more Interval testing
(deftest successive-intervals-meet
(doseq [x [(t/date) (t/year) (t/year-month)]]
(is (ti/meets? (t/end x) (t/beginning (t/inc x))))))
;; Can we disturb?
(deftest cannot-disturb-test
(extend-protocol p/ITimeSpan
LocalTime
(beginning [i] i)
(end [i] i))
(let
[disturb-interval [(ti/new-interval (t/time "07:00") (t/time "22:00"))]
no-disturb-interval (ti/complement disturb-interval)
can-disturb? (fn [t] (not (some #(t/coincident? % t) no-disturb-interval)))
]
(is (not (can-disturb? (t/time "03:00"))))
(is (not (can-disturb? (t/time "07:00"))))
(is (can-disturb? (t/time "07:01")))
(is (can-disturb? (t/time "12:00")))
(is (can-disturb? (t/time "21:59")))
(is (not (can-disturb? (t/time "22:00"))))
(is (not (can-disturb? (t/time "00:00"))))))