Skip to content

Commit 328fc65

Browse files
Change library for templates
1 parent 750a785 commit 328fc65

File tree

8 files changed

+55
-48
lines changed

8 files changed

+55
-48
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
(ns isogram-test
22
(:require [clojure.test :refer [deftest testing is]]
33
isogram))
4-
{% for test_case in test_cases %}
5-
(deftest isogram_test_{{forloop.counter}}
6-
(testing "{{test_case.path|join:" - "}}"
7-
{% if test_case.expected %}(is (isogram/isogram? "{{test_case.input.phrase}}")))) {% else %}(is (not (isogram/isogram? "{{test_case.input.phrase}}")))){% endif %}
8-
{% endfor %}
4+
5+
{{#test_cases}}
6+
(deftest isogram_test_{{idx}}
7+
(testing "{{description}}"
8+
{{#expected}}
9+
(is (isogram/isogram? "{{input.phrase}}"))))
10+
{{/expected}}
11+
{{^expected}}
12+
(is (not (isogram/isogram? "{{input.phrase}}")))))
13+
{{/expected}}
14+
15+
{{/test_cases}}
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
(ns isogram)
1+
(ns isogram
2+
(:require [clojure.string :as str]))
23

3-
(defn isogram? [] ;; <- arglist goes here
4-
;; your code goes here
5-
)
4+
(defn isogram? [word]
5+
(apply distinct? (filter #(Character/isLetter %) (str/lower-case word))))

exercises/practice/isogram/test/isogram_test.clj

+14-14
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,57 @@
44

55
(deftest isogram_test_1
66
(testing "empty string"
7-
(is (isogram/isogram? ""))))
7+
(is (isogram/isogram? ""))))
88

99
(deftest isogram_test_2
1010
(testing "isogram with only lower case characters"
11-
(is (isogram/isogram? "isogram"))))
11+
(is (isogram/isogram? "isogram"))))
1212

1313
(deftest isogram_test_3
1414
(testing "word with one duplicated character"
15-
(is (not (isogram/isogram? "eleven"))))
15+
(is (not (isogram/isogram? "eleven")))))
1616

1717
(deftest isogram_test_4
1818
(testing "word with one duplicated character from the end of the alphabet"
19-
(is (not (isogram/isogram? "zzyzx"))))
19+
(is (not (isogram/isogram? "zzyzx")))))
2020

2121
(deftest isogram_test_5
2222
(testing "longest reported english isogram"
23-
(is (isogram/isogram? "subdermatoglyphic"))))
23+
(is (isogram/isogram? "subdermatoglyphic"))))
2424

2525
(deftest isogram_test_6
2626
(testing "word with duplicated character in mixed case"
27-
(is (not (isogram/isogram? "Alphabet"))))
27+
(is (not (isogram/isogram? "Alphabet")))))
2828

2929
(deftest isogram_test_7
3030
(testing "word with duplicated character in mixed case, lowercase first"
31-
(is (not (isogram/isogram? "alphAbet"))))
31+
(is (not (isogram/isogram? "alphAbet")))))
3232

3333
(deftest isogram_test_8
3434
(testing "hypothetical isogrammic word with hyphen"
35-
(is (isogram/isogram? "thumbscrew-japingly"))))
35+
(is (isogram/isogram? "thumbscrew-japingly"))))
3636

3737
(deftest isogram_test_9
3838
(testing "hypothetical word with duplicated character following hyphen"
39-
(is (not (isogram/isogram? "thumbscrew-jappingly"))))
39+
(is (not (isogram/isogram? "thumbscrew-jappingly")))))
4040

4141
(deftest isogram_test_10
4242
(testing "isogram with duplicated hyphen"
43-
(is (isogram/isogram? "six-year-old"))))
43+
(is (isogram/isogram? "six-year-old"))))
4444

4545
(deftest isogram_test_11
4646
(testing "made-up name that is an isogram"
47-
(is (isogram/isogram? "Emily Jung Schwartzkopf"))))
47+
(is (isogram/isogram? "Emily Jung Schwartzkopf"))))
4848

4949
(deftest isogram_test_12
5050
(testing "duplicated character in the middle"
51-
(is (not (isogram/isogram? "accentor"))))
51+
(is (not (isogram/isogram? "accentor")))))
5252

