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
10 changes: 5 additions & 5 deletions exercises/practice/satellite/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{{ header }}
{% for case in cases %}
@test "{{ case["description"] }}" {
{{ case.test_function_start }}
{% if loop.first %}# {% endif %}[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash {{ solution }} "{{ case["input"]["preorder"] | join(" ") }}" "{{ case["input"]["inorder"] | join(" ") }}"
{%- if case["expect_error"] %}
run bash {{ solution }} "{{ case.input.preorder | join(" ") }}" "{{ case.input.inorder | join(" ") }}"
{%- if case.expect_error %}
assert_failure
shopt -s nocasematch
assert_output "{{ case["expect_error_msg"] }}"
assert_output "{{ case.expect_error_msg }}"
{%- else %}
assert_success
expectedJson=$(cat << END_JSON
{{ case["expected"] | tojson(separators=None, indent=4) | indent(4, first=True) }}
{{ case.expected | tojson(separators=None, indent=4) | indent(4, first=True) }}
END_JSON
)
# compare without spaces
Expand Down
21 changes: 10 additions & 11 deletions exercises/practice/satellite/satellite.bats
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bats
load bats-extra

# generated on 2026-08-14T05:27:25+00:00
# generated on 2026-11-08T06:49:56+00:00

@test "Empty tree" {
test_empty_tree() { # @test
# [[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash satellite.sh "" ""
assert_success
Expand All @@ -15,7 +15,7 @@ END_JSON
[[ "${output//[[:space:]]/}" == "${expectedJson//[[:space:]]/}" ]]
}

@test "Tree with one item" {
test_tree_with_one_item() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash satellite.sh "a" "a"
assert_success
Expand All @@ -31,7 +31,7 @@ END_JSON
[[ "${output//[[:space:]]/}" == "${expectedJson//[[:space:]]/}" ]]
}

@test "Tree with many items" {
test_tree_with_many_items() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash satellite.sh "a i x f r" "i a f x r"
assert_success
Expand Down Expand Up @@ -63,31 +63,31 @@ END_JSON
[[ "${output//[[:space:]]/}" == "${expectedJson//[[:space:]]/}" ]]
}

@test "Reject traversals of different length" {
test_reject_traversals_of_different_length() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash satellite.sh "a b" "b a r"
assert_failure
shopt -s nocasematch
assert_output "traversals must have the same length"
}

@test "Reject inconsistent traversals of same length" {
test_reject_inconsistent_traversals_of_same_length() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash satellite.sh "x y z" "a b c"
assert_failure
shopt -s nocasematch
assert_output "traversals must have the same elements"
}

@test "Reject traversals with repeated items" {
test_reject_traversals_with_repeated_items() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash satellite.sh "a b a" "b a a"
assert_failure
shopt -s nocasematch
assert_output "traversals must contain unique items"
}

@test "A degenerate binary tree" {
test_a_degenerate_binary_tree() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash satellite.sh "a b c d" "d c b a"
assert_success
Expand Down Expand Up @@ -115,7 +115,7 @@ END_JSON
[[ "${output//[[:space:]]/}" == "${expectedJson//[[:space:]]/}" ]]
}

@test "Another degenerate binary tree" {
test_another_degenerate_binary_tree() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash satellite.sh "a b c d" "a b c d"
assert_success
Expand Down Expand Up @@ -143,7 +143,7 @@ END_JSON
[[ "${output//[[:space:]]/}" == "${expectedJson//[[:space:]]/}" ]]
}

@test "Tree with many more items" {
test_tree_with_many_more_items() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash satellite.sh "a b d g h c e f i" "g d h b a e c i f"
assert_success
Expand Down Expand Up @@ -190,4 +190,3 @@ END_JSON
# compare without spaces
[[ "${output//[[:space:]]/}" == "${expectedJson//[[:space:]]/}" ]]
}

14 changes: 7 additions & 7 deletions exercises/practice/save-the-cow/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{{ header }}
{% for case in cases %}
@test "{{ case["descriptions"] | join(": ") }}" {
{{ case.test_function_start }}
{% if loop.first %}# {% endif %}[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash {{ solution }} "{{ case["input"]["word"] }}" "{{ case["input"]["guesses"] | join('" "') }}"
{%- if case["expect_error"] %}
run bash {{ solution }} "{{ case.input.word }}" "{{ case.input.guesses | join('" "') }}"
{%- if case.expect_error %}
assert_failure
assert_output "{{ case["expect_error_msg"] }}"
assert_output "{{ case.expect_error_msg }}"
{%- else %}
expected="$(cat << EXPECTED
State: {{ case["expected"]["state"] }}
Masked word: {{ case["expected"]["maskedWord"] }}
Remaining failures: {{ case["expected"]["remainingFailures"] }}
State: {{ case.expected.state }}
Masked word: {{ case.expected.maskedWord }}
Remaining failures: {{ case.expected.remainingFailures }}
EXPECTED
)"

Expand Down
23 changes: 11 additions & 12 deletions exercises/practice/save-the-cow/save_the_cow.bats
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env bats
load bats-extra

# generated on 2026-09-13T19:12:55+00:00
# generated on 2026-11-08T06:49:56+00:00

@test "Initially 9 failures are allowed and no letters are guessed" {
test_initially_9_failures_are_allowed_and_no_letters_are_guessed() { # @test
# [[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash save_the_cow.sh "loot" ""
expected="$(cat << EXPECTED
Expand All @@ -17,7 +17,7 @@ EXPECTED
assert_output "$expected"
}

@test "After 10 failures the game is over" {
test_after_10_failures_the_game_is_over() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash save_the_cow.sh "loot" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
expected="$(cat << EXPECTED
Expand All @@ -31,7 +31,7 @@ EXPECTED
assert_output "$expected"
}

@test "Losing with several correct guesses" {
test_losing_with_several_correct_guesses() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash save_the_cow.sh "loot" "t" "o" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j"
expected="$(cat << EXPECTED
Expand All @@ -45,7 +45,7 @@ EXPECTED
assert_output "$expected"
}

@test "Feeding a correct letter removes underscores" {
test_feeding_a_correct_letter_removes_underscores() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash save_the_cow.sh "loot" "t"
expected="$(cat << EXPECTED
Expand All @@ -59,7 +59,7 @@ EXPECTED
assert_output "$expected"
}

@test "Feeding a correct letter twice counts as a failure" {
test_feeding_a_correct_letter_twice_counts_as_a_failure() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash save_the_cow.sh "loot" "t" "t"
expected="$(cat << EXPECTED
Expand All @@ -73,7 +73,7 @@ EXPECTED
assert_output "$expected"
}

@test "Guessing a repeated letter reveals all instances" {
test_guessing_a_repeated_letter_reveals_all_instances() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash save_the_cow.sh "loot" "t" "t" "o"
expected="$(cat << EXPECTED
Expand All @@ -87,7 +87,7 @@ EXPECTED
assert_output "$expected"
}

@test "Getting all the letters right makes for a win" {
test_getting_all_the_letters_right_makes_for_a_win() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash save_the_cow.sh "loot" "t" "t" "o" "l"
expected="$(cat << EXPECTED
Expand All @@ -101,7 +101,7 @@ EXPECTED
assert_output "$expected"
}

@test "Winning on the last guess is still a win" {
test_winning_on_the_last_guess_is_still_a_win() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash save_the_cow.sh "loot" "a" "b" "c" "d" "e" "f" "g" "h" "i" "t" "o" "l"
expected="$(cat << EXPECTED
Expand All @@ -115,17 +115,16 @@ EXPECTED
assert_output "$expected"
}

@test "Guessing after a lose is error" {
test_guessing_after_a_lose_is_error() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash save_the_cow.sh "loot" "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" "k"
assert_failure
assert_output "cannot guess after the game is lost"
}

@test "Guessing after a win is error" {
test_guessing_after_a_win_is_error() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash save_the_cow.sh "loot" "t" "o" "l" "l"
assert_failure
assert_output "cannot guess after the game is won"
}

10 changes: 5 additions & 5 deletions exercises/practice/say/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{{ header }}
{% for case in cases %}
@test "{{ case["description"] }}" {
{{ case.test_function_start }}
{% if loop.first %}# {% endif %}[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash {{ solution }} {{ case["input"]["number"] }}
{%- if case["expect_error"] %}
run bash {{ solution }} {{ case.given }}
{%- if case.expect_error %}
assert_failure
assert_output "{{ case["expect_error_msg"] }}"
assert_output "{{ case.expect_error_msg }}"
{%- else %}
assert_success
assert_output "{{ case["expected"] }}"
assert_output "{{ case.expected }}"
{%- endif %}
}
{% endfor %}
Loading
Loading