Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync hamming tests and update stub #243

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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" "")))
Loading