Skip to content

Commit

Permalink
[clean]テストコード追加
Browse files Browse the repository at this point in the history
  • Loading branch information
jiro4989 committed Nov 17, 2018
1 parent 5b30bcb commit 8832f98
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion project.clj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(defproject meme "1.0.1-SNAPSHOT"
(defproject meme "1.0.2-SNAPSHOT"
:description "meme is naming tool like linux commands."
:url "https://github.com/jiro4989/meme"
:plugins [[lein-kibit "0.1.6"]]
Expand Down
15 changes: 10 additions & 5 deletions src/meme/core.clj
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@
none (format "%s" n)
:else (format (str "%" padding-size "d" delimiter "%s") weight n))))

(defn weighting-words
"コマンド名候補リストに重みを付けてマップとして返す"
[round-words common-words]
(->> round-words
(filter #(< 1 (count %)))
(map #(weight/weight % common-words round-words))
(sort-by :name)
(sort-by :weight)))

(def cli-options
; 重み数値の空白詰め桁数
[["-p" "--padding-size int" "padding size"
Expand Down Expand Up @@ -58,9 +67,5 @@
:else (let [words (str/split (first arguments) #"\s")
common-words (read-words "resources/word.txt")
round-words (word/round-robin-words words (:round-prefix-chars-size options))]
(doseq [m (->> round-words
(filter #(< 1 (count %)))
(map #(weight/weight % common-words round-words))
(sort-by :name)
(sort-by :weight))]
(doseq [m (weighting-words round-words common-words)]
(println (format-line m options)))))))
14 changes: 14 additions & 0 deletions test/meme/core_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,17 @@
(is (= " 1,cat" (format-line m {:none false :padding-size 3 :delimiter ","}))))
))

(deftest test-weighting-words
(testing "weighting-wordsは"
(testing "重みを付けて返す"
(is (= [{:weight 7 :name "grep"}] (weighting-words ["grep"] []))))
(testing "常用英単語に同名のものがあれば重みがつく"
(is (= [{:weight 7 :name "ab"} {:weight 12 :name "grep"}] (weighting-words ["grep" "ab"] ["grep"]))))
))

(deftest test-main
(testing "mainは"
(testing "エラーが発生しない"
(is (nil? (-main "global regular expression print"))))
))

0 comments on commit 8832f98

Please sign in to comment.