Skip to content

Commit aa23b4d

Browse files
ErikSchierboomee7
andauthored
sync: write fuller description for nested test cases (#301)
Some exercises in the `problem-specifications` repo have a `canonical-data.json` file that uses nesting, meaning that there is more than one `cases` property. `configlet` handled these nicely, but each `description` in each `tests.toml` file contained only the description of the test case itself. This could be unclear, and was especially confusing when test cases in different nested objects had the same description. Each `description` is purely for humans to read - it isn't used otherwise. With this commit, `configlet sync` writes the "full description" to the `tests.toml` file. For example, a `tests.toml` for the `triangle` exercise might previously contain (omitting other test cases for clarity): ```toml [3022f537-b8e5-4cc1-8f12-fd775827a00c] description = "sides may be floats" [adb4ee20-532f-43dc-8d31-e9271b7ef2bc] description = "sides may be floats" [26d9d59d-f8f1-40d3-ad58-ae4d54123d7d] description = "sides may be floats" ``` But with this commit: ```toml [3022f537-b8e5-4cc1-8f12-fd775827a00c] description = "equilateral triangle → sides may be floats" [adb4ee20-532f-43dc-8d31-e9271b7ef2bc] description = "isosceles triangle → sides may be floats" [26d9d59d-f8f1-40d3-ad58-ae4d54123d7d] description = "scalene triangle → sides may be floats" ``` For the canonical data for this exercise, see: https://github.com/exercism/problem-specifications/blob/f17f457fdc06/exercises/triangle/canonical-data.json We decided that putting everything in `description` is better than: - adding extra key/value pair(s) named e.g. `category` or `super` - adding TOML comments - using sub-tables While working on this PR, we noticed that 18 exercises in `problem-specifications` had unnecessary nesting. We simplified them in exercism/problem-specifications#1798 Closes: #202 Co-authored-by: ee7 <[email protected]>
1 parent ac34a79 commit aa23b4d

File tree

2 files changed

+57
-27
lines changed

2 files changed

+57
-27
lines changed

src/sync/probspecs.nim

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,23 @@ func isReimplementation*(testCase: ProbSpecsTestCase): bool =
5656
func reimplements*(testCase: ProbSpecsTestCase): string =
5757
testCase["reimplements"].getStr()
5858

59-
proc initProbSpecsTestCases(node: JsonNode): seq[ProbSpecsTestCase] =
60-
## Returns a seq of every individual test case in `node` (flattening).
59+
proc initProbSpecsTestCases(node: JsonNode, prefix = ""): seq[ProbSpecsTestCase] =
60+
## Returns a seq of every individual test case in `node` (flattening). We
61+
## alter each `description` value to indicate any nesting, which is OK because
62+
## we only use the `description` for writing `tests.toml`.
6163
if node.hasKey("uuid"):
64+
if node.hasKey("description"):
65+
if node["description"].kind == JString:
66+
node["description"].str = &"""{prefix}{node["description"].getStr()}"""
6267
result.add ProbSpecsTestCase(node)
6368
elif node.hasKey("cases"):
69+
let prefix =
70+
if node.hasKey("description"):
71+
&"""{prefix}{node["description"].getStr()}"""
72+
else:
73+
prefix
6474
for childNode in node["cases"].getElems():
65-
result.add initProbSpecsTestCases(childNode)
75+
result.add initProbSpecsTestCases(childNode, prefix)
6676

6777
proc grainsWorkaround(grainsPath: string): JsonNode =
6878
## Parses the canonical data file for `grains`, replacing the too-large

tests/test_binary.nim

Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79,19 +79,19 @@ Checking exercises...
7979
- disallow right empty strand (920cd6e3-18f4-4143-b6b8-74270bb8f8a3)
8080
- disallow empty second strand (9ab9262f-3521-4191-81f5-0ed184a5aa89)
8181
[warn] high-scores: missing 2 test cases
82-
- Latest score after personal top scores (2df075f9-fec9-4756-8f40-98c52a11504f)
83-
- Scores after personal top scores (809c4058-7eb1-4206-b01e-79238b9b71bc)
82+
- Top 3 scores → Latest score after personal top scores (2df075f9-fec9-4756-8f40-98c52a11504f)
83+
- Top 3 scores → Scores after personal top scores (809c4058-7eb1-4206-b01e-79238b9b71bc)
8484
[warn] isogram: missing 1 test cases
8585
- word with duplicated character and with two hyphens (0d0b8644-0a1e-4a31-a432-2b3ee270d847)
8686
[warn] kindergarten-garden: missing 8 test cases
87-
- for Charlie (566b621b-f18e-4c5f-873e-be30544b838c)
88-
- for David (3ad3df57-dd98-46fc-9269-1877abf612aa)
89-
- for Eve (0f0a55d1-9710-46ed-a0eb-399ba8c72db2)
90-
- for Fred (a7e80c90-b140-4ea1-aee3-f4625365c9a4)
91-
- for Ginny (9d94b273-2933-471b-86e8-dba68694c615)
92-
- for Harriet (f55bc6c2-ade8-4844-87c4-87196f1b7258)
93-
- for Ileana (759070a3-1bb1-4dd4-be2c-7cce1d7679ae)
94-
- for Joseph (78578123-2755-4d4a-9c7d-e985b8dda1c6)
87+
- full garden → for Charlie (566b621b-f18e-4c5f-873e-be30544b838c)
88+
- full garden → for David (3ad3df57-dd98-46fc-9269-1877abf612aa)
89+
- full garden → for Eve (0f0a55d1-9710-46ed-a0eb-399ba8c72db2)
90+
- full garden → for Fred (a7e80c90-b140-4ea1-aee3-f4625365c9a4)
91+
- full garden → for Ginny (9d94b273-2933-471b-86e8-dba68694c615)
92+
- full garden → for Harriet (f55bc6c2-ade8-4844-87c4-87196f1b7258)
93+
- full garden → for Ileana (759070a3-1bb1-4dd4-be2c-7cce1d7679ae)
94+
- full garden → for Joseph (78578123-2755-4d4a-9c7d-e985b8dda1c6)
9595
[warn] luhn: missing 1 test cases
9696
- non-numeric, non-space char in the middle with a sum that's divisible by 10 isn't allowed (8b72ad26-c8be-49a2-b99c-bcc3bf631b33)
9797
[warn] prime-factors: missing 5 test cases
@@ -252,12 +252,22 @@ All exercises are synced!
252252
+#
253253
+# As regular comments will be removed when this file is regenerated, comments
254254
+# can be added in a "comment" key.
255+
-description = "Personal top three from a list of scores"
256+
+description = "Top 3 scores → Personal top three from a list of scores"
257+
-description = "Personal top highest to lowest"
258+
+description = "Top 3 scores → Personal top highest to lowest"
259+
-description = "Personal top when there is a tie"
260+
+description = "Top 3 scores → Personal top when there is a tie"
261+
-description = "Personal top when there are less than 3"
262+
+description = "Top 3 scores → Personal top when there are less than 3"
263+
-description = "Personal top when there is only one"
264+
+description = "Top 3 scores → Personal top when there is only one"
255265
+
256266
+[2df075f9-fec9-4756-8f40-98c52a11504f]
257-
+description = "Latest score after personal top scores"
267+
+description = "Top 3 scores → Latest score after personal top scores"
258268
+
259269
+[809c4058-7eb1-4206-b01e-79238b9b71bc]
260-
+description = "Scores after personal top scores"
270+
+description = "Top 3 scores → Scores after personal top scores"
261271
--- exercises/practice/isogram/.meta/tests.toml
262272
+++ exercises/practice/isogram/.meta/tests.toml
263273
-# This is an auto-generated file. Regular comments will be removed when this
@@ -293,38 +303,48 @@ All exercises are synced!
293303
+#
294304
+# As regular comments will be removed when this file is regenerated, comments
295305
+# can be added in a "comment" key.
306+
-description = "garden with single student"
307+
+description = "partial garden → garden with single student"
308+
-description = "different garden with single student"
309+
+description = "partial garden → different garden with single student"
310+
-description = "garden with two students"
311+
+description = "partial garden → garden with two students"
312+
-description = "second student's garden"
313+
+description = "partial garden → multiple students for the same garden with three students → second student's garden"
314+
-description = "third student's garden"
315+
+description = "partial garden → multiple students for the same garden with three students → third student's garden"
296316
-description = "first student's garden"
297-
+description = "for Alice, first student's garden"
317+
+description = "full garden → for Alice, first student's garden"
298318
-description = "second student's garden"
299-
+description = "for Bob, second student's garden"
319+
+description = "full garden → for Bob, second student's garden"
300320
+
301321
+[566b621b-f18e-4c5f-873e-be30544b838c]
302-
+description = "for Charlie"
322+
+description = "full garden → for Charlie"
303323
+
304324
+[3ad3df57-dd98-46fc-9269-1877abf612aa]
305-
+description = "for David"
325+
+description = "full garden → for David"
306326
+
307327
+[0f0a55d1-9710-46ed-a0eb-399ba8c72db2]
308-
+description = "for Eve"
328+
+description = "full garden → for Eve"
309329
+
310330
+[a7e80c90-b140-4ea1-aee3-f4625365c9a4]
311-
+description = "for Fred"
331+
+description = "full garden → for Fred"
312332
+
313333
+[9d94b273-2933-471b-86e8-dba68694c615]
314-
+description = "for Ginny"
334+
+description = "full garden → for Ginny"
315335
+
316336
+[f55bc6c2-ade8-4844-87c4-87196f1b7258]
317-
+description = "for Harriet"
337+
+description = "full garden → for Harriet"
318338
+
319339
+[759070a3-1bb1-4dd4-be2c-7cce1d7679ae]
320-
+description = "for Ileana"
340+
+description = "full garden → for Ileana"
321341
+
322342
+[78578123-2755-4d4a-9c7d-e985b8dda1c6]
323-
+description = "for Joseph"
343+
+description = "full garden → for Joseph"
324344
-description = "second to last student's garden"
325-
+description = "for Kincaid, second to last student's garden"
345+
+description = "full garden → for Kincaid, second to last student's garden"
326346
-description = "last student's garden"
327-
+description = "for Larry, last student's garden"
347+
+description = "full garden → for Larry, last student's garden"
328348
--- exercises/practice/luhn/.meta/tests.toml
329349
+++ exercises/practice/luhn/.meta/tests.toml
330350
-# This is an auto-generated file. Regular comments will be removed when this

0 commit comments

Comments
 (0)