From 4aed1a47e85649f4f7a3e7bf2b23d9a7cff2e17e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Wed, 27 Mar 2024 01:55:53 -0700 Subject: [PATCH] Update strain test suite (#395) --- exercises/practice/strain/.meta/config.json | 2 +- exercises/practice/strain/.meta/tests.toml | 52 +++++++ .../strain/src/test/groovy/StrainSpec.groovy | 127 +++++++++++++----- 3 files changed, 150 insertions(+), 31 deletions(-) create mode 100644 exercises/practice/strain/.meta/tests.toml diff --git a/exercises/practice/strain/.meta/config.json b/exercises/practice/strain/.meta/config.json index e5a25245..5d80c53e 100644 --- a/exercises/practice/strain/.meta/config.json +++ b/exercises/practice/strain/.meta/config.json @@ -13,7 +13,7 @@ ".meta/src/reference/groovy/Strain.groovy" ] }, - "blurb": "Implement the `keep` and `discard` operation on collections. Given a collection and a predicate on the collection's elements, `keep` returns a new collection containing those elements where the predicate is true, while `discard` returns a new collection containing those elements where the predicate is false.", + "blurb": "Implement the `keep` and `discard` operation on collections.", "source": "Conversation with James Edward Gray II", "source_url": "http://graysoftinc.com/" } diff --git a/exercises/practice/strain/.meta/tests.toml b/exercises/practice/strain/.meta/tests.toml new file mode 100644 index 00000000..3a617b4a --- /dev/null +++ b/exercises/practice/strain/.meta/tests.toml @@ -0,0 +1,52 @@ +# This is an auto-generated file. +# +# Regenerating this file via `configlet sync` will: +# - Recreate every `description` key/value pair +# - Recreate every `reimplements` key/value pair, where they exist in problem-specifications +# - Remove any `include = true` key/value pair (an omitted `include` key implies inclusion) +# - Preserve any other key/value pair +# +# As user-added comments (using the # character) will be removed when this file +# is regenerated, comments can be added via a `comment` key. + +[26af8c32-ba6a-4eb3-aa0a-ebd8f136e003] +description = "keep on empty list returns empty list" + +[f535cb4d-e99b-472a-bd52-9fa0ffccf454] +description = "keeps everything" + +[950b8e8e-f628-42a8-85e2-9b30f09cde38] +description = "keeps nothing" + +[92694259-6e76-470c-af87-156bdf75018a] +description = "keeps first and last" + +[938f7867-bfc7-449e-a21b-7b00cbb56994] +description = "keeps neither first nor last" + +[8908e351-4437-4d2b-a0f7-770811e48816] +description = "keeps strings" + +[2728036b-102a-4f1e-a3ef-eac6160d876a] +description = "keeps lists" + +[ef16beb9-8d84-451a-996a-14e80607fce6] +description = "discard on empty list returns empty list" + +[2f42f9bc-8e06-4afe-a222-051b5d8cd12a] +description = "discards everything" + +[ca990fdd-08c2-4f95-aa50-e0f5e1d6802b] +description = "discards nothing" + +[71595dae-d283-48ca-a52b-45fa96819d2f] +description = "discards first and last" + +[ae141f79-f86d-4567-b407-919eaca0f3dd] +description = "discards neither first nor last" + +[daf25b36-a59f-4f29-bcfe-302eb4e43609] +description = "discards strings" + +[a38d03f9-95ad-4459-80d1-48e937e4acaf] +description = "discards lists" diff --git a/exercises/practice/strain/src/test/groovy/StrainSpec.groovy b/exercises/practice/strain/src/test/groovy/StrainSpec.groovy index 5a5c8ba8..c72188d1 100644 --- a/exercises/practice/strain/src/test/groovy/StrainSpec.groovy +++ b/exercises/practice/strain/src/test/groovy/StrainSpec.groovy @@ -2,104 +2,171 @@ import spock.lang.* class StrainSpec extends Specification { - def "Keep returns empty collection"() { + def "Keep on empty list returns empty list"() { expect: Strain.keep(collection, predicate) == expected where: - collection | predicate || expected - [] | { it % 2 == 0 } || [] + collection | predicate || expected + [] | { true } || [] } @Ignore - def "Keep all even numbers"() { + def "Keeps everything"() { expect: Strain.keep(collection, predicate) == expected where: - collection | predicate || expected - [1, 2, 3, 4, 5] | { it % 2 == 0 } || [2, 4] + collection | predicate || expected + [1, 3, 5] | { true } || [1, 3, 5] } @Ignore - def "Keep all odd numbers"() { + def "Keeps nothing"() { expect: Strain.keep(collection, predicate) == expected where: - collection | predicate || expected - [1, 2, 3, 4, 5] | { it % 2 != 0 } || [1, 3, 5] + collection | predicate || expected + [1, 3, 5] | { false } || [] } @Ignore - def "Keep all everything under 10"() { + def "Keeps first and last"() { expect: Strain.keep(collection, predicate) == expected where: - collection | predicate || expected - [1, 2, 3, 4, 5] | { it < 10 } || [1, 2, 3, 4, 5] + collection | predicate || expected + [1, 2, 3] | { it % 2 == 1 } || [1, 3] } @Ignore - def "Keep String that start with 'z'"() { + def "Keeps neither first nor last"() { expect: Strain.keep(collection, predicate) == expected where: - collection = ['apple', 'zebra', 'banana', 'zombies', 'cherimoya', 'zelot'] - predicate = { it.startsWith('z') } - expected = ['zebra', 'zombies', 'zelot'] + collection | predicate || expected + [1, 2, 3] | { it % 2 == 0 } || [2] + } + + @Ignore + def "Keeps strings"() { + expect: + Strain.keep(collection, predicate) == expected + + where: + collection = ['apple', 'zebra', 'banana', 'zombies', 'cherimoya', 'zealot'] + predicate = { it.startsWith('z') } + expected = ['zebra', 'zombies', 'zealot'] + } + + @Ignore + def "Keeps lists"() { + expect: + Strain.keep(collection, predicate) == expected + + where: + collection = [ + [1, 2, 3], + [5, 5, 5], + [5, 1, 2], + [2, 1, 2], + [1, 5, 2], + [2, 2, 1], + [1, 2, 5] + ] + predicate = { it.contains(5) } + expected = [ + [5, 5, 5], + [5, 1, 2], + [1, 5, 2], + [1, 2, 5] + ] } @Ignore - def "Discard returns empty collection"() { + def "Discard on empty list returns empty list"() { expect: Strain.discard(collection, predicate) == expected where: - collection | predicate || expected - [] | { it % 2 == 0 } || [] + collection | predicate || expected + [] | { true } || [] } @Ignore - def "Discard all even numbers"() { + def "Discards everything"() { expect: Strain.discard(collection, predicate) == expected where: - collection | predicate || expected - [1, 2, 3, 4, 5] | { it % 2 == 0 } || [1, 3, 5] + collection | predicate || expected + [1, 3, 5] | { true } || [] } @Ignore - def "Discard all odd numbers"() { + def "Discards nothing"() { expect: Strain.discard(collection, predicate) == expected where: - collection | predicate || expected - [1, 2, 3, 4, 5] | { it % 2 != 0 } || [2, 4] + collection | predicate || expected + [1, 3, 5] | { false } || [1, 3, 5] } @Ignore - def "Discard all everything under 10"() { + def "Discards first and last"() { expect: Strain.discard(collection, predicate) == expected where: - collection | predicate || expected - [1, 2, 3, 4, 5] | { it < 10 } || [] + collection | predicate || expected + [1, 2, 3] | { it % 2 == 1 } || [2] } @Ignore - def "Discard String that start with 'z'"() { + def "Discards neither first nor last"() { expect: Strain.discard(collection, predicate) == expected where: - collection = ['apple', 'zebra', 'banana', 'zombies', 'cherimoya', 'zelot'] + collection | predicate || expected + [1, 2, 3] | { it % 2 == 0 } || [1, 3] + } + + @Ignore + def "Discards strings"() { + expect: + Strain.discard(collection, predicate) == expected + + where: + collection = ['apple', 'zebra', 'banana', 'zombies', 'cherimoya', 'zealot'] predicate = { it.startsWith('z') } expected = ['apple', 'banana', 'cherimoya'] } + + @Ignore + def "Discards lists"() { + expect: + Strain.discard(collection, predicate) == expected + + where: + collection = [ + [1, 2, 3], + [5, 5, 5], + [5, 1, 2], + [2, 1, 2], + [1, 5, 2], + [2, 2, 1], + [1, 2, 5] + ] + predicate = { it.contains(5) } + expected = [ + [1, 2, 3], + [2, 1, 2], + [2, 2, 1] + ] + } } \ No newline at end of file