Skip to content

Commit ffbc340

Browse files
flower-field: reformat tests
[no important files changed]
1 parent 6f1e127 commit ffbc340

5 files changed

Lines changed: 217 additions & 31 deletions

File tree

CONTRIBUTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ bin/add-practice-exercise <exercise-slug>
1717

1818
- An exercise should include a `.meta/tests.toml` file if, and only if, the exercise has a `canonical-data.json` in [problem-specifications](https://github.com/exercism/problem-specifications/tree/main/exercises).
1919

20+
#### **Do you want to verify an exercise's example solution?**
21+
22+
- Use `bin/verify-exercises` to check that an exercise's example/exemplar solution passes its tests:
23+
24+
```shell
25+
bin/verify-exercises <exercise-slug> # omit the slug to verify every exercise
26+
```
27+
28+
- If `factor` is not on your `PATH`, point the `FACTOR` environment variable at the executable, e.g. `FACTOR=/path/to/factor bin/verify-exercises <exercise-slug>`.
29+
2030
#### **Do you want to report a bug?**
2131

2232
- **Ensure the bug was not already reported** by searching the [forum](https://forum.exercism.org/c/programming/factor).

exercises/practice/diamond/.meta/generator.jl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ module Diamond
22

33
function gen_test_case(case)
44
letter = case["input"]["letter"]
5-
expected = format_string_array(case["expected"])
6-
return "{ $(expected) }\n[ CHAR: $(letter) rows ] unit-test"
5+
rows = case["expected"]
6+
if length(rows) == 1
7+
expected = format_string_array(rows)
8+
return "{ $(expected) }\n[ CHAR: $(letter) rows ] unit-test"
9+
end
10+
body = join(map(s -> " \"$(escape_factor(s))\"", rows), "\n")
11+
expected = "{\n {\n$(body)\n }\n}"
12+
return "$(expected) [ CHAR: $(letter) rows ] unit-test"
713
end
814

915
end

exercises/practice/diamond/diamond/diamond-tests.factor

Lines changed: 82 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,91 @@ IN: diamond.tests
88
STOP-HERE
99

1010
"Degenerate case with no row containing 3 distinct groups of spaces" description
11-
{ { " A " "B B" " A " } }
12-
[ CHAR: B rows ] unit-test
11+
{
12+
{
13+
" A "
14+
"B B"
15+
" A "
16+
}
17+
} [ CHAR: B rows ] unit-test
1318

1419
"Smallest non-degenerate case with odd diamond side length" description
15-
{ { " A " " B B " "C C" " B B " " A " } }
16-
[ CHAR: C rows ] unit-test
20+
{
21+
{
22+
" A "
23+
" B B "
24+
"C C"
25+
" B B "
26+
" A "
27+
}
28+
} [ CHAR: C rows ] unit-test
1729

1830
"Smallest non-degenerate case with even diamond side length" description
19-
{ { " A " " B B " " C C " "D D" " C C " " B B " " A " } }
20-
[ CHAR: D rows ] unit-test
31+
{
32+
{
33+
" A "
34+
" B B "
35+
" C C "
36+
"D D"
37+
" C C "
38+
" B B "
39+
" A "
40+
}
41+
} [ CHAR: D rows ] unit-test
2142

2243
"Largest possible diamond" description
23-
{ { " A " " B B " " C C " " D D " " E E " " F F " " G G " " H H " " I I " " J J " " K K " " L L " " M M " " N N " " O O " " P P " " Q Q " " R R " " S S " " T T " " U U " " V V " " W W " " X X " " Y Y " "Z Z" " Y Y " " X X " " W W " " V V " " U U " " T T " " S S " " R R " " Q Q " " P P " " O O " " N N " " M M " " L L " " K K " " J J " " I I " " H H " " G G " " F F " " E E " " D D " " C C " " B B " " A " } }
24-
[ CHAR: Z rows ] unit-test
44+
{
45+
{
46+
" A "
47+
" B B "
48+
" C C "
49+
" D D "
50+
" E E "
51+
" F F "
52+
" G G "
53+
" H H "
54+
" I I "
55+
" J J "
56+
" K K "
57+
" L L "
58+
" M M "
59+
" N N "
60+
" O O "
61+
" P P "
62+
" Q Q "
63+
" R R "
64+
" S S "
65+
" T T "
66+
" U U "
67+
" V V "
68+
" W W "
69+
" X X "
70+
" Y Y "
71+
"Z Z"
72+
" Y Y "
73+
" X X "
74+
" W W "
75+
" V V "
76+
" U U "
77+
" T T "
78+
" S S "
79+
" R R "
80+
" Q Q "
81+
" P P "
82+
" O O "
83+
" N N "
84+
" M M "
85+
" L L "
86+
" K K "
87+
" J J "
88+
" I I "
89+
" H H "
90+
" G G "
91+
" F F "
92+
" E E "
93+
" D D "
94+
" C C "
95+
" B B "
96+
" A "
97+
}
98+
} [ CHAR: Z rows ] unit-test
Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
11
module FlowerField
22

3+
# Format an array of row strings as a single-level Factor array. Rows of
4+
# 0 or 1 elements stay inline; larger grids put one row per line, indented
5+
# four spaces, with the closing brace at column 0.
6+
function format_grid(rows)
7+
isempty(rows) && return "{ }"
8+
length(rows) == 1 && return "{ \"$(escape_factor(rows[1]))\" }"
9+
body = join(map(s -> " \"$(escape_factor(s))\"", rows), "\n")
10+
return "{\n$(body)\n}"
11+
end
12+
313
function gen_test_case(case)
414
garden = case["input"]["garden"]
515
expected = case["expected"]
6-
inp = format_string_array(garden)
7-
exp = format_string_array(expected)
8-
return "{ $(exp) }\n[ $(inp) annotate ] unit-test"
16+
# The expected grid is the input grid with some spaces replaced by
17+
# digits, so lay both out at the same indentation to make that obvious.
18+
# Collapsing the outer `{ ... }` onto the inner array's lines (`{ {`
19+
# ... `} }`) keeps the expected rows at the same column as the input.
20+
exp = "{ $(format_grid(expected)) }"
21+
inp = format_grid(garden)
22+
return "$(exp)\n[ $(inp) annotate ] unit-test"
923
end
1024

1125
end

exercises/practice/flower-field/flower-field/flower-field-tests.factor

Lines changed: 100 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ USING: exercism-tools flower-field io kernel tools.test unicode ;
22
IN: flower-field.tests
33

44
"no rows" description
5-
{ { } }
6-
[ { } annotate ] unit-test
5+
{ { } }
6+
[ { } annotate ] unit-test
77

88
STOP-HERE
99

@@ -12,20 +12,52 @@ STOP-HERE
1212
[ { "" } annotate ] unit-test
1313

1414
"no flowers" description
15-
{ { " " " " " " } }
16-
[ { " " " " " " } annotate ] unit-test
15+
{ {
16+
" "
17+
" "
18+
" "
19+
} }
20+
[ {
21+
" "
22+
" "
23+
" "
24+
} annotate ] unit-test
1725

1826
"garden full of flowers" description
19-
{ { "***" "***" "***" } }
20-
[ { "***" "***" "***" } annotate ] unit-test
27+
{ {
28+
"***"
29+
"***"
30+
"***"
31+
} }
32+
[ {
33+
"***"
34+
"***"
35+
"***"
36+
} annotate ] unit-test
2137

2238
"flower surrounded by spaces" description
23-
{ { "111" "1*1" "111" } }
24-
[ { " " " * " " " } annotate ] unit-test
39+
{ {
40+
"111"
41+
"1*1"
42+
"111"
43+
} }
44+
[ {
45+
" "
46+
" * "
47+
" "
48+
} annotate ] unit-test
2549

2650
"space surrounded by flowers" description
27-
{ { "***" "*8*" "***" } }
28-
[ { "***" "* *" "***" } annotate ] unit-test
51+
{ {
52+
"***"
53+
"*8*"
54+
"***"
55+
} }
56+
[ {
57+
"***"
58+
"* *"
59+
"***"
60+
} annotate ] unit-test
2961

3062
"horizontal line" description
3163
{ { "1*2*1" } }
@@ -36,20 +68,70 @@ STOP-HERE
3668
[ { "* *" } annotate ] unit-test
3769

3870
"vertical line" description
39-
{ { "1" "*" "2" "*" "1" } }
40-
[ { " " "*" " " "*" " " } annotate ] unit-test
71+
{ {
72+
"1"
73+
"*"
74+
"2"
75+
"*"
76+
"1"
77+
} }
78+
[ {
79+
" "
80+
"*"
81+
" "
82+
"*"
83+
" "
84+
} annotate ] unit-test
4185

4286
"vertical line, flowers at edges" description
43-
{ { "*" "1" " " "1" "*" } }
44-
[ { "*" " " " " " " "*" } annotate ] unit-test
87+
{ {
88+
"*"
89+
"1"
90+
" "
91+
"1"
92+
"*"
93+
} }
94+
[ {
95+
"*"
96+
" "
97+
" "
98+
" "
99+
"*"
100+
} annotate ] unit-test
45101

46102
"cross" description
47-
{ { " 2*2 " "25*52" "*****" "25*52" " 2*2 " } }
48-
[ { " * " " * " "*****" " * " " * " } annotate ] unit-test
103+
{ {
104+
" 2*2 "
105+
"25*52"
106+
"*****"
107+
"25*52"
108+
" 2*2 "
109+
} }
110+
[ {
111+
" * "
112+
" * "
113+
"*****"
114+
" * "
115+
" * "
116+
} annotate ] unit-test
49117

50118
"large garden" description
51-
{ { "1*22*1" "12*322" " 123*2" "112*4*" "1*22*2" "111111" } }
52-
[ { " * * " " * " " * " " * *" " * * " " " } annotate ] unit-test
119+
{ {
120+
"1*22*1"
121+
"12*322"
122+
" 123*2"
123+
"112*4*"
124+
"1*22*2"
125+
"111111"
126+
} }
127+
[ {
128+
" * * "
129+
" * "
130+
" * "
131+
" * *"
132+
" * * "
133+
" "
134+
} annotate ] unit-test
53135

54136
"multiple adjacent flowers" description
55137
{ { "1**1" } }

0 commit comments

Comments
 (0)