Add unit tests for lib.functions.take

This commit is contained in:
2025-02-21 13:59:13 +00:00
parent 4b4421c101
commit e9dcba06bb
2 changed files with 10 additions and 1 deletions

View File

@@ -27,7 +27,7 @@ each member is STEP distance apart."
(loop :for i :from start :to (1- end) :by step
:collect i)))
(fn take (n lst) (-> (fixnum list) list)
(fn take (n lst) (-> (fixnum sequence) sequence)
"Return the first N elements of LST."
(subseq lst 0 n))

View File

@@ -39,3 +39,12 @@
(true (null (range 1 1)))
(is equal '(1 2 3 4) (range 1 5))
(is equal '(-3 -2 -1 0) (range -3 1)))
(define-test (function-test take)
:compile-at :execute
(fail (take nil nil))
(fail (take 100 nil))
(fail (take nil 100))
(true (->> (list 1 2 3 4) (take 0) null))
(is equal "H" (take 1 "Hello"))
(is equal '(1 2) (take 2 '(1 2 3 4 5))))