From b7559bc93ec49b0d862cd5f91d1f0487640dc294 Mon Sep 17 00:00:00 2001 From: Isaac Good Date: Fri, 25 Sep 2026 15:54:52 -0700 Subject: [PATCH] [list-ops] Sync new test case --- exercises/practice/list-ops/.meta/tests.toml | 10 +++++-- .../practice/list-ops/test-list-ops.bats | 29 ++++++++++++++++++- 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/exercises/practice/list-ops/.meta/tests.toml b/exercises/practice/list-ops/.meta/tests.toml index 6c98fa9b..a36270b1 100644 --- a/exercises/practice/list-ops/.meta/tests.toml +++ b/exercises/practice/list-ops/.meta/tests.toml @@ -29,8 +29,8 @@ description = "concatenate a list of lists -> list of lists" [d6ecd72c-197f-40c3-89a4-aa1f45827e09] description = "concatenate a list of lists -> list of nested lists" -comment = "although gawk has arrays of arrays, you cannot write `a[1] = b` if b is an array" include = false +comment = "although gawk has arrays of arrays, you cannot write `a[1] = b` if b is an array" [0524fba8-3e0f-4531-ad2b-f7a43da86a16] description = "filter list returning only values that satisfy the filter function -> empty list" @@ -40,8 +40,8 @@ description = "filter list returning only values that satisfy the filter functio [1cf0b92d-8d96-41d5-9c21-7b3c37cb6aad] description = "returns the length of a list -> empty list" -comment = "builtin length() function exists" include = false +comment = "builtin length() function exists" [d7b8d2d9-2d16-44c4-9a19-6e5f237cb71e] description = "returns the length of a list -> non-empty list" @@ -105,8 +105,12 @@ reimplements = "be396a53-c074-4db3-8dd6-f7ed003cce7c" description = "reverse the elements of the list -> empty list" [fcc03d1e-42e0-4712-b689-d54ad761f360] -description = "reverse the elements of the list -> non-empty list" +description = "reverse the elements of the list -> non-empty even-length list" + +[64d77184-5f74-4845-b158-545d2dd2df98] +description = "reverse the elements of the list -> non-empty odd-length list" [40872990-b5b8-4cb8-9085-d91fc0d05d26] description = "reverse the elements of the list -> list of lists is not flattened" include = false +comment = "skip tests with complex data structures like nested lists" diff --git a/exercises/practice/list-ops/test-list-ops.bats b/exercises/practice/list-ops/test-list-ops.bats index 00b43dc5..203a2c07 100644 --- a/exercises/practice/list-ops/test-list-ops.bats +++ b/exercises/practice/list-ops/test-list-ops.bats @@ -518,7 +518,7 @@ load bats-extra assert_output "" } -@test "reverse non-empty list" { +@test "reverse non-empty even-length list" { [[ $BATS_RUN_SKIPPED == "true" ]] || skip run gawk ' @include "array-utils.awk" @@ -541,3 +541,30 @@ load bats-extra assert_line --index 3 -- "[4] = 1" assert_equal "${#lines[@]}" 4 } + +@test "reverse non-empty odd-length list" { + [[ $BATS_RUN_SKIPPED == "true" ]] || skip + run gawk ' + @include "array-utils.awk" + @include "list-ops.awk" + + BEGIN { + split("1 3 5 7 9 11 13", list) + array::init(result) + + listops::reverse(list, result) + + array::pprint(result) + } + ' + + assert_success + assert_line --index 0 -- "[1] = 13" + assert_line --index 1 -- "[2] = 11" + assert_line --index 2 -- "[3] = 9" + assert_line --index 3 -- "[4] = 7" + assert_line --index 4 -- "[5] = 5" + assert_line --index 5 -- "[6] = 3" + assert_line --index 6 -- "[7] = 1" + assert_equal "${#lines[@]}" 7 +}