54 lines
1.6 KiB
Clojure
54 lines
1.6 KiB
Clojure
(ns challenge.discrete-value-range-test
|
|
(:require
|
|
[clojure.test :refer [deftest testing is]]
|
|
[challenge.discrete-value-range :as range]))
|
|
|
|
(deftype IntInclusiveDiscreteValueRange
|
|
[^int start ^int end]
|
|
range/DiscreteValueRange
|
|
(abuts [_this other]
|
|
(or (= 1 (abs (- start (.end other))))
|
|
(= 1 (abs (- end (.start other))))))
|
|
(value-before [__this]
|
|
(dec start))
|
|
(value-after [_this]
|
|
(inc end))
|
|
(start [_this]
|
|
start)
|
|
(end [_this]
|
|
end)
|
|
|
|
Object
|
|
(toString [_this]
|
|
(str start ".." end))
|
|
(equals [_this other]
|
|
(and (= start (.start other))
|
|
(= end (.end other)))))
|
|
|
|
(defn int-range-inclusive [start end]
|
|
(assert (<= start end))
|
|
(->IntInclusiveDiscreteValueRange start end))
|
|
|
|
(deftest integer-ranges-sanity-test
|
|
(testing "value equality"
|
|
(is (= (int-range-inclusive 0 1)
|
|
(int-range-inclusive 0 1))))
|
|
|
|
(testing "abuts"
|
|
(is (= true (range/abuts (int-range-inclusive 0 1)
|
|
(int-range-inclusive 2 3))))
|
|
(is (= true (range/abuts (int-range-inclusive 1 1)
|
|
(int-range-inclusive 2 3))))
|
|
(is (= true (range/abuts (int-range-inclusive 4 7)
|
|
(int-range-inclusive 2 3))))
|
|
(is (= false (range/abuts (int-range-inclusive 4 7)
|
|
(int-range-inclusive 1 2)))))
|
|
(testing "value-before"
|
|
(is (= 0 (range/value-before (int-range-inclusive 1 8)))))
|
|
(testing "value-after"
|
|
(is (= 9 (range/value-after (int-range-inclusive 1 8)))))
|
|
(testing "start"
|
|
(is (= 1 (range/start (int-range-inclusive 1 8)))))
|
|
(testing "end"
|
|
(is (= 8 (range/end (int-range-inclusive 1 8))))))
|