merge dense with sparse now works

Not yet sure I'm right about the semantics of sparse-with-dense: are nils in a dense array first class values?
This commit is contained in:
Simon Brooke 2019-06-28 09:45:05 +01:00
parent 59fb5529aa
commit 1aa3173dc9
3 changed files with 93 additions and 28 deletions

View file

@ -172,20 +172,30 @@
(get (make-sparse-array :x :y :z) 3 4 5 6))))))
(deftest merge-test
(testing "merge, one dimension"
(testing "merge, sparse arrays, one dimension"
(let
[merged (merge-sparse-arrays
[merged (merge-arrays
(put (make-sparse-array :x) "hello" 3)
(put (make-sparse-array :x) "goodbye" 4))]
(is (= "hello" (get merged 3)))
(is (= "goodbye" (get merged 4)))))
(testing "merge, two dimensions"
(testing "merge, sparse arrays, two dimensions"
(let
[merged (merge-sparse-arrays
[merged (merge-arrays
(put (make-sparse-array :x :y) "hello" 3 4)
(put (make-sparse-array :x :y) "goodbye" 4 3))]
(is (= "hello" (get merged 3 4)))
(is (= "goodbye" (get merged 4 3))))))
(is (= "goodbye" (get merged 4 3)))))
(testing "merge, dense with sparse, two dimensions")
(let [dense [[[nil nil nil][nil nil nil][nil nil nil]]
[[nil nil nil][nil nil nil][nil nil nil]]
[[nil nil nil][nil nil nil][nil nil nil]]]
sparse (put (put (make-sparse-array :x :y :z) "hello" 0 0 0) "goodbye" 2 2 2)
expected [[["hello" nil nil] [nil nil nil] [nil nil nil]]
[[nil nil nil] [nil nil nil] [nil nil nil]]
[[nil nil nil] [nil nil nil] [nil nil "goodbye"]]]
actual (merge-arrays dense sparse)]
(is (= actual expected))))
(deftest dense-to-sparse-tests
(testing "dense-to-sparse, one dimension"