diff options
author | Aryadev Chavali <aryadev@aryadevchavali.com> | 2025-02-21 13:58:58 +0000 |
---|---|---|
committer | Aryadev Chavali <aryadev@aryadevchavali.com> | 2025-02-21 14:11:08 +0000 |
commit | 4b4421c101a269051e53d76313d5035d27b4b074 (patch) | |
tree | ebf09a737b9b66028c914376b6062332cee57582 | |
parent | 53174000dfaebbe4ecb5b9a89bcf16bea0fdf547 (diff) | |
download | cantedraw-4b4421c101a269051e53d76313d5035d27b4b074.tar.gz cantedraw-4b4421c101a269051e53d76313d5035d27b4b074.tar.bz2 cantedraw-4b4421c101a269051e53d76313d5035d27b4b074.zip |
Add unit tests for lib.functions.range
-rw-r--r-- | lib/functions.lisp | 2 | ||||
-rw-r--r-- | tests/functions.lisp | 9 |
2 files changed, 10 insertions, 1 deletions
diff --git a/lib/functions.lisp b/lib/functions.lisp index 2a7f4ab..40e940a 100644 --- a/lib/functions.lisp +++ b/lib/functions.lisp @@ -22,7 +22,7 @@ (fn range (start end &optional (step 1)) (-> (fixnum fixnum &optional fixnum) list) "Make a list of numbers from START to END (exclusive). If STEP is given, then each member is STEP distance apart." - (if (<= end start) + (if (< end start) (error (format nil "~a < ~a" end start)) (loop :for i :from start :to (1- end) :by step :collect i))) diff --git a/tests/functions.lisp b/tests/functions.lisp index ef6b83e..0025827 100644 --- a/tests/functions.lisp +++ b/tests/functions.lisp @@ -30,3 +30,12 @@ (is eq nil (parse-integer* "a2048abcdef")) (is eq nil (parse-integer* "garbage")) (fail (parse-integer* nil))) + +(define-test (function-test range) + :compile-at :execute + (fail (range 1 0)) + (fail (range nil nil)) + (fail (range "a" "b")) + (true (null (range 1 1))) + (is equal '(1 2 3 4) (range 1 5)) + (is equal '(-3 -2 -1 0) (range -3 1))) |