about summary refs log tree commit diff
path: root/configs/shared/.emacs.d/wpc
diff options
context:
space:
mode:
authorWilliam Carroll <wpcarro@gmail.com>2020-01-20T10·15+0000
committerWilliam Carroll <wpcarro@gmail.com>2020-01-22T21·13+0000
commit0c59df832714c09f9dbf881bf352507916999d2d (patch)
tree6fbcbbf2feeaa99f47b6c6217eb514fbb7bdf11f /configs/shared/.emacs.d/wpc
parenta11af5766622a6b0771ef5d521f4eac8dd7d637c (diff)
Add tests for vector.el
Adds a few tests for vector{set,set!} functions.
Diffstat (limited to 'configs/shared/.emacs.d/wpc')
-rw-r--r--configs/shared/.emacs.d/wpc/vector.el22
1 files changed, 22 insertions, 0 deletions
diff --git a/configs/shared/.emacs.d/wpc/vector.el b/configs/shared/.emacs.d/wpc/vector.el
index 4fc6ffe911d3..6d2fe20d1209 100644
--- a/configs/shared/.emacs.d/wpc/vector.el
+++ b/configs/shared/.emacs.d/wpc/vector.el
@@ -21,6 +21,13 @@
 
 ;; 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*'
 ;; vs. `vector/concat'.
 (defun vector/concat (&rest args)
@@ -50,6 +57,21 @@ Returns a copy of `XS' with the updates."
     (aset copy i v)
     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: Implement this.
 ;; (defun vector/delete (i xs)