Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
96 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,16 @@ | |||
(ns inflections.number) | |||
|
|||
(defn parse-float | |||
"Parse `s` as a float number." | |||
[s] (try (Float/parseFloat (str s)) | |||
(catch NumberFormatException _ nil))) | |||
|
|||
(defn parse-integer | |||
"Parse `s` as a integer." | |||
[s] (try (Integer/parseInt (str s)) | |||
(catch NumberFormatException _ nil))) | |||
|
|||
(defn parse-long | |||
"Parse `s` as a long." | |||
[s] (try (Long/parseLong (str s)) | |||
(catch NumberFormatException _ nil))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,11 @@ | |||
(ns inflections.number) | |||
|
|||
(defn parse-float | |||
"Parse `s` as a floating-point number." | |||
[s] (let [n (js/parseFloat (str s))] | |||
(if-not (js/isNaN n) n))) | |||
|
|||
(defn parse-integer | |||
"Parse `s` as a integer." | |||
[s] (let [n (js/parseInt (str s))] | |||
(if-not (js/isNaN n) n))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,5 @@ | |||
#!/usr/bin/env bash | |||
if [ ! -f target/inflections-test.js ]; then | |||
lein cljsbuild once | |||
fi | |||
echo "inflections.test.run()" | d8 --shell target/inflections-test.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,24 @@ | |||
(ns inflections.test.number | |||
(:use clojure.test | |||
inflections.number)) | |||
|
|||
(deftest test-parse-float | |||
(is (nil? (parse-float nil))) | |||
(is (nil? (parse-float ""))) | |||
(is (= 1.0 (parse-float "1"))) | |||
(is (= 10.0 (parse-float "10.0"))) | |||
(is (= -10.0 (parse-float "-10.0")))) | |||
|
|||
(deftest test-parse-integer | |||
(is (nil? (parse-integer nil))) | |||
(is (nil? (parse-integer ""))) | |||
(is (= 1 (parse-integer "1"))) | |||
(is (= 10 (parse-integer "10"))) | |||
(is (= -10 (parse-integer "-10")))) | |||
|
|||
(deftest test-parse-long | |||
(is (nil? (parse-long nil))) | |||
(is (nil? (parse-long ""))) | |||
(is (= 1 (parse-long "1"))) | |||
(is (= 10 (parse-long "10"))) | |||
(is (= -10 (parse-long "-10")))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,8 @@ | |||
(ns inflections.test | |||
(:require [inflections.test.core :as core] | |||
[inflections.test.number :as number])) | |||
|
|||
(defn ^:export run [] | |||
(core/test) | |||
(number/test) | |||
"All tests passed.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,20 @@ | |||
(ns inflections.test.number | |||
(:require [inflections.number :refer [parse-float parse-integer]])) | |||
|
|||
(defn test-parse-float [] | |||
(assert (nil? (parse-float nil))) | |||
(assert (nil? (parse-float ""))) | |||
(assert (= 1.0 (parse-float "1"))) | |||
(assert (= 10.0 (parse-float "10.0"))) | |||
(assert (= -10.0 (parse-float "-10.0")))) | |||
|
|||
(defn test-parse-integer [] | |||
(assert (nil? (parse-integer nil))) | |||
(assert (nil? (parse-integer ""))) | |||
(assert (= 1 (parse-integer "1"))) | |||
(assert (= 10 (parse-integer "10"))) | |||
(assert (= -10 (parse-integer "-10")))) | |||
|
|||
(defn test [] | |||
(test-parse-float) | |||
(test-parse-integer)) |