Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions config/generator_macros.j2
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,14 @@ include("{{ exercise }}.jl")
{% macro julia_dict(d, char_keys=false) -%}
Dict({% for k, v in d.items() %}{% if char_keys %}'{{ k }}'{% else %}{{ julia_string(k) }}{% endif %} => {% if v is string %}{{ julia_string(v) }}{% elif v is sequence %}{{ julia_vector(v) }}{% else %}{{ v }}{% endif %}{% if not loop.last %}, {% endif %}{% endfor %})
{%- endmacro %}

{# A Julia Matrix literal from a list of rows; empty and single-column matrices need special forms #}
{% macro julia_matrix(rows) -%}
{%- if not rows or not rows[0] -%}
Int[;;]
{%- elif rows[0] | length == 1 -%}
reshape([{{ rows | map("first") | join(", ") }}], :, 1)
{%- else -%}
[{% for row in rows %}{{ row | join(" ") }}{% if not loop.last %}; {% endif %}{% endfor %}]
{%- endif %}
{%- endmacro %}
11 changes: 11 additions & 0 deletions exercises/practice/flower-field/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{%- import "generator_macros.j2" as macros with context -%}
{{ macros.canonical_ref() }}

{{ macros.header() }}
{% for case in cases %}
@testset "{{ case["description"] }}" begin
{%- set garden = macros.julia_vector(case["input"]["garden"]) if case["input"]["garden"] else "String[]" %}
@test annotate({{ garden }}) == {{ macros.julia_vector(case["expected"]) }}
end
{% endfor %}
end
104 changes: 19 additions & 85 deletions exercises/practice/flower-field/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,129 +1,63 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/flower-field/canonical-data.json
# File last updated on 2026-10-24

using Test

include("flower-field.jl")

@testset verbose = true "tests" begin
@testset "no rows" begin
@test annotate([]) == []
@test annotate(String[]) == []
end

@testset "no columns" begin
@test annotate([""]) == [""]
end

@testset "no flowers" begin
flowerfield = [" ",
" ",
" "]
out = [" ",
" ",
" "]
@test annotate(flowerfield) == out
@test annotate([" ", " ", " "]) == [" ", " ", " "]
end

@testset "garden full of flowers" begin
flowerfield = ["***",
"***",
"***"]
out = ["***",
"***",
"***"]
@test annotate(flowerfield) == out
@test annotate(["***", "***", "***"]) == ["***", "***", "***"]
end

@testset "flower surrounded by spaces" begin
flowerfield = [" ",
" * ",
" "]
out = ["111",
"1*1",
"111"]
@test annotate(flowerfield) == out
@test annotate([" ", " * ", " "]) == ["111", "1*1", "111"]
end

@testset "space surrounded by flowers" begin
flowerfield = ["***",
"* *",
"***"]
out = ["***",
"*8*",
"***"]
@test annotate(flowerfield) == out
@test annotate(["***", "* *", "***"]) == ["***", "*8*", "***"]
end

@testset "horizontal line" begin
flowerfield = [" * * "]
out = ["1*2*1"]
@test annotate(flowerfield) == out
@test annotate([" * * "]) == ["1*2*1"]
end

@testset "horizontal line, flowers at edges" begin
flowerfield = ["* *"]
out = ["*1 1*"]
@test annotate(flowerfield) == out
@test annotate(["* *"]) == ["*1 1*"]
end

@testset "vertical line" begin
flowerfield = [" ",
"*",
" ",
"*",
" "]
out = ["1",
"*",
"2",
"*",
"1"]
@test annotate(flowerfield) == out
@test annotate([" ", "*", " ", "*", " "]) == ["1", "*", "2", "*", "1"]
end

@testset "vertical line, flowers at edges" begin
flowerfield = ["*",
" ",
" ",
" ",
"*"]
out = ["*",
"1",
" ",
"1",
"*"]
@test annotate(flowerfield) == out
@test annotate(["*", " ", " ", " ", "*"]) == ["*", "1", " ", "1", "*"]
end

@testset "cross" begin
flowerfield = [" * ",
" * ",
"*****",
" * ",
" * "]
out = [" 2*2 ",
"25*52",
"*****",
"25*52",
" 2*2 "]
@test annotate(flowerfield) == out
@test annotate([" * ", " * ", "*****", " * ", " * "]) ==
[" 2*2 ", "25*52", "*****", "25*52", " 2*2 "]
end

@testset "large garden" begin
flowerfield = [" * * ",
" * ",
" * ",
" * *",
" * * ",
" "]
out = ["1*22*1",
"12*322",
" 123*2",
"112*4*",
"1*22*2",
"111111"]
@test annotate(flowerfield) == out
@test annotate([" * * ", " * ", " * ", " * *", " * * ", " "]) ==
["1*22*1", "12*322", " 123*2", "112*4*", "1*22*2", "111111"]
end

@testset "multiple adjacent flowers" begin
flowerfield = [" ** "]
out = ["1**1"]
@test annotate(flowerfield) == out
end
@test annotate([" ** "]) == ["1**1"]
end
end
10 changes: 10 additions & 0 deletions exercises/practice/game-of-life/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{%- import "generator_macros.j2" as macros with context -%}
{{ macros.canonical_ref() }}

{{ macros.header() }}
{% for case in cases %}
@testset "{{ case["description"] }}" begin
@test gameoflife({{ macros.julia_matrix(case["input"]["matrix"]) }}) == {{ macros.julia_matrix(case["expected"]) }}
end
{% endfor %}
end
100 changes: 23 additions & 77 deletions exercises/practice/game-of-life/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,99 +1,45 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/game-of-life/canonical-data.json
# File last updated on 2026-10-24

using Test

include("game-of-life.jl")

@testset verbose = true "tests" begin
@testset "empty matrix" begin
matrix = reshape([], 0,2)

expected = reshape([], 0,2)
@test gameoflife(matrix) == expected
@test gameoflife(Int[;;]) == Int[;;]
end

@testset "live cells with zero live neighbors die" begin
matrix = [0 0 0;
0 1 0;
0 0 0]

expected = [0 0 0;
0 0 0;
0 0 0]
@test gameoflife(matrix) == expected
@test gameoflife([0 0 0; 0 1 0; 0 0 0]) == [0 0 0; 0 0 0; 0 0 0]
end

@testset "live cells with only one live neighbor die" begin
matrix = [0 0 0;
0 1 0;
0 1 0]

expected = [0 0 0;
0 0 0;
0 0 0]
@test gameoflife(matrix) == expected
@test gameoflife([0 0 0; 0 1 0; 0 1 0]) == [0 0 0; 0 0 0; 0 0 0]
end

@testset "live cells with two live neighbors stay alive" begin
matrix = [1 0 1;
1 0 1;
1 0 1]

expected = [0 0 0;
1 0 1;
0 0 0]
@test gameoflife(matrix) == expected
@test gameoflife([1 0 1; 1 0 1; 1 0 1]) == [0 0 0; 1 0 1; 0 0 0]
end

@testset "live cells with three live neighbors stay alive" begin
matrix = [0 1 0;
1 0 0;
1 1 0]

expected = [0 0 0;
1 0 0;
1 1 0]
@test gameoflife(matrix) == expected
@test gameoflife([0 1 0; 1 0 0; 1 1 0]) == [0 0 0; 1 0 0; 1 1 0]
end

@testset "dead cells with three live neighbors become alive" begin
matrix = [1 1 0;
0 0 0;
1 0 0]

expected = [0 0 0;
1 1 0;
0 0 0]
@test gameoflife(matrix) == expected
@test gameoflife([1 1 0; 0 0 0; 1 0 0]) == [0 0 0; 1 1 0; 0 0 0]
end

@testset "live cells with four or more neighbors die" begin
matrix = [1 1 1;
1 1 1;
1 1 1]

expected = [1 0 1;
0 0 0;
1 0 1]
@test gameoflife(matrix) == expected
@test gameoflife([1 1 1; 1 1 1; 1 1 1]) == [1 0 1; 0 0 0; 1 0 1]
end

@testset "bigger matrix" begin
matrix = [1 1 0 1 1 0 0 0;
1 0 1 1 0 0 0 0;
1 1 1 0 0 1 1 1;
0 0 0 0 0 1 1 0;
1 0 0 0 1 1 0 0;
1 1 0 0 0 1 1 1;
0 0 1 0 1 0 0 1;
1 0 0 0 0 0 1 1]

expected = [1 1 0 1 1 0 0 0;
0 0 0 0 0 1 1 0;
1 0 1 1 1 1 0 1;
1 0 0 0 0 0 0 1;
1 1 0 0 1 0 0 1;
1 1 0 1 0 0 0 1;
1 0 0 0 0 0 0 0;
0 0 0 0 0 0 1 1]
@test gameoflife(matrix) == expected
@test gameoflife([1 1 0 1 1 0 0 0; 1 0 1 1 0 0 0 0; 1 1 1 0 0 1 1 1;
0 0 0 0 0 1 1 0; 1 0 0 0 1 1 0 0; 1 1 0 0 0 1 1 1;
0 0 1 0 1 0 0 1; 1 0 0 0 0 0 1 1]) ==
[1 1 0 1 1 0 0 0; 0 0 0 0 0 1 1 0; 1 0 1 1 1 1 0 1; 1 0 0 0 0 0 0 1;
1 1 0 0 1 0 0 1; 1 1 0 1 0 0 0 1; 1 0 0 0 0 0 0 0; 0 0 0 0 0 0 1 1]
end
end
11 changes: 11 additions & 0 deletions exercises/practice/matrix/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{%- import "generator_macros.j2" as macros with context -%}
{{ macros.canonical_ref() }}

{{ macros.header() }}
{% for case in cases %}
@testset "{{ case["description"] }}" begin
rows, columns = matrix({{ macros.julia_string(case["input"]["string"]) }})
@test {{ case["property"] }}s[{{ case["input"]["index"] }}] == {{ macros.julia_vector(case["expected"]) }}
end
{% endfor %}
end
36 changes: 20 additions & 16 deletions exercises/practice/matrix/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/matrix/canonical-data.json
# File last updated on 2026-10-24

using Test

include("matrix.jl")
Expand All @@ -6,40 +10,40 @@ include("matrix.jl")
@testset "extract row from one number matrix" begin
rows, columns = matrix("1")
@test rows[1] == [1]
end
end

@testset "can extract row" begin
@testset "can extract row" begin
rows, columns = matrix("1 2\n3 4")
@test rows[2] == [3, 4]
end
end

@testset "extract row where numbers have different widths" begin
@testset "extract row where numbers have different widths" begin
rows, columns = matrix("1 2\n10 20")
@test rows[2] == [10, 20]
end
end

@testset "can extract row from non-square matrix with no corresponding column" begin
@testset "can extract row from non-square matrix with no corresponding column" begin
rows, columns = matrix("1 2 3\n4 5 6\n7 8 9\n8 7 6")
@test rows[4] == [8, 7, 6]
end
end

@testset "extract column from one number matrix" begin
rows, columns = matrix("1")
@testset "extract column from one number matrix" begin
rows, columns = matrix("1")
@test columns[1] == [1]
end
end

@testset "can extract column" begin
@testset "can extract column" begin
rows, columns = matrix("1 2 3\n4 5 6\n7 8 9")
@test columns[3] == [3, 6, 9]
end
end

@testset "can extract column from non-square matrix with no corresponding row" begin
@testset "can extract column from non-square matrix with no corresponding row" begin
rows, columns = matrix("1 2 3 4\n5 6 7 8\n9 8 7 6")
@test columns[4] == [4, 8, 6]
end
end

@testset "extract column where numbers have different widths" begin
@testset "extract column where numbers have different widths" begin
rows, columns = matrix("89 1903 3\n18 3 1\n9 4 800")
@test columns[2] == [1903, 3, 4]
end
end
end
10 changes: 10 additions & 0 deletions exercises/practice/saddle-points/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{%- import "generator_macros.j2" as macros with context -%}
{{ macros.canonical_ref() }}

{{ macros.header() }}
{% for case in cases %}
@testset "{{ case["description"] }}" begin
@test sort(saddlepoints({{ macros.julia_matrix(case["input"]["matrix"]) }})) == [{% for p in case["expected"] | sort(attribute="row,column") %}({{ p["row"] }}, {{ p["column"] }}){% if not loop.last %}, {% endif %}{% endfor %}]
end
{% endfor %}
end
Loading
Loading