Add int-string? to check if a string is a number.
continuous-integration/drone/push Build is passing
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -8,6 +8,12 @@
|
|||||||
(if (re-matches #"\d+" str)
|
(if (re-matches #"\d+" str)
|
||||||
true false))
|
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
|
(defn parse-unsigned-int
|
||||||
"Return an integer if the argument is an integer."
|
"Return an integer if the argument is an integer."
|
||||||
[str-or-int]
|
[str-or-int]
|
||||||
|
|||||||
@@ -16,6 +16,18 @@
|
|||||||
"-10" false
|
"-10" false
|
||||||
"abc" 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
|
(deftest parse-unsigned-int-test
|
||||||
(testing "The function parse the integer if the string is an integer."
|
(testing "The function parse the integer if the string is an integer."
|
||||||
(are [str-or-int expected]
|
(are [str-or-int expected]
|
||||||
|
|||||||
Reference in New Issue
Block a user