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
17 changes: 17 additions & 0 deletions exercises/practice/run-length-encoding/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{{ header }}
{% for idx, case in cases %}
@test "{{ case["descriptions"] | join(": ") }}" {
{% if idx == 0 %}# {% endif %}[[ $BATS_RUN_SKIPPED == "true" ]] || skip
expected="{{ case["expected"] }}"
{%- if case["property"] == "consistency" %}
run bash run_length_encoding.sh encode "{{ case["input"]["string"] }}"
assert_success
encoded=$output
run bash run_length_encoding.sh decode "$encoded"
{%- else %}
run bash {{ solution }} {{ case["property"] }} "{{ case["input"]["string"] }}"
{%- endif %}
assert_success
assert_output "$expected"
}
{% endfor %}
37 changes: 16 additions & 21 deletions exercises/practice/run-length-encoding/run_length_encoding.bats
Original file line number Diff line number Diff line change
@@ -1,111 +1,106 @@
#!/usr/bin/env bats
load bats-extra

# local version: 1.1.0.0
# generated on 2026-06-29T06:30:35+00:00
# local version: 2.0.0.0

# run-length encode a string

@test "encode empty string" {
#[[ $BATS_RUN_SKIPPED == "true" ]] || skip
@test "run-length encode a string: empty string" {
# [[ $BATS_RUN_SKIPPED == "true" ]] || skip
expected=""
run bash run_length_encoding.sh encode ""
assert_success
assert_output "$expected"
}

@test "encode single characters only are encoded without count" {
@test "run-length encode a string: single characters only are encoded without count" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
expected="XYZ"
run bash run_length_encoding.sh encode "XYZ"
assert_success
assert_output "$expected"
}

@test "encode string with no single characters" {
@test "run-length encode a string: string with no single characters" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
expected="2A3B4C"
run bash run_length_encoding.sh encode "AABBBCCCC"
assert_success
assert_output "$expected"
}

@test "encode single characters mixed with repeated characters" {
@test "run-length encode a string: single characters mixed with repeated characters" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
expected="12WB12W3B24WB"
run bash run_length_encoding.sh encode "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB"
assert_success
assert_output "$expected"
}

@test "encode multiple whitespace mixed in string" {
@test "run-length encode a string: multiple whitespace mixed in string" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
expected="2 hs2q q2w2 "
run bash run_length_encoding.sh encode " hsqq qww "
assert_success
assert_output "$expected"
}

@test "encode lowercase characters" {
@test "run-length encode a string: lowercase characters" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
expected="2a3b4c"
run bash run_length_encoding.sh encode "aabbbcccc"
assert_success
assert_output "$expected"
}

# run-length decode a string

@test "decode empty string" {
@test "run-length decode a string: empty string" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
expected=""
run bash run_length_encoding.sh decode ""
assert_success
assert_output "$expected"
}

@test "single characters only" {
@test "run-length decode a string: single characters only" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
expected="XYZ"
run bash run_length_encoding.sh decode "XYZ"
assert_success
assert_output "$expected"
}

@test "decode string with no single characters" {
@test "run-length decode a string: string with no single characters" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
expected="AABBBCCCC"
run bash run_length_encoding.sh decode "2A3B4C"
assert_success
assert_output "$expected"
}

@test "decode single characters with repeated characters" {
@test "run-length decode a string: single characters with repeated characters" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
expected="WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB"
run bash run_length_encoding.sh decode "12WB12W3B24WB"
assert_success
assert_output "$expected"
}

@test "decode multiple whitespace mixed in string" {
@test "run-length decode a string: multiple whitespace mixed in string" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
expected=" hsqq qww "
run bash run_length_encoding.sh decode "2 hs2q q2w2 "
assert_success
assert_output "$expected"
}

@test "decode lower case string" {
@test "run-length decode a string: lowercase string" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
expected="aabbbcccc"
run bash run_length_encoding.sh decode "2a3b4c"
assert_success
assert_output "$expected"
}

# encode and then decode

@test "encode followed by decode gives original string" {
@test "encode and then decode: encode followed by decode gives original string" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
expected="zzz ZZ zZ"
run bash run_length_encoding.sh encode "zzz ZZ zZ"
Expand Down