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
22 changes: 11 additions & 11 deletions exercises/practice/rail-fence-cipher/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
{{ header }}
{% for case in cases %}
@test "{{ case["description"] }}" {
{{ case.test_function_start }}
{% if loop.first %}# {% endif %}[[ $BATS_RUN_SKIPPED == "true" ]] || skip
{%- if case["property"] == "encode" %}
run bash {{ solution }} -e {{ case["input"]["rails"] }} "{{ case["input"]["msg"] }}"
{%- if case.property == "encode" %}
run bash {{ solution }} -e {{ case.input.rails }} "{{ case.input.msg }}"
{%- else %}
run bash {{ solution }} -d {{ case["input"]["rails"] }} "{{ case["input"]["msg"] }}"
run bash {{ solution }} -d {{ case.input.rails }} "{{ case.input.msg }}"
{%- endif %}
assert_success
assert_output "{{ case["expected"] }}"
assert_output "{{ case.expected }}"
}
{% endfor %}
# Track specific tests

@test "encode with more rails than text" {
test_encode_with_more_rails_than_text () { #@test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash rail_fence_cipher.sh -e 10 "hello"
assert_success
assert_output "hello"
}

@test "decode with more rails than text" {
test_decode_with_more_rails_than_text () { #@test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash rail_fence_cipher.sh -d 10 "hello"
assert_success
assert_output "hello"
}

@test "decode the encoded text yields the original" {
test_decode_the_encoded_text_yields_the_original () { #@test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
plaintext="the quick brown fox jumped over the lazy dogs"
rails=5
Expand All @@ -41,21 +41,21 @@

# Invocation errors

@test "no options" {
test_no_options () { #@test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash rail_fence_cipher.sh
assert_failure
assert_output # there is _some_ output
}

@test "zero rails" {
test_zero_rails () { #@test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash rail_fence_cipher.sh -e 0 abc
assert_failure
assert_output # there is _some_ output
}

@test "negative rails" {
test_negative_rails () { #@test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash rail_fence_cipher.sh -d -2 abc
assert_failure
Expand Down
26 changes: 13 additions & 13 deletions exercises/practice/rail-fence-cipher/rail_fence_cipher.bats
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
#!/usr/bin/env bats
load bats-extra

# generated on 2026-06-29T16:53:24+00:00
# generated on 2026-11-08T06:49:56+00:00

@test "encode with two rails" {
test_encode_encode_with_two_rails() { # @test
# [[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash rail_fence_cipher.sh -e 2 "XOXOXOXOXOXOXOXOXO"
assert_success
assert_output "XXXXXXXXXOOOOOOOOO"
}

@test "encode with three rails" {
test_encode_encode_with_three_rails() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash rail_fence_cipher.sh -e 3 "WEAREDISCOVEREDFLEEATONCE"
assert_success
assert_output "WECRLTEERDSOEEFEAOCAIVDEN"
}

@test "encode with ending in the middle" {
test_encode_encode_with_ending_in_the_middle() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash rail_fence_cipher.sh -e 4 "EXERCISES"
assert_success
assert_output "ESXIEECSR"
}

@test "decode with three rails" {
test_decode_decode_with_three_rails() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash rail_fence_cipher.sh -d 3 "TEITELHDVLSNHDTISEIIEA"
assert_success
assert_output "THEDEVILISINTHEDETAILS"
}

@test "decode with five rails" {
test_decode_decode_with_five_rails() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash rail_fence_cipher.sh -d 5 "EIEXMSMESAORIWSCE"
assert_success
assert_output "EXERCISMISAWESOME"
}

@test "decode with six rails" {
test_decode_decode_with_six_rails() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash rail_fence_cipher.sh -d 6 "133714114238148966225439541018335470986172518171757571896261"
assert_success
Expand All @@ -47,21 +47,21 @@ load bats-extra

# Track specific tests

@test "encode with more rails than text" {
test_encode_with_more_rails_than_text () { #@test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash rail_fence_cipher.sh -e 10 "hello"
assert_success
assert_output "hello"
}

@test "decode with more rails than text" {
test_decode_with_more_rails_than_text () { #@test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash rail_fence_cipher.sh -d 10 "hello"
assert_success
assert_output "hello"
}

@test "decode the encoded text yields the original" {
test_decode_the_encoded_text_yields_the_original () { #@test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
plaintext="the quick brown fox jumped over the lazy dogs"
rails=5
Expand All @@ -75,21 +75,21 @@ load bats-extra

# Invocation errors

@test "no options" {
test_no_options () { #@test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash rail_fence_cipher.sh
assert_failure
assert_output # there is _some_ output
}

@test "zero rails" {
test_zero_rails () { #@test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash rail_fence_cipher.sh -e 0 abc
assert_failure
assert_output # there is _some_ output
}

@test "negative rails" {
test_negative_rails () { #@test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash rail_fence_cipher.sh -d -2 abc
assert_failure
Expand Down
6 changes: 3 additions & 3 deletions exercises/practice/raindrops/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{ 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"] }}
run bash {{ solution }} {{ case.given }}
assert_success
assert_output "{{ case["expected"] }}"
assert_output "{{ case.expected }}"
}
{% endfor %}
39 changes: 19 additions & 20 deletions exercises/practice/raindrops/raindrops.bats
Original file line number Diff line number Diff line change
@@ -1,131 +1,130 @@
#!/usr/bin/env bats
load bats-extra

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

@test "the sound for 1 is 1" {
test_the_sound_for_1_is_1() { # @test
# [[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash raindrops.sh 1
assert_success
assert_output "1"
}

@test "the sound for 3 is Pling" {
test_the_sound_for_3_is_pling() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash raindrops.sh 3
assert_success
assert_output "Pling"
}

@test "the sound for 5 is Plang" {
test_the_sound_for_5_is_plang() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash raindrops.sh 5
assert_success
assert_output "Plang"
}

@test "the sound for 7 is Plong" {
test_the_sound_for_7_is_plong() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash raindrops.sh 7
assert_success
assert_output "Plong"
}

@test "the sound for 6 is Pling as it has a factor 3" {
test_the_sound_for_6_is_pling_as_it_has_a_factor_3() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash raindrops.sh 6
assert_success
assert_output "Pling"
}

@test "2 to the power 3 does not make a raindrop sound as 3 is the exponent not the base" {
test_2_to_the_power_3_does_not_make_a_raindrop_sound_as_3_is_the_exponent_not_the_base() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash raindrops.sh 8
assert_success
assert_output "8"
}

@test "the sound for 9 is Pling as it has a factor 3" {
test_the_sound_for_9_is_pling_as_it_has_a_factor_3() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash raindrops.sh 9
assert_success
assert_output "Pling"
}

@test "the sound for 10 is Plang as it has a factor 5" {
test_the_sound_for_10_is_plang_as_it_has_a_factor_5() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash raindrops.sh 10
assert_success
assert_output "Plang"
}

@test "the sound for 14 is Plong as it has a factor of 7" {
test_the_sound_for_14_is_plong_as_it_has_a_factor_of_7() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash raindrops.sh 14
assert_success
assert_output "Plong"
}

@test "the sound for 15 is PlingPlang as it has factors 3 and 5" {
test_the_sound_for_15_is_plingplang_as_it_has_factors_3_and_5() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash raindrops.sh 15
assert_success
assert_output "PlingPlang"
}

@test "the sound for 21 is PlingPlong as it has factors 3 and 7" {
test_the_sound_for_21_is_plingplong_as_it_has_factors_3_and_7() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash raindrops.sh 21
assert_success
assert_output "PlingPlong"
}

@test "the sound for 25 is Plang as it has a factor 5" {
test_the_sound_for_25_is_plang_as_it_has_a_factor_5() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash raindrops.sh 25
assert_success
assert_output "Plang"
}

@test "the sound for 27 is Pling as it has a factor 3" {
test_the_sound_for_27_is_pling_as_it_has_a_factor_3() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash raindrops.sh 27
assert_success
assert_output "Pling"
}

@test "the sound for 35 is PlangPlong as it has factors 5 and 7" {
test_the_sound_for_35_is_plangplong_as_it_has_factors_5_and_7() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash raindrops.sh 35
assert_success
assert_output "PlangPlong"
}

@test "the sound for 49 is Plong as it has a factor 7" {
test_the_sound_for_49_is_plong_as_it_has_a_factor_7() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash raindrops.sh 49
assert_success
assert_output "Plong"
}

@test "the sound for 52 is 52" {
test_the_sound_for_52_is_52() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash raindrops.sh 52
assert_success
assert_output "52"
}

@test "the sound for 105 is PlingPlangPlong as it has factors 3, 5 and 7" {
test_the_sound_for_105_is_plingplangplong_as_it_has_factors_3_5_and_7() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash raindrops.sh 105
assert_success
assert_output "PlingPlangPlong"
}

@test "the sound for 3125 is Plang as it has a factor 5" {
test_the_sound_for_3125_is_plang_as_it_has_a_factor_5() { # @test
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash raindrops.sh 3125
assert_success
assert_output "Plang"
}

30 changes: 15 additions & 15 deletions exercises/practice/rational-numbers/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
{{ header }}
{% for case in cases %}
@test "{{ case["description"] }}" {
{{ case.test_function_start }}
{% if loop.first %}# {% endif %}[[ $BATS_RUN_SKIPPED == "true" ]] || skip
{%- if case["property"] in ["add", "sub", "mul", "div"] %}
{%- set op = {"add": "+", "sub": "-", "mul": "*", "div": "/"}[case["property"]] %}
{%- set args = [op, case["input"]["r1"] | join("/"), case["input"]["r2"] | join("/")] %}
{%- elif case["property"] == "abs" %}
{%- set args = ["abs", case["input"]["r"] | join("/")] %}
{%- elif case["property"] == "exprational" %}
{%- set args = ["pow", case["input"]["r"] | join("/"), case["input"]["n"]] %}
{%- elif case["property"] == "expreal" %}
{%- set args = ["rpow", case["input"]["x"], case["input"]["r"] | join("/")] %}
{%- elif case["property"] == "reduce" %}
{%- set args = ["reduce", case["input"]["r"] | join("/")] %}
{%- if case.property in ["add", "sub", "mul", "div"] %}
{%- set op = {"add": "+", "sub": "-", "mul": "*", "div": "/"}[case.property] %}
{%- set args = [op, case.input.r1 | join("/"), case.input.r2 | join("/")] %}
{%- elif case.property == "abs" %}
{%- set args = ["abs", case.input.r | join("/")] %}
{%- elif case.property == "exprational" %}
{%- set args = ["pow", case.input.r | join("/"), case.input.n] %}
{%- elif case.property == "expreal" %}
{%- set args = ["rpow", case.input.x, case.input.r | join("/")] %}
{%- elif case.property == "reduce" %}
{%- set args = ["reduce", case.input.r | join("/")] %}
{%- endif %}
run bash {{ solution }} "{{ args | join('" "') }}"
assert_success

{%- if case["property"] == "expreal" %}
assert_output "{{ case["expected"] | string | truncate(8, True, "") }}"
{%- if case.property == "expreal" %}
assert_output "{{ case.expected | string | truncate(8, True, "") }}"
{%- else %}
assert_output "{{ case["expected"] | join("/") }}"
assert_output "{{ case.expected | join("/") }}"
{%- endif %}
}
{% endfor %}
Loading
Loading