From 5dd6abb38fa9488f42aacb4d8963a1c1b42ec08a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A1s=20B=20Nagy?= <20251272+BNAndras@users.noreply.github.com> Date: Thu, 16 May 2024 09:51:34 -0700 Subject: [PATCH] Sync hamming tests and update stub (#243) --- exercises/practice/hamming/.meta/example.lfe | 13 +++++--- exercises/practice/hamming/src/hamming.lfe | 4 +++ .../practice/hamming/test/hamming-tests.lfe | 31 ++++++++++++------- 3 files changed, 32 insertions(+), 16 deletions(-) diff --git a/exercises/practice/hamming/.meta/example.lfe b/exercises/practice/hamming/.meta/example.lfe index 80675e8b..87aa711d 100644 --- a/exercises/practice/hamming/.meta/example.lfe +++ b/exercises/practice/hamming/.meta/example.lfe @@ -1,8 +1,11 @@ (defmodule hamming (export (distance 2))) -(defun distance (strand-x strand-y) - (lists:sum - (lists:zipwith - (lambda (x y) (if (=:= x y) 0 1)) - strand-x strand-y))) +(defun distance (strand1 strand2) + (if (not (== (length strand1) (length strand2))) + (error "strands must have the same length") + (lists:sum + (lists:zipwith + (lambda (a b) (if (=:= a b) 0 1)) + strand1 + strand2)))) diff --git a/exercises/practice/hamming/src/hamming.lfe b/exercises/practice/hamming/src/hamming.lfe index e69de29b..a3f0629e 100644 --- a/exercises/practice/hamming/src/hamming.lfe +++ b/exercises/practice/hamming/src/hamming.lfe @@ -0,0 +1,4 @@ +(defmodule hamming + (export (distance 2))) + + ; Please implement the distance function. diff --git a/exercises/practice/hamming/test/hamming-tests.lfe b/exercises/practice/hamming/test/hamming-tests.lfe index 748480f1..30d65f10 100644 --- a/exercises/practice/hamming/test/hamming-tests.lfe +++ b/exercises/practice/hamming/test/hamming-tests.lfe @@ -4,20 +4,29 @@ (include-lib "ltest/include/ltest-macros.lfe") -(deftest empty +(deftest empty-strands (is-equal 0 (hamming:distance "" ""))) -(deftest equal - (is-equal 0 (hamming:distance "GAGCCTACTAACGGGAT" "GAGCCTACTAACGGGAT"))) +(deftest single-letter-identical-strands + (is-equal 0 (hamming:distance "A" "A"))) -(deftest all-different - (is-equal 17 (hamming:distance "GAGCCTACTAACGGGAT" "FFFFFFFFFFFFFFFFF"))) +(deftest single-letter-different-strands + (is-equal 1 (hamming:distance "G" "T"))) -(deftest ends-different - (is-equal 2 (hamming:distance "GAGCCTACTAACGGGAT" "TAGCCTACTAACGGGAG"))) +(deftest long-identical-strands + (is-equal 0 (hamming:distance "GGACTGAAATCTG" "GGACTGAAATCTG"))) -(deftest middle-different - (is-equal 1 (hamming:distance "GAGCCTACTAACGGGAT" "GAGCCTACCAACGGGAT"))) +(deftest long-different-strands + (is-equal 9 (hamming:distance "GGACGGATTCTG" "AGGACGGATTCT"))) -(deftest some-differences - (is-equal 6 (hamming:distance "GAGCCTACTAACGGGAT" "GAACCTCCCAAGGGATT"))) +(deftest disallow-first-strand-longer + (is-error (hamming:distance "AATG" "AAA"))) + +(deftest disallow-second-strand-longer + (is-error (hamming:distance "ATA" "AGTG"))) + +(deftest disallow-empty-first-strand + (is-error (hamming:distance "" "G"))) + +(deftest disallow-empty-second-strand + (is-error (hamming:distance "G" "")))