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
9 changes: 7 additions & 2 deletions config/generator_macros.j2
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,17 @@ include("{{ exercise }}.jl")
{%- endif %}
{%- endmacro %}

{# A Julia string literal, with \, " and $ escaped #}
{# A Julia string literal, with \, ", $, newlines and tabs escaped #}
{% macro julia_string(s) -%}
"{{ s | replace("\\", "\\\\") | replace('"', '\\"') | replace("$", "\\$") }}"
"{{ s | replace("\\", "\\\\") | replace('"', '\\"') | replace("$", "\\$") | replace("\n", "\\n") | replace("\t", "\\t") }}"
{%- endmacro %}

{# A Julia vector literal; string elements are quoted with julia_string, nested lists become nested vectors #}
{% macro julia_vector(xs) -%}
[{% for x in xs %}{% if x is string %}{{ julia_string(x) }}{% elif x is sequence %}{{ julia_vector(x) }}{% else %}{{ x }}{% endif %}{% if not loop.last %}, {% endif %}{% endfor %}]
{%- endmacro %}

{# A Julia Dict literal; string keys are quoted with julia_string, or as Chars if char_keys is true #}
{% 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 %}
10 changes: 10 additions & 0 deletions exercises/practice/etl/.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 transform(Dict({% for score, letters in case["input"]["legacy"].items() %}{{ score }} => [{% for c in letters %}'{{ c }}'{% if not loop.last %}, {% endif %}{% endfor %}]{% if not loop.last %}, {% endif %}{% endfor %})) == {{ macros.julia_dict(case["expected"], char_keys=true) }}
end
{% endfor %}
end
37 changes: 17 additions & 20 deletions exercises/practice/etl/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,37 +1,34 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/etl/canonical-data.json
# File last updated on 2026-10-24

using Test

include("etl.jl")

@testset verbose = true "tests" begin
@testset "single letter" begin
input = Dict(1=>['A'])
output = Dict('a'=>1)
@test transform(input) == output
@test transform(Dict(1 => ['A'])) == Dict('a' => 1)
end

@testset "single score with multiple letters" begin
input = Dict(1=>['A', 'E', 'I', 'O', 'U'])
output = Dict('a'=>1, 'e'=>1, 'i'=>1, 'o'=>1, 'u'=>1)
@test transform(input) == output
@test transform(Dict(1 => ['A', 'E', 'I', 'O', 'U'])) ==
Dict('a' => 1, 'e' => 1, 'i' => 1, 'o' => 1, 'u' => 1)
end

@testset "multiple scores with multiple letters" begin
input = Dict(1=>['A', 'E'], 2=>['D', 'G'])
output = Dict('g'=>2, 'e'=>1, 'a'=>1, 'd'=>2)
@test transform(input) == output
@test transform(Dict(1 => ['A', 'E'], 2 => ['D', 'G'])) ==
Dict('a' => 1, 'd' => 2, 'e' => 1, 'g' => 2)
end

@testset "multiple scores with differing numbers of letters" begin
input = Dict(1=>[ 'A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T' ],
2=>[ 'D', 'G' ], 3=>[ 'B', 'C', 'M', 'P' ],
4=>[ 'F', 'H', 'V', 'W', 'Y' ], 5=>[ 'K' ],
8=>[ 'J', 'X' ], 10=>[ 'Q', 'Z' ])
output = Dict('a'=>1, 'b'=>3, 'c'=>3, 'd'=>2, 'e'=>1,
'f'=>4, 'g'=>2, 'h'=>4, 'i'=>1, 'j'=>8,
'k'=>5, 'l'=>1, 'm'=>3, 'n'=>1, 'o'=>1,
'p'=>3, 'q'=>10, 'r'=>1, 's'=>1, 't'=>1,
'u'=>1, 'v'=>4, 'w'=>4, 'x'=>8, 'y'=>4,
'z'=>10)
@test transform(input) == output
@test transform(Dict(1 => ['A', 'E', 'I', 'O', 'U', 'L', 'N', 'R', 'S', 'T'],
2 => ['D', 'G'], 3 => ['B', 'C', 'M', 'P'],
4 => ['F', 'H', 'V', 'W', 'Y'], 5 => ['K'], 8 => ['J', 'X'],
10 => ['Q', 'Z'])) ==
Dict('a' => 1, 'b' => 3, 'c' => 3, 'd' => 2, 'e' => 1, 'f' => 4, 'g' => 2,
'h' => 4, 'i' => 1, 'j' => 8, 'k' => 5, 'l' => 1, 'm' => 3, 'n' => 1,
'o' => 1, 'p' => 3, 'q' => 10, 'r' => 1, 's' => 1, 't' => 1, 'u' => 1,
'v' => 4, 'w' => 4, 'x' => 8, 'y' => 4, 'z' => 10)
end
end
10 changes: 10 additions & 0 deletions exercises/practice/food-chain/.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 recite({{ case["input"]["startVerse"] }}, {{ case["input"]["endVerse"] }}) == {{ macros.julia_vector(case["expected"]) }}
end
{% endfor %}
end
Loading
Loading