Skip to content

Commit

Permalink
reverse-string: Add generator and regenerate tests (#774)
Browse files Browse the repository at this point in the history
* add generator and regenerate tests

* update example solution

* update starter file

* update contributors

* fix example solution
  • Loading branch information
tasxatzial authored Jan 17, 2025
1 parent 3f9f0f5 commit 57805fa
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 29 deletions.
3 changes: 2 additions & 1 deletion exercises/practice/reverse-string/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"amscotti",
"AndreaCrotti",
"haus",
"mtkp"
"mtkp",
"tasxatzial"
],
"files": {
"solution": [
Expand Down
6 changes: 3 additions & 3 deletions exercises/practice/reverse-string/.meta/example.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
(ns reverse-string
(:require [clojure.string :as s]))
(ns reverse-string)

(defn reverse-string
([word] (s/reverse word)))
[s]
(apply str (into () s)))
8 changes: 8 additions & 0 deletions exercises/practice/reverse-string/.meta/generator.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
(ns reverse-string-test
(:require [clojure.test :refer [deftest testing is]]
reverse-string))
{{#test_cases.reverse}}
(deftest reverse-string_test_{{idx}}
(testing {{description}}
(is (= {{expected}} (reverse-string/reverse-string {{input.value}})))))
{{/test_cases.reverse~}}
24 changes: 21 additions & 3 deletions exercises/practice/reverse-string/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# This is an auto-generated file.
#
# Regenerating this file via `configlet sync` will:
# - Recreate every `description` key/value pair
# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications
# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion)
# - Preserve any other key/value pair
#
# As user-added comments (using the # character) will be removed when this file
# is regenerated, comments can be added via a `comment` key.

[c3b7d806-dced-49ee-8543-933fd1719b1c]
description = "an empty string"
Expand All @@ -19,3 +26,14 @@ description = "a palindrome"

[b9e7dec1-c6df-40bd-9fa3-cd7ded010c4c]
description = "an even-sized word"

[1bed0f8a-13b0-4bd3-9d59-3d0593326fa2]
description = "wide characters"

[93d7e1b8-f60f-4f3c-9559-4056e10d2ead]
description = "grapheme cluster with pre-combined form"
include = false

[1028b2c1-6763-4459-8540-2da47ca512d9]
description = "grapheme clusters"
include = false
8 changes: 5 additions & 3 deletions exercises/practice/reverse-string/src/reverse_string.clj
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
(ns reverse-string)

(defn reverse-string [s] ;; <- arglist goes here
;; your code goes here
)
(defn reverse-string
"Reverses the given string"
[s]
;; function body
)
42 changes: 23 additions & 19 deletions exercises/practice/reverse-string/test/reverse_string_test.clj
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
(ns reverse-string-test
(:require [clojure.test :refer [deftest testing is]]
[reverse-string :refer [reverse-string]]))
reverse-string))

(deftest empty-string
(testing "An empty string"
(is (= "" (reverse-string "")))))
(deftest reverse-string_test_1
(testing "an empty string"
(is (= "" (reverse-string/reverse-string "")))))

(deftest a-word
(testing "A word"
(is (= "tobor" (reverse-string "robot")))))
(deftest reverse-string_test_2
(testing "a word"
(is (= "tobor" (reverse-string/reverse-string "robot")))))

(deftest capitalised-word
(testing "A capitalized word"
(is (= "nemaR" (reverse-string "Ramen")))))
(deftest reverse-string_test_3
(testing "a capitalized word"
(is (= "nemaR" (reverse-string/reverse-string "Ramen")))))

(deftest sentence-with-punctuation
(testing "A sentence with punctuation"
(is (= "!yrgnuh m'I" (reverse-string "I'm hungry!")))))
(deftest reverse-string_test_4
(testing "a sentence with punctuation"
(is (= "!yrgnuh m'I" (reverse-string/reverse-string "I'm hungry!")))))

(deftest palindrome
(testing "A palindrome"
(is (= "racecar" (reverse-string "racecar")))))
(deftest reverse-string_test_5
(testing "a palindrome"
(is (= "racecar" (reverse-string/reverse-string "racecar")))))

(deftest even-sized-word
(testing "An even sized word"
(is (= "reward" (reverse-string "drawer")))))
(deftest reverse-string_test_6
(testing "an even-sized word"
(is (= "reward" (reverse-string/reverse-string "drawer")))))

(deftest reverse-string_test_7
(testing "wide characters"
(is (= "猫子" (reverse-string/reverse-string "子猫")))))

0 comments on commit 57805fa

Please sign in to comment.