 (ns cljam.io.wig-test
   (:require [clojure.test :refer :all]
             [clojure.java.io :as cio]
+            [clojure.string :as cstr]
             [cljam.test-common :refer :all]
             [cljam.io.wig :as wig]
             [cljam.util :as util])

    (.toString bao)))

(deftest reader
  (testing "read wig"
    (is (= (str->wig "variableStep chrom=chr1 span=10\n1 1\n100 2")
           [{:format :variable-step
             :chrom "chr1"
             :span 10
             :values [{:start 1 :value 1}
                      {:start 100 :value 2}]}]))
    (is (= (str->wig "fixedStep chrom=chr1 start=1 step=20 span=10\n1\n2")
           [{:format :fixed-step
             :chrom "chr1"
             :start 1
             :step 20
             :span 10
             :values [1 2]}])))

  (testing "make reader instance"
    (with-open [rdr (wig/reader test-wig-file1)]
      (is (instance? cljam.io.wig.WIGReader rdr))))

      (is (instance? cljam.io.wig.WIGWriter wtr))))

  (testing "write wig"
    (is (= (-> "variableStep chrom=chr1 span=10\n1 1\n101 2" str->wig wig->str)
           "variableStep chrom=chr1 span=10\n1 1\n101 2"))
    (is (= (-> "fixedStep chrom=chr1 start=1 step=20 span=10\n1\n2" str->wig wig->str)
           "fixedStep chrom=chr1 start=1 step=20 span=10\n1\n2")))

  (testing "write wig with default span value for variableStep"
    (is (= (-> "variableStep chrom=chr1\n1 1\n101 2" str->wig wig->str)
           "variableStep chrom=chr1\n1 1\n101 2")))

  (testing "write wig with default span and step value for fixedStep"
    (is (= (-> "fixedStep chrom=chr1 start=1\n1\n2" str->wig wig->str)
           "fixedStep chrom=chr1 start=1\n1\n2")))

  (testing "write wig with continuous same formats"
    (let [s (cstr/join \newline ["variableStep chrom=chr19 span=5"
                                 "1 1"
                                 "11 10"
                                 "variableStep chrom=chr19 span=10"
                                 "101 1"
                                 "111 10"])]
      (is (= s (-> s str->wig wig->str))))
    (let [s (cstr/join \newline ["fixedStep chrom=chr19 start=1 step=10 span=5"
                                 "1"
                                 "10"
                                 "fixedStep chrom=chr19 start=101 step=10 span=10"
                                 "1"
                                 "10"])]
      (is (= s (-> s str->wig wig->str))))))

(deftest source-type-test
  (let [temp-file (str temp-dir "test.wig")]
