Permalink
Browse files

Merge pull request #82 from davidjameshumphreys/numeric-parse

Numeric parse
  • Loading branch information...
2 parents d1bc05a + 3f10c84 commit 1a10635a70911bc8dc0fd072181398b6fbe57e5b @otfrom otfrom committed Jul 1, 2012
Showing with 9 additions and 2 deletions.
  1. +1 −1 modules/incanter-io/src/incanter/io.clj
  2. +8 −1 modules/incanter-io/test/incanter/io_tests.clj
View
2 modules/incanter-io/src/incanter/io.clj
@@ -30,7 +30,7 @@ incanter.io
(defn- parse-string [value]
(if (re-matches #"\d+" value)
- (try (Integer/parseInt value)
+ (try (Long/parseLong value)
(catch NumberFormatException _ value))
(try (Double/parseDouble value)
(catch NumberFormatException _ value))))
View
9 modules/incanter-io/test/incanter/io_tests.clj
@@ -86,4 +86,11 @@
(is (= [:speed :dist] (:column-names cars-dataset)) (str "Reading column names for " name " failed"))
(is (= 50 (count (:rows cars-dataset)))) (str "Reading rows for " name " failed"))) ;; end of read-dataset-validation tests
-
+(def parse-string (ns-resolve 'incanter.io 'parse-string))
+(deftest parse-string-validation
+
+ (testing "Parsing string values into numbers"
+ (is (= 1234 (parse-string "1234")))
+ (is (instance? java.lang.Long (parse-string "5678")))
+ (is (instance? java.lang.Long (parse-string "1330418008377")))
+ ))

0 comments on commit 1a10635

Please sign in to comment.