Skip to content

Commit

Permalink
Merge pull request #64 from ayamada/feature/test-check-dict-file
Browse files Browse the repository at this point in the history
Issue #61 (5) Examine result file of `create-dict` in test
  • Loading branch information
totakke committed Apr 25, 2017
2 parents 912842c + 507f865 commit f10a9cf
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions test-resources/test-fa.dict
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@HD VN:1.0 SO:unsorted
@SQ SN:ref LN:45 M5:7a66cae8ab14aef8d635bc80649e730b UR:file:///Users/chrovis/cljam/test-resources/test.fa
@SQ SN:ref2 LN:40 M5:1636753510ec27476fdd109a6684680e UR:file:///Users/chrovis/cljam/test-resources/test.fa
1 change: 1 addition & 0 deletions test/cljam/t_common.clj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@

(def test-fa-file "test-resources/test.fa")
(def test-fa-bz2-file "test-resources/test.fa.bz2")
(def test-fa-dict-file "test-resources/test-fa.dict")
(def medium-fa-file "test-resources/medium.fa")
(def medium-fa-gz-file "test-resources/medium.fa.gz")

Expand Down
21 changes: 19 additions & 2 deletions test/cljam/t_dict.clj
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
(ns cljam.t-dict
"Tests for cljam.dict."
(:require [clojure.test :refer :all]
[clojure.string :as string]
[me.raynes.fs :as fs]
[clojure.java.io :as io]
[cljam.t-common :refer :all]
[cljam.dict :as dict]))

(defn same-dict-file? [f1 f2]
(with-open [r1 (io/reader f1)
r2 (io/reader f2)]
(let [dict1 (line-seq r1)
dict2 (line-seq r2)
;; NB: `UR` is calculated by local file path, ignore it,
;; and ignore `VN` too.
omit-some (fn [line]
(string/join "\t"
(remove #(re-find #"^(UR|VN):" %)
(string/split line #"\t"))))]
(when (= (count dict1) (count dict2))
(->> (map #(= (omit-some %1) (omit-some %2)) dict1 dict2)
(every? true?))))))

;; Resources
;; ---------

Expand All @@ -20,5 +37,5 @@
:after (clean-cache!)}
;; Create dictionary without errors
(is (not-throw? (dict/create-dict temp-fa-file out-dict-file)))
;; Check the file existence
(is (fs/exists? out-dict-file))))
;; Check the file contents
(is (same-dict-file? out-dict-file test-fa-dict-file))))

0 comments on commit f10a9cf

Please sign in to comment.