diff --git a/src/sparse_array/core.clj b/src/sparse_array/core.clj index 6906a36..be8a3f0 100644 --- a/src/sparse_array/core.clj +++ b/src/sparse_array/core.clj @@ -32,17 +32,18 @@ ([x & axes] (and (map? x) + (number? (:dimensions x)) (pos? (:dimensions x)) (keyword? (:coord x)) (= (:coord x) (first axes)) (if - (rest axes) + (empty? (rest axes)) + (= (:content x) :data) (and (= (:content x) (rest axes)) (every? sparse-array? - (map #(x %) (filter integer? (keys x))))) - (= (:content x) :data))))) + (map #(x %) (filter integer? (keys x))))))))) (defn put "Return a sparse array like this `array` but with this `value` at these diff --git a/test/sparse_array/core_test.clj b/test/sparse_array/core_test.clj index 216681a..b7d5707 100644 --- a/test/sparse_array/core_test.clj +++ b/test/sparse_array/core_test.clj @@ -16,8 +16,38 @@ :coord :y, :content :data, 3 "goodbye"}})) - (is-not (sparse-array? [])) - (is-not (sparse-array? "hello")) + (is (= (sparse-array? []) false)) + (is (= (sparse-array? "hello") false)) + (is (= + (sparse-array? + (dissoc (make-sparse-array :x :y :z) :dimensions)) + false) + "All mandatory keywords must be present: dimensions") + (is (= + (sparse-array? + (dissoc (make-sparse-array :x :y :z) :coord)) + false) + "All mandatory keywords must be present: coord") + (is (= + (sparse-array? + (dissoc (make-sparse-array :x :y :z) :content)) + false) + "All mandatory keywords must be present: content") + (is (= + (sparse-array? {:dimensions 2, + :coord :x, + :content '(:y), + 3 {:dimensions 1, + :coord :y, + :content :data, + 4 "hello"}, + 4 {:dimensions 1, + :coord :y, + :content :data, + 3 "goodbye"} + 5 :foo}) + false) + "Can't have data in a non-data layer") )) (deftest put-and-get