Add tests for vector.el
Adds a few tests for vector{set,set!} functions.
This commit is contained in:
parent
a11af57666
commit
0c59df8327
1 changed files with 22 additions and 0 deletions
|
@ -21,6 +21,13 @@
|
||||||
|
|
||||||
;; TODO: Consider supporting an alias named tuple for vector.
|
;; TODO: Consider supporting an alias named tuple for vector.
|
||||||
|
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
;; Library
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
|
||||||
|
(defconst vector/enable-tests? t
|
||||||
|
"When t, run the tests defined herein.")
|
||||||
|
|
||||||
;; TODO: Consider labelling variadic functions like `vector/concat*'
|
;; TODO: Consider labelling variadic functions like `vector/concat*'
|
||||||
;; vs. `vector/concat'.
|
;; vs. `vector/concat'.
|
||||||
(defun vector/concat (&rest args)
|
(defun vector/concat (&rest args)
|
||||||
|
@ -50,6 +57,21 @@ Returns a copy of `XS' with the updates."
|
||||||
(aset copy i v)
|
(aset copy i v)
|
||||||
copy))
|
copy))
|
||||||
|
|
||||||
|
(defun vector/set! (i v xs)
|
||||||
|
"Set index `I' to value `V' in `XS'.
|
||||||
|
This function mutates XS."
|
||||||
|
(aset xs i v))
|
||||||
|
|
||||||
|
(when vector/enable-tests?
|
||||||
|
(let ((xs [1 2 3])
|
||||||
|
(ys [1 2 3]))
|
||||||
|
(prelude/assert (= 1 (vector/get 0 ys)))
|
||||||
|
(vector/set 0 4 ys)
|
||||||
|
(prelude/assert (= 1 (vector/get 0 ys)))
|
||||||
|
(prelude/assert (= 1 (vector/get 0 xs)))
|
||||||
|
(vector/set! 0 4 xs)
|
||||||
|
(prelude/assert (= 4 (vector/get 0 xs)))))
|
||||||
|
|
||||||
;; TODO: Decide between "remove" and "delete" as the appropriate verbs.
|
;; TODO: Decide between "remove" and "delete" as the appropriate verbs.
|
||||||
;; TODO: Implement this.
|
;; TODO: Implement this.
|
||||||
;; (defun vector/delete (i xs)
|
;; (defun vector/delete (i xs)
|
||||||
|
|
Loading…
Reference in a new issue