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
2 changes: 1 addition & 1 deletion bin/add-exercise
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ import {{ exercise | to_pascal }} exposing [{{ cases[0]["property"] | to_snake }
{% for case in cases -%}
# {{ case["description"] }}
expect
result = {{ case["property"] | to_snake }} {{ case["input"]["myArg"] | to_roc }}
result = {{ case["property"] | to_snake }}({{ case["input"]["myArg"] | to_roc }})
result == {{ case["expected"] | to_roc }}

{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion config/generator_macros.j2
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ app [main!] {
import pf.Stdout

main! = |_args|
Stdout.line! ""
Stdout.line!("")

{%- endmacro %}

26 changes: 14 additions & 12 deletions exercises/practice/accumulate/.meta/template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,36 @@
import {{ exercise | to_pascal }} exposing [{{ cases[0]["property"] | to_snake }}]

{% set accumulators = {
"(x) => x * x": "\\x ->\n x * x",
"(x) => x * x": "|x|\n x * x",
"(x) => upcase(x)": "to_upper",
"(x) => reverse(x)": "reverse",
"(x) => accumulate([\"1\", \"2\", \"3\"], (y) => x + y)": "\\x ->\n accumulate [\"1\", \"2\", \"3\"] (\\y -> Str.concat x y)"
"(x) => accumulate([\"1\", \"2\", \"3\"], (y) => x + y)": "|x|\n accumulate([\"1\", \"2\", \"3\"], |y| Str.concat(x, y))"
} -%}

{% for case in cases -%}
# {{ case["description"] }}
expect
result = {{ case["property"] | to_snake }} {{ case["input"]["list"] | to_roc }} {{ accumulators[case["input"]["accumulator"]] }}
result = {{ case["property"] | to_snake }}({{ case["input"]["list"] | to_roc }}, {{ accumulators[case["input"]["accumulator"]] }})
result == {{ case["expected"] | to_roc }}

{% endfor %}

reverse : Str -> Str
reverse = |str|
Str.to_utf8 str
Str.to_utf8(str)
|> List.reverse
|> Str.from_utf8
|> Result.with_default ""
|> Result.with_default("")

to_upper : Str -> Str
to_upper = |str|
Str.to_utf8 str
|> List.map |byte|
if 'a' <= byte && byte <= 'z' then
byte - 'a' + 'A'
else
byte
Str.to_utf8(str)
|> List.map(
|byte|
if 'a' <= byte && byte <= 'z' then
byte - 'a' + 'A'
else
byte
)
|> Str.from_utf8
|> Result.with_default ""
|> Result.with_default("")
2 changes: 1 addition & 1 deletion exercises/practice/accumulate/accumulate-test.roc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/accumulate/canonical-data.json
# File last updated on 2025-01-04
# File last updated on 2025-07-26
app [main!] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br",
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/acronym/.meta/template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {{ exercise | to_pascal }} exposing [abbreviate]
{% for case in cases -%}
# {{ case["description"] }}
expect
result = {{ case["property"] | to_snake }} {{ case["input"]["phrase"] | to_roc }}
result = {{ case["property"] | to_snake }}({{ case["input"]["phrase"] | to_roc }})
result == {{ case["expected"] | to_roc }}

{% endfor %}
2 changes: 1 addition & 1 deletion exercises/practice/acronym/acronym-test.roc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/acronym/canonical-data.json
# File last updated on 2025-01-04
# File last updated on 2025-07-26
app [main!] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br",
}
Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/affine-cipher/.meta/template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import {{ exercise | to_pascal }} exposing [encode, decode]
expect
phrase = {{ case["input"]["phrase"] | to_roc }}
key = {a: {{ case["input"]["key"]["a"] }}, b: {{ case["input"]["key"]["b"] }}}
result = {{ case["property"] | to_snake }} phrase key
result = {{ case["property"] | to_snake }}(phrase, key)
{%- if case["expected"]["error"] %}
result |> Result.is_err
{%- else %}
expected = Ok {{ case["expected"] | to_roc }}
expected = Ok({{ case["expected"] | to_roc }})
result == expected
{%- endif %}

Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/affine-cipher/affine-cipher-test.roc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/affine-cipher/canonical-data.json
# File last updated on 2025-01-04
# File last updated on 2025-07-26
app [main!] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br",
}
Expand Down
4 changes: 2 additions & 2 deletions exercises/practice/all-your-base/.meta/template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {{ exercise | to_pascal }} exposing [{{ cases[0]["property"] | to_snake }
{% for case in cases -%}
# {{ case["description"] }}
expect
result = {{ case["property"] | to_snake }} { input_base: {{ case["input"]["inputBase"] | to_roc }}, output_base: {{ case["input"]["outputBase"] | to_roc }}, digits: {{ case["input"]["digits"] | to_roc }} }
result = {{ case["property"] | to_snake }}({ input_base: {{ case["input"]["inputBase"] | to_roc }}, output_base: {{ case["input"]["outputBase"] | to_roc }}, digits: {{ case["input"]["digits"] | to_roc }} })
{%- if case["expected"]["error"] %}
result |> Result.is_err
{%- else %}
result == Ok {{ case["expected"] }}
result == Ok({{ case["expected"] }})
{%- endif %}

{% endfor %}
2 changes: 1 addition & 1 deletion exercises/practice/all-your-base/all-your-base-test.roc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/all-your-base/canonical-data.json
# File last updated on 2025-01-04
# File last updated on 2025-07-26
app [main!] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br",
}
Expand Down
6 changes: 3 additions & 3 deletions exercises/practice/allergies/.meta/template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {{ exercise | to_pascal }} exposing [allergic_to, set]
# {{ outerCase["description"] }} {{ case["description"] | default('') }}
expect
{%- if case["property"] == "allergicTo" %}
result = allergic_to {{ case["input"]["item"] | to_pascal }} {{ case["input"]["score"] | to_roc }}
result = allergic_to({{ case["input"]["item"] | to_pascal }}, {{ case["input"]["score"] | to_roc }})
result == {{ case["expected"] | to_roc }}
{%- else %}
result = set {{ case["input"]["score"] }}
result == Set.from_list [{{ case["expected"] | map('to_pascal') | join(", ") }}]
result = set({{ case["input"]["score"] }})
result == Set.from_list([{{ case["expected"] | map('to_pascal') | join(", ") }}])
{%- endif %}

{% endfor %}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/allergies/allergies-test.roc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/allergies/canonical-data.json
# File last updated on 2025-01-04
# File last updated on 2025-07-26
app [main!] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br",
}
Expand Down
8 changes: 4 additions & 4 deletions exercises/practice/alphametics/.meta/template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import {{ exercise | to_pascal }} exposing [{{ cases[0]["property"] | to_snake }
{% for case in cases -%}
# {{ case["description"] }}
expect
result = {{ case["property"] | to_snake }} {{ case["input"]["puzzle"] | to_roc }}
result = {{ case["property"] | to_snake }}({{ case["input"]["puzzle"] | to_roc }})
{%- if case["expected"] %}
Result.with_default result [] |> Set.from_list == Set.from_list [
Result.with_default(result, []) |> Set.from_list == Set.from_list([
{%- for letter, value in case["expected"].items() %}
('{{ letter }}', {{ value }}),
{%- endfor %}
]
])
{%- else %}
Result.is_err result
Result.is_err(result)
{%- endif %}

{% endfor %}
2 changes: 1 addition & 1 deletion exercises/practice/alphametics/alphametics-test.roc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/alphametics/canonical-data.json
# File last updated on 2025-01-04
# File last updated on 2025-07-26
app [main!] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br",
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/anagram/.meta/template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {{ exercise | to_pascal }} exposing [{{ cases[0]["property"] | to_snake }
{% for case in cases -%}
# {{ case["description"] }}
expect
result = {{ case["property"] | to_snake }} {{ case["input"]["subject"] | to_roc }} {{ case["input"]["candidates"] | to_roc }}
result = {{ case["property"] | to_snake }}({{ case["input"]["subject"] | to_roc }}, {{ case["input"]["candidates"] | to_roc }})
result == {{ case["expected"] | to_roc }}

{% endfor %}
2 changes: 1 addition & 1 deletion exercises/practice/anagram/anagram-test.roc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/anagram/canonical-data.json
# File last updated on 2025-01-04
# File last updated on 2025-07-26
app [main!] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br",
unicode: "https://github.com/roc-lang/unicode/releases/download/0.3.0/9KKFsA4CdOz0JIOL7iBSI_2jGIXQ6TsFBXgd086idpY.tar.br",
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/armstrong-numbers/.meta/template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {{ exercise | to_pascal }} exposing [is_armstrong_number]
{% for case in cases -%}
# {{ case["description"] }}
expect
result = {{ case["property"] | to_snake }} {{ case["input"]["number"] }}
result = {{ case["property"] | to_snake }}({{ case["input"]["number"] }})
result == {{ case["expected"] | to_roc }}

{% endfor %}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/armstrong-numbers/canonical-data.json
# File last updated on 2025-01-04
# File last updated on 2025-07-26
app [main!] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br",
}
Expand Down
2 changes: 1 addition & 1 deletion exercises/practice/atbash-cipher/.meta/template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ expect
phrase = {{ case["input"]["phrase"] | to_roc }}
result = phrase |> {{ case["property"] | to_snake }}
expected = {{ case["expected"] | to_roc }}
result == Ok expected
result == Ok(expected)

{% endfor %}
{% endfor %}
2 changes: 1 addition & 1 deletion exercises/practice/atbash-cipher/atbash-cipher-test.roc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/atbash-cipher/canonical-data.json
# File last updated on 2025-01-04
# File last updated on 2025-07-26
app [main!] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br",
}
Expand Down
10 changes: 5 additions & 5 deletions exercises/practice/binary-search-tree/.meta/template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import {{ exercise | to_pascal }} exposing [from_list, to_list]
{%- endmacro %}

{% macro to_tree(tree) -%}
{% if tree is none %}Nil{% else %}Node {
{% if tree is none %}Nil{% else %}Node({
value: {{ tree["data"] }},
left: {{ to_tree(tree["left"]) }},
right: {{ to_tree(tree["right"]) }},
}{% endif %}
}){% endif %}
{%- endmacro %}

{% for supercase in cases %}
Expand All @@ -33,12 +33,12 @@ import {{ exercise | to_pascal }} exposing [from_list, to_list]
expect
data = {{ to_int_list(subcase["input"]["treeData"]) }}
{%- if subcase["property"] == "data" %}
result = data |> from_list
result = from_list(data)
expected = {{ to_tree(subcase["expected"]) }}
result == expected
{%- else %}
tree = data |> from_list
result = tree |> to_list
tree = from_list(data)
result = to_list(tree)
expected = {{ to_int_list(subcase["expected"]) }}
result == expected
{%- endif %}
Expand Down
32 changes: 16 additions & 16 deletions exercises/practice/binary-search-tree/binary-search-tree-test.roc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/binary-search-tree/canonical-data.json
# File last updated on 2025-01-04
# File last updated on 2025-07-26
app [main!] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br",
}
Expand All @@ -18,7 +18,7 @@ import BinarySearchTree exposing [from_list, to_list]

expect
data = [4]
result = data |> from_list
result = from_list(data)
expected = Node(
{
value: 4,
Expand All @@ -35,7 +35,7 @@ expect
# smaller number at left node
expect
data = [4, 2]
result = data |> from_list
result = from_list(data)
expected = Node(
{
value: 4,
Expand All @@ -54,7 +54,7 @@ expect
# same number at left node
expect
data = [4, 4]
result = data |> from_list
result = from_list(data)
expected = Node(
{
value: 4,
Expand All @@ -73,7 +73,7 @@ expect
# greater number at right node
expect
data = [4, 5]
result = data |> from_list
result = from_list(data)
expected = Node(
{
value: 4,
Expand All @@ -95,7 +95,7 @@ expect

expect
data = [4, 2, 6, 1, 3, 5, 7]
result = data |> from_list
result = from_list(data)
expected = Node(
{
value: 4,
Expand Down Expand Up @@ -148,40 +148,40 @@ expect
# can sort single number
expect
data = [2]
tree = data |> from_list
result = tree |> to_list
tree = from_list(data)
result = to_list(tree)
expected = [2]
result == expected

# can sort if second number is smaller than first
expect
data = [2, 1]
tree = data |> from_list
result = tree |> to_list
tree = from_list(data)
result = to_list(tree)
expected = [1, 2]
result == expected

# can sort if second number is same as first
expect
data = [2, 2]
tree = data |> from_list
result = tree |> to_list
tree = from_list(data)
result = to_list(tree)
expected = [2, 2]
result == expected

# can sort if second number is greater than first
expect
data = [2, 3]
tree = data |> from_list
result = tree |> to_list
tree = from_list(data)
result = to_list(tree)
expected = [2, 3]
result == expected

# can sort complex tree
expect
data = [2, 1, 3, 6, 7, 5]
tree = data |> from_list
result = tree |> to_list
tree = from_list(data)
result = to_list(tree)
expected = [1, 2, 3, 5, 6, 7]
result == expected

6 changes: 3 additions & 3 deletions exercises/practice/binary-search/.meta/template.j2
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ import {{ exercise | to_pascal }} exposing [{{ cases[0]["property"] | to_snake }
{% for case in cases -%}
# {{ case["description"] }}
expect
result = {{ case["input"]["array"] | to_roc }} |> {{ case["property"] | to_snake }} {{ case["input"]["value"] }}
result = {{ case["input"]["array"] | to_roc }} |> {{ case["property"] | to_snake }}({{ case["input"]["value"] }})
{%- if case["expected"]["error"] %}
Result.is_err result
Result.is_err(result)
{%- else %}
result == Ok {{ case["expected"] }}
result == Ok({{ case["expected"] }})
{%- endif %}

{% endfor %}
2 changes: 1 addition & 1 deletion exercises/practice/binary-search/binary-search-test.roc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# These tests are auto-generated with test data from:
# https://github.com/exercism/problem-specifications/tree/main/exercises/binary-search/canonical-data.json
# File last updated on 2025-01-04
# File last updated on 2025-07-26
app [main!] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/Hj-J_zxz7V9YurCSTFcFdu6cQJie4guzsPMUi5kBYUk.tar.br",
}
Expand Down
Loading