move form deftype to defrecord for easier set comparison
deftype gives different object instances which causes comparisons of sets with different instances to fail, as it check the instance equality instead of value equality, which can be provided by using defrecord instead of deftype
This commit is contained in:
@@ -3,8 +3,8 @@
|
||||
[clojure.test :refer [deftest testing is]]
|
||||
[challenge.discrete-value-range :as range]))
|
||||
|
||||
(deftype IntInclusiveDiscreteValueRange
|
||||
[^int start ^int end]
|
||||
(defrecord IntInclusiveDiscreteValueRange
|
||||
[^int start ^int end]
|
||||
range/DiscreteValueRange
|
||||
(abuts [_this other]
|
||||
(or (= 1 (abs (- start (.end other))))
|
||||
@@ -29,13 +29,10 @@
|
||||
|
||||
Object
|
||||
(toString [_this]
|
||||
(str start ".." end))
|
||||
(equals [_this other]
|
||||
(and (= start (.start other))
|
||||
(= end (.end other)))))
|
||||
(str start ".." end)))
|
||||
|
||||
(defn int-range-inclusive [start end]
|
||||
(assert (<= start end))
|
||||
(assert (<= start end) (str "start : " start "; end: " end))
|
||||
(->IntInclusiveDiscreteValueRange start end))
|
||||
|
||||
(defmethod range/->discrete-value-range :int-range-inclusive [_ start end]
|
||||
|
||||
Reference in New Issue
Block a user