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

transpose: Add generator and regenerate tests #801

Merged
merged 2 commits into from
Jan 24, 2025
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
8 changes: 8 additions & 0 deletions exercises/practice/transpose/.meta/generator.clj
Original file line number Diff line number Diff line change
@@ -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))
16 changes: 16 additions & 0 deletions exercises/practice/transpose/.meta/generator.tpl
Original file line number Diff line number Diff line change
@@ -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}}
263 changes: 130 additions & 133 deletions exercises/practice/transpose/test/transpose_test.clj
Original file line number Diff line number Diff line change
@@ -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"]))))))