Skip to content

Commit

Permalink
hamming: Sync tests with problem specifications (#666)
Browse files Browse the repository at this point in the history
* sync tests

* implement tests
  • Loading branch information
tasxatzial authored Sep 10, 2024
1 parent cda6c4b commit 327a9de
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 17 deletions.
43 changes: 40 additions & 3 deletions exercises/practice/hamming/.meta/tests.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# This is an auto-generated file. Regular comments will be removed when this
# file is regenerated. Regenerating will not touch any manually added keys,
# so comments can be added in a "comment" key.
# 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.

[f6dcb64f-03b0-4b60-81b1-3c9dbf47e887]
description = "empty strands"
Expand All @@ -19,12 +26,42 @@ description = "long different strands"

[919f8ef0-b767-4d1b-8516-6379d07fcb28]
description = "disallow first strand longer"
include = false

[b9228bb1-465f-4141-b40f-1f99812de5a8]
description = "disallow first strand longer"
reimplements = "919f8ef0-b767-4d1b-8516-6379d07fcb28"

[8a2d4ed0-ead5-4fdd-924d-27c4cf56e60e]
description = "disallow second strand longer"
include = false

[dab38838-26bb-4fff-acbe-3b0a9bfeba2d]
description = "disallow second strand longer"
reimplements = "8a2d4ed0-ead5-4fdd-924d-27c4cf56e60e"

[5dce058b-28d4-4ca7-aa64-adfe4e17784c]
description = "disallow left empty strand"
include = false

[db92e77e-7c72-499d-8fe6-9354d2bfd504]
description = "disallow left empty strand"
include = false
reimplements = "5dce058b-28d4-4ca7-aa64-adfe4e17784c"

[b764d47c-83ff-4de2-ab10-6cfe4b15c0f3]
description = "disallow empty first strand"
reimplements = "db92e77e-7c72-499d-8fe6-9354d2bfd504"

[38826d4b-16fb-4639-ac3e-ba027dec8b5f]
description = "disallow right empty strand"
include = false

[920cd6e3-18f4-4143-b6b8-74270bb8f8a3]
description = "disallow right empty strand"
include = false
reimplements = "38826d4b-16fb-4639-ac3e-ba027dec8b5f"

[9ab9262f-3521-4191-81f5-0ed184a5aa89]
description = "disallow empty second strand"
reimplements = "920cd6e3-18f4-4143-b6b8-74270bb8f8a3"
45 changes: 31 additions & 14 deletions exercises/practice/hamming/test/hamming_test.clj
Original file line number Diff line number Diff line change
@@ -1,22 +1,39 @@
(ns hamming-test
(:require [clojure.test :refer [deftest is]]
(:require [clojure.test :refer [deftest is testing]]
hamming))

(deftest no-difference-between-empty-strands
(is (= 0 (hamming/distance "" ""))))
(deftest empty-strands
(testing "Empty strands"
(is (= 0 (hamming/distance "" "")))))

(deftest no-difference-between-identical-strands
(is (= 0 (hamming/distance "GGACTGA" "GGACTGA"))))
(deftest single-letter-identical-strands
(testing "Single letter identical strands"
(is (= 0 (hamming/distance "A" "A")))))

(deftest complete-distance-in-small-strand
(is (= 3 (hamming/distance "ACT" "GGA"))))
(deftest single-letter-different-strands
(testing "Single letter different strands"
(is (= 1 (hamming/distance "G" "T")))))

(deftest small-distance-in-middle-somewhere
(is (= 1 (hamming/distance "GGACG" "GGTCG"))))
(deftest long-identical-strands
(testing "Long identical strands"
(is (= 0 (hamming/distance "GGACTGAAATCTG" "GGACTGAAATCTG")))))

(deftest larger-distance
(is (= 2 (hamming/distance "ACCAGGG" "ACTATGG"))))
(deftest long-different-strands
(testing "Long different strands"
(is (= 9 (hamming/distance "GGACGGATTCTG" "AGGACGGATTCT")))))

(deftest undefined-when-lengths-are-different
(is (= nil (hamming/distance "AAAC" "TAGGGGAGGCTAGCGGTAGGAC")))
(is (= nil (hamming/distance "GACTACGGACAGGGTAACATAG" "GACA"))))
(deftest disallow-first-strand-longer
(testing "Disallow first strand longer"
(is (= nil (hamming/distance "AATG" "AAA")))))

(deftest disallow-second-strand-longer
(testing "Disallow second strand longer"
(is (= nil (hamming/distance "ATA" "AGTG")))))

(deftest disallow-empty-first-strand
(testing "Disallow empty first strand"
(is (= nil (hamming/distance "" "G")))))

(deftest disallow-empty-second-strand
(testing "Disallow empty second strand"
(is (= nil (hamming/distance "G" "")))))

0 comments on commit 327a9de

Please sign in to comment.