clj-ml/test/clj_ml/io_test.clj

25 lines
1.1 KiB
Clojure
Raw Permalink Normal View History

2013-03-22 14:57:49 +00:00
(ns clj-ml.io-test
(:require [clojure.string :as str])
2013-03-22 14:57:49 +00:00
(:use [clj-ml io data] :reload-all)
(:use clojure.test midje.sweet))
2013-07-11 11:40:32 +00:00
(deftest test-load-instances-iris-arff-url
(let [ds (do (println "Loading instances from http://clj-ml.artifice.cc/iris.arff ...")
(load-instances :arff "http://clj-ml.artifice.cc/iris.arff"))]
2013-03-22 14:57:49 +00:00
(is (= 150 (dataset-count ds)))))
2013-07-11 11:40:32 +00:00
(deftest test-load-instances-iris-csv-url
(let [ds (do (println "Loading instances from http://clj-ml.artifice.cc/iris.csv ...")
(load-instances :csv "http://clj-ml.artifice.cc/iris.csv"))]
2013-07-11 11:40:32 +00:00
(is (= 150 (dataset-count ds)))))
(deftest test-save-instances
(let [ds (make-dataset "test" [:a :b {:c [:m :n]}] [[1 2 :m] [4 5 :m]])]
(is (= (do (save-instances :csv "test.csv" ds)
(str/replace (slurp "test.csv") #"\r\n" "\n"))
"a,b,c\n1,2,m\n4,5,m\n"))
2013-07-11 11:40:32 +00:00
(is (= (do (save-instances :arff "test.arff" ds)
(str/replace (slurp "test.arff") #"\r\n" "\n"))
"@relation test\n\n@attribute a numeric\n@attribute b numeric\n@attribute c {m,n}\n\n@data\n1,2,m\n4,5,m\n"))))
2013-07-11 11:40:32 +00:00