diff --git a/exercises/practice/transpose/.meta/generator.clj b/exercises/practice/transpose/.meta/generator.clj new file mode 100644 index 000000000..c6078c0fb --- /dev/null +++ b/exercises/practice/transpose/.meta/generator.clj @@ -0,0 +1,8 @@ +(ns transpose-generator) + +(defn update-test-case [test-case] + (if (= "empty string" (:description test-case)) + (-> test-case + (assoc-in [:input :lines] [""]) + (assoc :expected [""])) + test-case)) diff --git a/exercises/practice/transpose/.meta/generator.tpl b/exercises/practice/transpose/.meta/generator.tpl new file mode 100644 index 000000000..0bf5c3b7c --- /dev/null +++ b/exercises/practice/transpose/.meta/generator.tpl @@ -0,0 +1,16 @@ +(ns transpose-test + (:require [clojure.test :refer [deftest testing is]] + [clojure.string :as str] + transpose)) + +{{#test_cases.transpose}} +(deftest transpose_test_{{idx}} + (testing {{description}} + (is (= (str/join "\n" [{{#expected~}} + {{.}} + {{/expected}}]) + (transpose/transpose + (str/join "\n" [{{#input.lines~}} + {{.}} + {{/input.lines}}])))))) +{{/test_cases.transpose}} diff --git a/exercises/practice/transpose/test/transpose_test.clj b/exercises/practice/transpose/test/transpose_test.clj index c3c3cad93..7c1d523bd 100644 --- a/exercises/practice/transpose/test/transpose_test.clj +++ b/exercises/practice/transpose/test/transpose_test.clj @@ -1,184 +1,181 @@ (ns transpose-test (:require [clojure.test :refer [deftest testing is]] + [clojure.string :as str] transpose)) -(defn join-with-line-separator - [coll] - (clojure.string/join "\n" coll)) - (deftest transpose_test_1 (testing "empty string" - (is (= (join-with-line-separator [""]) + (is (= (str/join "\n" [""]) (transpose/transpose - (join-with-line-separator [""])))))) + (str/join "\n" [""])))))) (deftest transpose_test_2 (testing "two characters in a row" - (is (= (join-with-line-separator ["A" - "1"]) + (is (= (str/join "\n" ["A" + "1"]) (transpose/transpose - (join-with-line-separator ["A1"])))))) + (str/join "\n" ["A1"])))))) (deftest transpose_test_3 (testing "two characters in a column" - (is (= (join-with-line-separator ["A1"]) + (is (= (str/join "\n" ["A1"]) (transpose/transpose - (join-with-line-separator ["A" - "1"])))))) + (str/join "\n" ["A" + "1"])))))) (deftest transpose_test_4 (testing "simple" - (is (= (join-with-line-separator ["A1" - "B2" - "C3"]) + (is (= (str/join "\n" ["A1" + "B2" + "C3"]) (transpose/transpose - (join-with-line-separator ["ABC" - "123"])))))) + (str/join "\n" ["ABC" + "123"])))))) (deftest transpose_test_5 (testing "single line" - (is (= (join-with-line-separator ["S" - "i" - "n" - "g" - "l" - "e" - " " - "l" - "i" - "n" - "e" - "."]) + (is (= (str/join "\n" ["S" + "i" + "n" + "g" + "l" + "e" + " " + "l" + "i" + "n" + "e" + "."]) (transpose/transpose - (join-with-line-separator ["Single line."])))))) + (str/join "\n" ["Single line."])))))) (deftest transpose_test_6 (testing "first line longer than second line" - (is (= (join-with-line-separator ["TT" - "hh" - "ee" - " " - "ff" - "oi" - "uf" - "rt" - "th" - "h " - " l" - "li" - "in" - "ne" - "e." - "."]) + (is (= (str/join "\n" ["TT" + "hh" + "ee" + " " + "ff" + "oi" + "uf" + "rt" + "th" + "h " + " l" + "li" + "in" + "ne" + "e." + "."]) (transpose/transpose - (join-with-line-separator ["The fourth line." - "The fifth line."])))))) + (str/join "\n" ["The fourth line." + "The fifth line."])))))) (deftest transpose_test_7 (testing "second line longer than first line" - (is (= (join-with-line-separator ["TT" - "hh" - "ee" - " " - "fs" - "ie" - "rc" - "so" - "tn" - " d" - "l " - "il" - "ni" - "en" - ".e" - " ."]) + (is (= (str/join "\n" ["TT" + "hh" + "ee" + " " + "fs" + "ie" + "rc" + "so" + "tn" + " d" + "l " + "il" + "ni" + "en" + ".e" + " ."]) (transpose/transpose - (join-with-line-separator ["The first line.", - "The second line."])))))) + (str/join "\n" ["The first line." + "The second line."])))))) (deftest transpose_test_8 (testing "mixed line length" - (is (= (join-with-line-separator ["TAAA" - "h " - "elll" - " ooi" - "lnnn" - "ogge" - "n e." - "glr" - "ei " - "snl" - "tei" - " .n" - "l e" - "i ." - "n" - "e" - "."]) + (is (= (str/join "\n" ["TAAA" + "h " + "elll" + " ooi" + "lnnn" + "ogge" + "n e." + "glr" + "ei " + "snl" + "tei" + " .n" + "l e" + "i ." + "n" + "e" + "."]) (transpose/transpose - (join-with-line-separator ["The longest line." - "A long line." - "A longer line." - "A line."])))))) + (str/join "\n" ["The longest line." + "A long line." + "A longer line." + "A line."])))))) (deftest transpose_test_9 (testing "square" - (is (= (join-with-line-separator ["HEART" - "EMBER" - "ABUSE" - "RESIN" - "TREND"]) + (is (= (str/join "\n" ["HEART" + "EMBER" + "ABUSE" + "RESIN" + "TREND"]) (transpose/transpose - (join-with-line-separator ["HEART" - "EMBER" - "ABUSE" - "RESIN" - "TREND"])))))) + (str/join "\n" ["HEART" + "EMBER" + "ABUSE" + "RESIN" + "TREND"])))))) (deftest transpose_test_10 (testing "rectangle" - (is (= (join-with-line-separator ["FOBS" - "RULE" - "ATOP" - "CLOT" - "TIME" - "UNIT" - "RENT" - "EDGE"]) + (is (= (str/join "\n" ["FOBS" + "RULE" + "ATOP" + "CLOT" + "TIME" + "UNIT" + "RENT" + "EDGE"]) (transpose/transpose - (join-with-line-separator ["FRACTURE" - "OUTLINED" - "BLOOMING" - "SEPTETTE"])))))) + (str/join "\n" ["FRACTURE" + "OUTLINED" + "BLOOMING" + "SEPTETTE"])))))) (deftest transpose_test_11 (testing "triangle" - (is (= (join-with-line-separator ["TEASER" - " EASER" - " ASER" - " SER" - " ER" - " R"]) + (is (= (str/join "\n" ["TEASER" + " EASER" + " ASER" + " SER" + " ER" + " R"]) (transpose/transpose - (join-with-line-separator ["T" - "EE" - "AAA" - "SSSS" - "EEEEE" - "RRRRRR"])))))) + (str/join "\n" ["T" + "EE" + "AAA" + "SSSS" + "EEEEE" + "RRRRRR"])))))) (deftest transpose_test_12 (testing "jagged triangle" - (is (= (join-with-line-separator ["123456" - "1 3456" - " 3456" - " 3 56" - " 56" - " 5"]) + (is (= (str/join "\n" ["123456" + "1 3456" + " 3456" + " 3 56" + " 56" + " 5"]) (transpose/transpose - (join-with-line-separator ["11" - "2" - "3333" - "444" - "555555" - "66666"])))))) + (str/join "\n" ["11" + "2" + "3333" + "444" + "555555" + "66666"]))))))