Skip to content

Commit

Permalink
Sync hamming tests and update stub (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
BNAndras authored May 16, 2024
1 parent fb48f38 commit 5dd6abb
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 16 deletions.
13 changes: 8 additions & 5 deletions exercises/practice/hamming/.meta/example.lfe
Original file line number Diff line number Diff line change
@@ -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))))
4 changes: 4 additions & 0 deletions exercises/practice/hamming/src/hamming.lfe
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(defmodule hamming
(export (distance 2)))

; Please implement the distance function.
31 changes: 20 additions & 11 deletions exercises/practice/hamming/test/hamming-tests.lfe
Original file line number Diff line number Diff line change
Expand Up @@ -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" "")))

0 comments on commit 5dd6abb

Please sign in to comment.