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:
2026-01-11 16:17:50 -06:00
parent d0c78810f0
commit 211efb5d16

View File

@@ -3,7 +3,7 @@
[clojure.test :refer [deftest testing is]] [clojure.test :refer [deftest testing is]]
[challenge.discrete-value-range :as range])) [challenge.discrete-value-range :as range]))
(deftype IntInclusiveDiscreteValueRange (defrecord IntInclusiveDiscreteValueRange
[^int start ^int end] [^int start ^int end]
range/DiscreteValueRange range/DiscreteValueRange
(abuts [_this other] (abuts [_this other]
@@ -29,13 +29,10 @@
Object Object
(toString [_this] (toString [_this]
(str start ".." end)) (str start ".." end)))
(equals [_this other]
(and (= start (.start other))
(= end (.end other)))))
(defn int-range-inclusive [start end] (defn int-range-inclusive [start end]
(assert (<= start end)) (assert (<= start end) (str "start : " start "; end: " end))
(->IntInclusiveDiscreteValueRange start end)) (->IntInclusiveDiscreteValueRange start end))
(defmethod range/->discrete-value-range :int-range-inclusive [_ start end] (defmethod range/->discrete-value-range :int-range-inclusive [_ start end]