5353
(deftest isogram_test_13
5454
(testing "same first and last characters"
55-
(is (not (isogram/isogram? "angola"))))
55+
(is (not (isogram/isogram? "angola")))))
5656

5757
(deftest isogram_test_14
5858
(testing "word with duplicated character and with two hyphens"
59-
(is (not (isogram/isogram? "up-to-date"))))
59+
(is (not (isogram/isogram? "up-to-date")))))
6060

Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
(ns two-fer-test
22
(:require [clojure.test :refer [deftest testing is]]
33
two-fer))
4-
{% for test_case in test_cases %}
5-
(deftest two-fer_test_{{forloop.counter}}
6-
(testing "{{test_case.path|join:" - "}}"
7-
(is (= "{{test_case.expected}}" (two-fer/two-fer{% if test_case.input.name %} "{{test_case.input.name}}"{% endif %})))))
8-
{% endfor %}
4+
5+
{{#test_cases}}
6+
(deftest two-fer_test_{{idx}}
7+
(testing "{{description}}"
8+
(is (= "{{expected}}" (two-fer/two-fer{{#input.name}} "{{input.name}}"{{/input.name}})))))
9+
10+
{{/test_cases}}
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
(ns two-fer)
22

3-
(defn two-fer [name] ;; <- arglist goes here
4-
;; your code goes here
5-
)
3+
(defn two-fer
4+
([] (str "One for you, one for me."))
5+
([name] (str "One for " name ", one for me.")))

generators/deps.edn

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{:paths ["src"]
22
:deps {org.clojure/data.json {:mvn/version "2.5.1"}
3-
selmer/selmer {:mvn/version "1.12.61"}
3+
pogonos/pogonos {:mvn/version "0.2.1"}
44
io.github.tonsky/toml-clj {:mvn/version "0.1.0"}
55
clj-jgit/clj-jgit {:mvn/version "1.1.0"}}}

generators/src/canonical_data.clj

+8-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
[toml-clj.core :as toml]
55
[clj-jgit.porcelain :refer [git-clone git-pull load-repo]]
66
[log]
7-
[paths]))
7+
[paths]
8+
[clojure.string :as str]))
89

910
(def git-url "https://github.com/exercism/problem-specifications.git")
1011

@@ -41,9 +42,11 @@
4142
(let [excluded (excluded-uuids slug)]
4243
(fn [node] (contains? excluded (:uuid node)))))
4344

44-
(defn- node->test-case [node path]
45+
(defn- node->test-case [idx node]
4546
(-> node
46-
(assoc :path path :error (get-in node [:expected :error]))
47+
(assoc :idx (inc idx)
48+
:description (str/join " - " (:path node))
49+
:error (get-in node [:expected :error]))
4750
(dissoc :reimplements :comments :scenarios)))
4851

4952
(defn- test-case-nodes
@@ -54,12 +57,12 @@
5457
updated-path (if description (conj path description) path)]
5558
(if children
5659
(mapcat #(test-case-nodes % updated-path) children)
57-
[(node->test-case node updated-path)]))))
60+
[(assoc node :path updated-path)]))))
5861

5962
(defn test-cases [slug]
6063
(->> slug
6164
(canonical-data)
6265
(test-case-nodes)
6366
(remove (excluded? slug))
67+
(map-indexed node->test-case)
6468
(into [])))
65-

generators/src/templates.clj

+6-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
(ns templates
2-
(:require [selmer.parser :as selmer]
2+
(:require [pogonos.core :as pg]
3+
[pogonos.output :as output]
34
[log]
45
[paths]))
56

@@ -11,14 +12,8 @@
1112
(map #(-> % (.getParentFile) (.getParentFile) (.getName)))
1213
(set)))
1314

14-
(defn- render-template [data template]
15-
(selmer/render (slurp template) data))
16-
17-
(defn- render [slug test-cases]
18-
(let [data {:slug slug :test_cases test-cases}]
19-
(render-template data (paths/generator-template-file slug))))
20-
2115
(defn generate-tests-file [slug test-cases]
22-
(->> test-cases
23-
(render slug)
24-
(spit (paths/tests-file slug))))
16+
(pg/render-file
17+
(paths/generator-template-file slug)
18+
{:test_cases test-cases}
19+
{:output (output/to-file (paths/tests-file slug))}))

0 commit comments

Comments
 (0)