Add int-string? to check if a string is a number.
continuous-integration/drone/push Build is passing Details

dev
KKlochko 2 years ago
parent 91dc00ea0d
commit e145382570

@ -8,6 +8,12 @@
(if (re-matches #"\d+" str)
true false))
(defn int-string?
"Return true if the string is an signed integer."
[str]
(if (re-matches #"[+-]?\b\d+\b" str)
true false))
(defn parse-unsigned-int
"Return an integer if the argument is an integer."
[str-or-int]

@ -16,6 +16,18 @@
"-10" false
"abc" false)))
(deftest int-string?-test
(testing "The function return true only for an singned integer as a string."
(are [str expected]
(= expected
(int-string? str))
"9" true
"10" true
"-10" true
"asd -10 " false
" -10 " false
"abc" false)))
(deftest parse-unsigned-int-test
(testing "The function parse the integer if the string is an integer."
(are [str-or-int expected]

Loading…
Cancel
Save