Add unit tests for lib.functions.remove-at-indices
This commit is contained in:
@@ -55,8 +55,8 @@ where key x in A has associations {y in LST : INDICATOR(y) = x}."
|
|||||||
"Given string INP, attempt to parse an integer. Return NIL otherwise."
|
"Given string INP, attempt to parse an integer. Return NIL otherwise."
|
||||||
(parse-integer inp :junk-allowed t))
|
(parse-integer inp :junk-allowed t))
|
||||||
|
|
||||||
(fn remove-at-indices (indices lst) (-> (list list) list)
|
(fn remove-at-indices (indices lst) (-> (list sequence) list)
|
||||||
(loop :for i :from 0 :to (1- (length lst))
|
(loop :for i :from 0 :to (1- (length lst))
|
||||||
:for item :in lst
|
:for item :in (coerce lst 'list)
|
||||||
:if (not (member i indices))
|
:if (not (member i indices))
|
||||||
:collect item))
|
:collect item))
|
||||||
|
|||||||
@@ -93,3 +93,22 @@
|
|||||||
(is equal 3 (->> (assoc #\t res) cdr length))
|
(is equal 3 (->> (assoc #\t res) cdr length))
|
||||||
(is equal 2 (->> (assoc #\space res) cdr length))
|
(is equal 2 (->> (assoc #\space res) cdr length))
|
||||||
(is equal 2 (->> (assoc #\s res) cdr length))))
|
(is equal 2 (->> (assoc #\s res) cdr length))))
|
||||||
|
|
||||||
|
(define-test (function-test remove-at-indices)
|
||||||
|
:depends-on (range)
|
||||||
|
:compile-at :execute
|
||||||
|
(fail (remove-at-indices "a string" "another string"))
|
||||||
|
(true (null (remove-at-indices nil nil)))
|
||||||
|
(is equal '(1 2 3) (remove-at-indices nil '(1 2 3)))
|
||||||
|
(is equal '(2) (remove-at-indices '(0 2) '(1 2 3)))
|
||||||
|
(let* ((inp (range 100 200))
|
||||||
|
(t1 (remove-at-indices (range 0 100 2) inp))
|
||||||
|
(t2 (remove-at-indices (range 1 100 2) inp)))
|
||||||
|
(is equal 50 (length t1))
|
||||||
|
(is equal 50 (length t2))
|
||||||
|
(true (every (lambda (n) (not (member n t2))) t1))
|
||||||
|
(true (every (lambda (n) (not (member n t1))) t2)))
|
||||||
|
(let* ((indices (list 0 5 6 7 8 9 10))
|
||||||
|
(str-lst (remove-at-indices indices "Hello World"))
|
||||||
|
(ret (coerce str-lst 'string)))
|
||||||
|
(is string= "ello" ret)))
|
||||||
|
|||||||
Reference in New Issue
Block a user