Skip to content

Commit e9ace2d

Browse files
committed
[run-length-encoding] Add a Jinja test template
1 parent f126234 commit e9ace2d

2 files changed

Lines changed: 33 additions & 21 deletions

File tree

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{ header }}
2+
{% for idx, case in cases %}
3+
@test "{{ case["descriptions"] | join(": ") }}" {
4+
{% if idx == 0 %}# {% endif %}[[ $BATS_RUN_SKIPPED == "true" ]] || skip
5+
expected="{{ case["expected"] }}"
6+
{%- if case["property"] == "consistency" %}
7+
run bash run_length_encoding.sh encode "{{ case["input"]["string"] }}"
8+
assert_success
9+
encoded=$output
10+
run bash run_length_encoding.sh decode "$encoded"
11+
{%- else %}
12+
run bash {{ solution }} {{ case["property"] }} "{{ case["input"]["string"] }}"
13+
{%- endif %}
14+
assert_success
15+
assert_output "$expected"
16+
}
17+
{% endfor %}

exercises/practice/run-length-encoding/run_length_encoding.bats

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,106 @@
11
#!/usr/bin/env bats
22
load bats-extra
33

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

6-
# run-length encode a string
7-
8-
@test "encode empty string" {
9-
#[[ $BATS_RUN_SKIPPED == "true" ]] || skip
7+
@test "run-length encode a string: empty string" {
8+
# [[ $BATS_RUN_SKIPPED == "true" ]] || skip
109
expected=""
1110
run bash run_length_encoding.sh encode ""
1211
assert_success
1312
assert_output "$expected"
1413
}
1514

16-
@test "encode single characters only are encoded without count" {
15+
@test "run-length encode a string: single characters only are encoded without count" {
1716
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
1817
expected="XYZ"
1918
run bash run_length_encoding.sh encode "XYZ"
2019
assert_success
2120
assert_output "$expected"
2221
}
2322

24-
@test "encode string with no single characters" {
23+
@test "run-length encode a string: string with no single characters" {
2524
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
2625
expected="2A3B4C"
2726
run bash run_length_encoding.sh encode "AABBBCCCC"
2827
assert_success
2928
assert_output "$expected"
3029
}
3130

32-
@test "encode single characters mixed with repeated characters" {
31+
@test "run-length encode a string: single characters mixed with repeated characters" {
3332
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
3433
expected="12WB12W3B24WB"
3534
run bash run_length_encoding.sh encode "WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB"
3635
assert_success
3736
assert_output "$expected"
3837
}
3938

40-
@test "encode multiple whitespace mixed in string" {
39+
@test "run-length encode a string: multiple whitespace mixed in string" {
4140
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
4241
expected="2 hs2q q2w2 "
4342
run bash run_length_encoding.sh encode " hsqq qww "
4443
assert_success
4544
assert_output "$expected"
4645
}
4746

48-
@test "encode lowercase characters" {
47+
@test "run-length encode a string: lowercase characters" {
4948
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
5049
expected="2a3b4c"
5150
run bash run_length_encoding.sh encode "aabbbcccc"
5251
assert_success
5352
assert_output "$expected"
5453
}
5554

56-
# run-length decode a string
57-
58-
@test "decode empty string" {
55+
@test "run-length decode a string: empty string" {
5956
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
6057
expected=""
6158
run bash run_length_encoding.sh decode ""
6259
assert_success
6360
assert_output "$expected"
6461
}
6562

66-
@test "single characters only" {
63+
@test "run-length decode a string: single characters only" {
6764
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
6865
expected="XYZ"
6966
run bash run_length_encoding.sh decode "XYZ"
7067
assert_success
7168
assert_output "$expected"
7269
}
7370

74-
@test "decode string with no single characters" {
71+
@test "run-length decode a string: string with no single characters" {
7572
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
7673
expected="AABBBCCCC"
7774
run bash run_length_encoding.sh decode "2A3B4C"
7875
assert_success
7976
assert_output "$expected"
8077
}
8178

82-
@test "decode single characters with repeated characters" {
79+
@test "run-length decode a string: single characters with repeated characters" {
8380
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
8481
expected="WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWB"
8582
run bash run_length_encoding.sh decode "12WB12W3B24WB"
8683
assert_success
8784
assert_output "$expected"
8885
}
8986

90-
@test "decode multiple whitespace mixed in string" {
87+
@test "run-length decode a string: multiple whitespace mixed in string" {
9188
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
9289
expected=" hsqq qww "
9390
run bash run_length_encoding.sh decode "2 hs2q q2w2 "
9491
assert_success
9592
assert_output "$expected"
9693
}
9794

98-
@test "decode lower case string" {
95+
@test "run-length decode a string: lowercase string" {
9996
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
10097
expected="aabbbcccc"
10198
run bash run_length_encoding.sh decode "2a3b4c"
10299
assert_success
103100
assert_output "$expected"
104101
}
105102

106-
# encode and then decode
107-
108-
@test "encode followed by decode gives original string" {
103+
@test "encode and then decode: encode followed by decode gives original string" {
109104
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
110105
expected="zzz ZZ zZ"
111106
run bash run_length_encoding.sh encode "zzz ZZ zZ"

0 commit comments

Comments
 (0)