Skip to content

Commit

Permalink
transpose: Add generator and regenerate tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tasxatzial committed Jan 23, 2025
1 parent 01ca533 commit 145f8f9
Show file tree
Hide file tree
Showing 2 changed files with 146 additions and 133 deletions.
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"]))))))

0 comments on commit 145f8f9

Please sign in to comment.