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
35 changes: 35 additions & 0 deletions exercises/practice/variable-length-quantity/.meta/template.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{{ header }}

#
# *** Input and Output numbers are expressed in hexadecimal.
#

{% for idx, case in cases %}
@test "{{ case["description"] }}" {
{% if idx == 0 %}# {% endif %}[[ $BATS_RUN_SKIPPED == "true" ]] || skip
{%- set hex_input = [] %}
{%- for num in case["input"]["integers"] %}
{%- set _ = hex_input.append('%02X' % num) %}
{%- endfor %}
run bash {{ solution }} {{ case["property"] }} {{ hex_input | join(" ") }}
{%- if case["expect_error"] %}
assert_failure
{#- The error message from the canonical data is not used. #}
assert_output --partial "incomplete byte sequence"
{%- else %}
{%- set hex_output = [] %}
{%- for num in case["expected"] %}
{%- set _ = hex_output.append('%02X' % num) %}
{%- endfor %}
assert_success
assert_output "{{ hex_output | join(" ") }}"
{%- endif %}
}
{% endfor %}

@test "invalid subcommand" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash variable_length_quantity.sh hello 80
assert_failure
assert_output --partial "unknown subcommand"
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env bats
load bats-extra

# generated on 2026-06-29T19:27:37+00:00

#
# *** Input and Output numbers are expressed in hexadecimal.
#


# Encode a series of integers, producing a series of bytes.

@test "zero" {
#[[ $BATS_RUN_SKIPPED == "true" ]] || skip
# [[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash variable_length_quantity.sh encode 00
assert_success
assert_output "00"
Expand All @@ -26,7 +26,7 @@ load bats-extra
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash variable_length_quantity.sh encode 53
assert_success
assert_output 53
assert_output "53"
}

@test "largest single byte" {
Expand Down Expand Up @@ -169,9 +169,6 @@ load bats-extra
assert_output "C0 00 C8 E8 56 FF FF FF 7F 00 FF 7F 81 80 00"
}


# Decode a series of bytes, producing a series of integers.

@test "one byte" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash variable_length_quantity.sh decode 7F
Expand Down Expand Up @@ -207,16 +204,6 @@ load bats-extra
assert_output "FFFFFFFF"
}

@test "multiple values" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash variable_length_quantity.sh decode C0 00 C8 E8 56 FF FF FF 7F 00 FF 7F 81 80 00
assert_success
assert_output "2000 123456 FFFFFFF 00 3FFF 4000"
}


# Some error conditions

@test "incomplete sequence causes error" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash variable_length_quantity.sh decode FF
Expand All @@ -231,6 +218,14 @@ load bats-extra
assert_output --partial "incomplete byte sequence"
}

@test "multiple values" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash variable_length_quantity.sh decode C0 00 C8 E8 56 FF FF FF 7F 00 FF 7F 81 80 00
assert_success
assert_output "2000 123456 FFFFFFF 00 3FFF 4000"
}


@test "invalid subcommand" {
[[ $BATS_RUN_SKIPPED == "true" ]] || skip
run bash variable_length_quantity.sh hello 80
Expand Down