From b643f88895250a36d7f2fd109b0aeaa1c869b727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Wed, 17 Apr 2024 13:39:15 -0700 Subject: [PATCH] Sync strain tests (#226) --- exercises/practice/strain/.meta/tests.toml | 52 +++++++ .../practice/strain/test/strain-tests.lfe | 134 ++++++++++++------ 2 files changed, 146 insertions(+), 40 deletions(-) create mode 100644 exercises/practice/strain/.meta/tests.toml 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/test/strain-tests.lfe b/exercises/practice/strain/test/strain-tests.lfe index 25e0602c..c3c966f0 100644 --- a/exercises/practice/strain/test/strain-tests.lfe +++ b/exercises/practice/strain/test/strain-tests.lfe @@ -4,45 +4,99 @@ (include-lib "ltest/include/ltest-macros.lfe") -(deftest empty-keep - (is-equal () (strain:keep #'under-10?/1 ()))) - -(deftest keep-everything - (is-equal '(1 2 3) (strain:keep #'under-10?/1 '(1 2 3)))) - -(deftest keep-first-last - (is-equal '(1 3) (strain:keep #'odd?/1 '(1 2 3)))) - -(deftest keep-nothing - (is-equal () (strain:keep #'even?/1 '(1 3 5 7)))) - -(deftest keep-neither-first-nor-last - (is-equal '(2) (strain:keep #'even?/1 '(1 2 3)))) - -(deftest keep-strings - (let ((strs '("apple" "zebra" "banana" "zombies" "cherimoya" "zealot"))) - (is-equal '("zebra" "zombies" "zealot") - (strain:keep #'starts-with-z?/1 strs)))) - -(deftest empty-discard - (is-equal () (strain:discard #'under-10?/1 ()))) - -(deftest discard-everything - (is-equal () (strain:discard #'under-10?/1 '(1 2 3)))) - -(deftest discard-first-and-last - (is-equal '(2) (strain:discard #'odd?/1 '(1 2 3)))) - -(deftest discard-nothing - (is-equal '(1 3 5 7) (strain:discard #'even?/1 '(1 3 5 7)))) - -(deftest discard-neither-first-nor-last - (is-equal '(1 3) (strain:discard #'even?/1 '(1 2 3)))) - -(deftest discard-strings - (let ((strs '("apple" "zebra" "banana" "zombies" "cherimoya" "zealot"))) - (is-equal '("apple" "banana" "cherimoya") - (strain:discard #'starts-with-z?/1 strs)))) +(deftest keep-on-empty-list-returns-empty-list + (is-equal () (strain:keep #'always-true/1 + ()))) + +(deftest keeps-everything + (is-equal '(1 3 5) (strain:keep #'always-true/1 + '(1 3 5)))) + +(deftest keeps-nothing + (is-equal () (strain:keep #'always-false/1 + '(1 3 5)))) + +(deftest keeps-first-and-last + (is-equal '(1 3) (strain:keep #'odd?/1 + '(1 2 3)))) + +(deftest keeps-neither-first-nor-last + (is-equal '(2) (strain:keep #'even?/1 + '(1 2 3)))) + +(deftest keeps-strings + (is-equal '("zebra" "zombies" "zealot") + (strain:keep #'starts-with-z?/1 + '("apple" + "zebra" + "banana" + "zombies" + "cherimoya" + "zealot")))) + +(deftest keeps-lists + (is-equal '((5 5 5) + (5 1 2) + (1 5 2) + (1 2 5)) + (strain:keep #'contains-five?/1 + '((1 2 3) + (5 5 5) + (5 1 2) + (2 1 2) + (1 5 2) + (2 2 1) + (1 2 5))))) + +(deftest discard-on-empty-list-returns-empty-list + (is-equal () + (strain:discard #'always-true/1 + ()))) + +(deftest discards-everything + (is-equal () (strain:discard #'always-true/1 + '(1 2 3)))) + +(deftest discards-nothing + (is-equal '(1 3 5) + (strain:discard #'always-false/1 + '(1 3 5)))) + +(deftest discards-first-and-last + (is-equal '(2) (strain:discard #'odd?/1 + '(1 2 3)))) + +(deftest discards-neither-first-nor-last + (is-equal '(1 3) (strain:discard #'even?/1 + '(1 2 3)))) + +(deftest discards-strings + (is-equal '("apple" "banana" "cherimoya") + (strain:discard #'starts-with-z?/1 + '("apple" + "zebra" + "banana" + "zombies" + "cherimoya" + "zealot")))) + +(deftest discards-lists + (is-equal '((1 2 3) + (2 1 2) + (2 2 1)) + (strain:discard #'contains-five?/1 + '((1 2 3) + (5 5 5) + (5 1 2) + (2 1 2) + (1 5 2) + (2 2 1) + (1 2 5))))) + + +(defun always-true (_) 'true) + +(defun always-false (_) 'false) (defun even? (n) (=:= (rem n 2) 0)) @@ -50,4 +104,4 @@ (defun starts-with-z? (str) (=:= (string:sub_string str 1 1) "z")) -(defun under-10? (n) (< n 10)) +(defun contains-five? (lst) (lists:member 5 lst))