Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #61 (5) Examine result file of create-dict in test #64

Merged
merged 2 commits into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -116,6 +116,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))))