Skip to content

Commit

Permalink
Rename nucleotide-count files (#241)
Browse files Browse the repository at this point in the history
  • Loading branch information
BNAndras authored May 16, 2024
1 parent 98a047a commit fb48f38
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 42 deletions.
4 changes: 2 additions & 2 deletions exercises/practice/nucleotide-count/.meta/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
],
"files": {
"solution": [
"src/dna.lfe"
"src/nucleotide-count.lfe"
],
"test": [
"test/dna-tests.lfe"
"test/nucleotide-count-tests.lfe"
],
"example": [
".meta/example.lfe"
Expand Down
9 changes: 4 additions & 5 deletions exercises/practice/nucleotide-count/.meta/example.lfe
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
(defmodule dna
(export (count 2)
(nucleotide-counts 1)))
(defmodule nucleotide-count
(export (counts 1)))

(defun validate (nucleotide)
(if (lists:member nucleotide '("A" "C" "G" "T"))
`#(ok ,nucleotide)
(erlang:error (++ "Invalid nucleotide: '" nucleotide "'"))))

(defun count (strand nucleotide)
;; `validate` will throw iff `nucleotide` is invalid.
;; `validate` will throw if `nucleotide` is invalid.
(validate nucleotide)
(lists:foldl
(lambda (nucleotide* sum)
Expand All @@ -18,7 +17,7 @@
0
strand))

(defun nucleotide-counts (strand)
(defun counts (strand)
(lists:map
(lambda (nucleotide)
`#(,nucleotide ,(count strand nucleotide)))
Expand Down
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[{description, ""},
{vsn, "0.0.1"},
{modules,
['dna']},
['nucleotide-count']},
{registered, []},
{applications,
[kernel, stdlib]},
Expand Down
4 changes: 4 additions & 0 deletions exercises/practice/nucleotide-count/src/nucleotide-count.lfe
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
(defmodule nucleotide-count
(export (counts 1)))

; Please implement the counts function
34 changes: 0 additions & 34 deletions exercises/practice/nucleotide-count/test/dna-tests.lfe

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
(defmodule nucleotide-count-tests
(behaviour ltest-unit)
(export all))

(include-lib "ltest/include/ltest-macros.lfe")

(deftest empty-strand
(is-equal `(#("A" 0) #("C" 0) #("G" 0) #("T" 0))
(nucleotide-count:counts "")))

(deftest can-count-one-nucleotide-in-single-character-input
(is-equal `(#("A" 0) #("C" 0) #("G" 1) #("T" 0))
(nucleotide-count:counts "G")))

(deftest strand-with-repeated-nucleotide
(is-equal `(#("A" 0) #("C" 0) #("G" 7) #("T" 0))
(nucleotide-count:counts "GGGGGGG")))

(deftest strand-with-multiple-nucleotides
(is-equal `(#("A" 20) #("C" 12) #("G" 17) #("T" 21))
(nucleotide-count:counts "AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC")))

(deftest strand-with-invalid-nucleotides
(is-error (nucleotide-count:counts "AGXXACT")))

0 comments on commit fb48f38

Please sign in to comment.