From 1a72a01f8daccc3ab7b0dfc7c29c6ea80c7688fe Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Tue, 15 Nov 2022 11:43:37 +0100 Subject: [PATCH 1/7] Rectify tests.toml for nucleotide-count This removes an unimplemented test from the tests.toml. --- exercises/practice/nucleotide-count/.meta/tests.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/exercises/practice/nucleotide-count/.meta/tests.toml b/exercises/practice/nucleotide-count/.meta/tests.toml index 79b22f7a8..304098760 100644 --- a/exercises/practice/nucleotide-count/.meta/tests.toml +++ b/exercises/practice/nucleotide-count/.meta/tests.toml @@ -5,9 +5,6 @@ [3e5c30a8-87e2-4845-a815-a49671ade970] description = "empty strand" -[a0ea42a6-06d9-4ac6-828c-7ccaccf98fec] -description = "can count one nucleotide in single-character input" - [eca0d565-ed8c-43e7-9033-6cefbf5115b5] description = "strand with repeated nucleotide" From 70601337f78925f267b7845914fcb40bc7aca1d2 Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Tue, 15 Nov 2022 11:44:16 +0100 Subject: [PATCH 2/7] Remove extraneous tests from nucleotide-count This deletes some tests that are not in the canonical-data in problem-specifications. --- .../nucleotide_count_test.cpp | 37 ------------------- 1 file changed, 37 deletions(-) diff --git a/exercises/practice/nucleotide-count/nucleotide_count_test.cpp b/exercises/practice/nucleotide-count/nucleotide_count_test.cpp index 2ad447490..969d7aff2 100644 --- a/exercises/practice/nucleotide-count/nucleotide_count_test.cpp +++ b/exercises/practice/nucleotide-count/nucleotide_count_test.cpp @@ -18,20 +18,6 @@ TEST_CASE("has_no_nucleotides") } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("has_no_adenosine") -{ - const nucleotide_count::counter dna(""); - - REQUIRE(0 == dna.count('A')); -} - -TEST_CASE("repetitive_cytidine_gets_counts") -{ - const nucleotide_count::counter dna("CCCCC"); - - REQUIRE(5 == dna.count('C')); -} - TEST_CASE("repetitive_sequence_has_only_guanosine") { const nucleotide_count::counter dna("GGGGGGGG"); @@ -42,29 +28,6 @@ TEST_CASE("repetitive_sequence_has_only_guanosine") REQUIRE(expected == actual); } -TEST_CASE("counts_only_thymidine") -{ - const nucleotide_count::counter dna("GGGGTAACCCGG"); - - REQUIRE(1 == dna.count('T')); -} - -TEST_CASE("counts_a_nucleotide_only_once") -{ - const nucleotide_count::counter dna("GGTTGG"); - - dna.count('T'); - - REQUIRE(2 == dna.count('T')); -} - -TEST_CASE("validates_nucleotides") -{ - const nucleotide_count::counter dna("GGTTGG"); - - REQUIRE_THROWS_AS(dna.count('X'), std::invalid_argument); -} - TEST_CASE("validates_nucleotides_on_construction") { REQUIRE_THROWS_AS(nucleotide_count::counter("GGTTGGX"), std::invalid_argument); From 6b218d77e22dff7b3f550a39894b9e4964edb167 Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Tue, 15 Nov 2022 11:47:50 +0100 Subject: [PATCH 3/7] Reorder nucleotide-count tests This reorders the tests to match the order in the canonical-data. --- .../nucleotide-count/nucleotide_count_test.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/exercises/practice/nucleotide-count/nucleotide_count_test.cpp b/exercises/practice/nucleotide-count/nucleotide_count_test.cpp index 969d7aff2..cc3608d7b 100644 --- a/exercises/practice/nucleotide-count/nucleotide_count_test.cpp +++ b/exercises/practice/nucleotide-count/nucleotide_count_test.cpp @@ -28,11 +28,6 @@ TEST_CASE("repetitive_sequence_has_only_guanosine") REQUIRE(expected == actual); } -TEST_CASE("validates_nucleotides_on_construction") -{ - REQUIRE_THROWS_AS(nucleotide_count::counter("GGTTGGX"), std::invalid_argument); -} - TEST_CASE("counts_all_nucleotides") { const nucleotide_count::counter dna("AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"); @@ -42,4 +37,9 @@ TEST_CASE("counts_all_nucleotides") REQUIRE(expected == actual); } + +TEST_CASE("validates_nucleotides_on_construction") +{ + REQUIRE_THROWS_AS(nucleotide_count::counter("GGTTGGX"), std::invalid_argument); +} #endif From 076b41421b3269c60e7d0c19ef3f91d31003c9dd Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Tue, 15 Nov 2022 11:49:58 +0100 Subject: [PATCH 4/7] Run configlet fmt on nucleotide-count This reformats the config.json to make configlet happy. --- exercises/practice/nucleotide-count/.meta/config.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/exercises/practice/nucleotide-count/.meta/config.json b/exercises/practice/nucleotide-count/.meta/config.json index 264b918e5..df7949dc6 100644 --- a/exercises/practice/nucleotide-count/.meta/config.json +++ b/exercises/practice/nucleotide-count/.meta/config.json @@ -1,5 +1,4 @@ { - "blurb": "Given a DNA string, compute how many times each nucleotide occurs in the string.", "authors": [ "LegalizeAdulthood" ], @@ -26,6 +25,7 @@ ".meta/example.h" ] }, + "blurb": "Given a DNA string, compute how many times each nucleotide occurs in the string.", "source": "The Calculating DNA Nucleotides_problem at Rosalind", "source_url": "http://rosalind.info/problems/dna/" } From 486c63dc62165e76e921b4a4d8975b5c78e4f8c8 Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Tue, 15 Nov 2022 12:14:52 +0100 Subject: [PATCH 5/7] Normalize nucleotide-count tests This updates the existing tests to use the inputs and test names from canonical-data. --- .../nucleotide_count_test.cpp | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/exercises/practice/nucleotide-count/nucleotide_count_test.cpp b/exercises/practice/nucleotide-count/nucleotide_count_test.cpp index cc3608d7b..e67c4378e 100644 --- a/exercises/practice/nucleotide-count/nucleotide_count_test.cpp +++ b/exercises/practice/nucleotide-count/nucleotide_count_test.cpp @@ -7,10 +7,10 @@ #include #include -TEST_CASE("has_no_nucleotides") +TEST_CASE("empty_strand") { const nucleotide_count::counter dna(""); - const std::map expected{ {'A', 0}, {'T', 0}, {'C', 0}, {'G', 0} }; + const std::map expected{ {'A', 0}, {'C', 0}, {'G', 0}, {'T', 0} }; const auto actual = dna.nucleotide_counts(); @@ -18,28 +18,29 @@ TEST_CASE("has_no_nucleotides") } #if defined(EXERCISM_RUN_ALL_TESTS) -TEST_CASE("repetitive_sequence_has_only_guanosine") + +TEST_CASE("strand_with_repeated_nucleotide") { - const nucleotide_count::counter dna("GGGGGGGG"); - const std::map expected{ {'A', 0}, {'T', 0}, {'C', 0}, {'G', 8} }; + const nucleotide_count::counter dna("GGGGGGG"); + const std::map expected{ {'A', 0}, {'C', 0}, {'G', 7}, {'T', 0} }; const auto actual = dna.nucleotide_counts(); REQUIRE(expected == actual); } -TEST_CASE("counts_all_nucleotides") +TEST_CASE("strand_with_multiple_nucleotides") { const nucleotide_count::counter dna("AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"); - std::map expected{ {'A', 20}, {'T', 21}, {'G', 17}, {'C', 12} }; + const std::map expected{ {'A', 20}, {'C', 12}, {'G', 17}, {'T', 21} }; - auto actual = dna.nucleotide_counts(); + const auto actual = dna.nucleotide_counts(); REQUIRE(expected == actual); } -TEST_CASE("validates_nucleotides_on_construction") +TEST_CASE("strand_with_invalid_nucleotides") { - REQUIRE_THROWS_AS(nucleotide_count::counter("GGTTGGX"), std::invalid_argument); + REQUIRE_THROWS_AS(nucleotide_count::counter("AGXXACT"), std::invalid_argument); } #endif From 8b09690686026e450ae85b0d9ab8f98adb6c81f5 Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Tue, 15 Nov 2022 12:16:40 +0100 Subject: [PATCH 6/7] Sync nucleotide-count with problem-specifications This brings the nucleotide-count exercise up to date with the specification in problem-specifications. The sync brought in changes to the instructions and metadata, as well as adding a new test. --- .../nucleotide-count/.docs/instructions.md | 8 +++++--- .../practice/nucleotide-count/.meta/config.json | 2 +- .../practice/nucleotide-count/.meta/tests.toml | 16 +++++++++++++--- .../nucleotide-count/nucleotide_count_test.cpp | 10 ++++++++++ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/exercises/practice/nucleotide-count/.docs/instructions.md b/exercises/practice/nucleotide-count/.docs/instructions.md index cd0875894..548d9ba5a 100644 --- a/exercises/practice/nucleotide-count/.docs/instructions.md +++ b/exercises/practice/nucleotide-count/.docs/instructions.md @@ -1,10 +1,12 @@ # Instructions -Each of us inherits from our biological parents a set of chemical instructions known as DNA that influence how our bodies are constructed. All known life depends on DNA! +Each of us inherits from our biological parents a set of chemical instructions known as DNA that influence how our bodies are constructed. +All known life depends on DNA! > Note: You do not need to understand anything about nucleotides or DNA to complete this exercise. -DNA is a long chain of other chemicals and the most important are the four nucleotides, adenine, cytosine, guanine and thymine. A single DNA chain can contain billions of these four nucleotides and the order in which they occur is important! +DNA is a long chain of other chemicals and the most important are the four nucleotides, adenine, cytosine, guanine and thymine. +A single DNA chain can contain billions of these four nucleotides and the order in which they occur is important! We call the order of these nucleotides in a bit of DNA a "DNA sequence". We represent a DNA sequence as an ordered collection of these four nucleotides and a common way to do that is with a string of characters such as "ATTACG" for a DNA sequence of 6 nucleotides. @@ -15,7 +17,7 @@ If the string contains characters that aren't A, C, G, or T then it is invalid a For example: -``` +```text "GATTACA" -> 'A': 3, 'C': 1, 'G': 1, 'T': 2 "INVALID" -> error ``` diff --git a/exercises/practice/nucleotide-count/.meta/config.json b/exercises/practice/nucleotide-count/.meta/config.json index df7949dc6..3c28229ba 100644 --- a/exercises/practice/nucleotide-count/.meta/config.json +++ b/exercises/practice/nucleotide-count/.meta/config.json @@ -27,5 +27,5 @@ }, "blurb": "Given a DNA string, compute how many times each nucleotide occurs in the string.", "source": "The Calculating DNA Nucleotides_problem at Rosalind", - "source_url": "http://rosalind.info/problems/dna/" + "source_url": "https://rosalind.info/problems/dna/" } diff --git a/exercises/practice/nucleotide-count/.meta/tests.toml b/exercises/practice/nucleotide-count/.meta/tests.toml index 304098760..7c55e53f2 100644 --- a/exercises/practice/nucleotide-count/.meta/tests.toml +++ b/exercises/practice/nucleotide-count/.meta/tests.toml @@ -1,10 +1,20 @@ -# 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. [3e5c30a8-87e2-4845-a815-a49671ade970] description = "empty strand" +[a0ea42a6-06d9-4ac6-828c-7ccaccf98fec] +description = "can count one nucleotide in single-character input" + [eca0d565-ed8c-43e7-9033-6cefbf5115b5] description = "strand with repeated nucleotide" diff --git a/exercises/practice/nucleotide-count/nucleotide_count_test.cpp b/exercises/practice/nucleotide-count/nucleotide_count_test.cpp index e67c4378e..0fabf316b 100644 --- a/exercises/practice/nucleotide-count/nucleotide_count_test.cpp +++ b/exercises/practice/nucleotide-count/nucleotide_count_test.cpp @@ -19,6 +19,16 @@ TEST_CASE("empty_strand") #if defined(EXERCISM_RUN_ALL_TESTS) +TEST_CASE("can_count_one_nucleotide_in_single_character_input") +{ + const nucleotide_count::counter dna("G"); + const std::map expected{ {'A', 0}, {'C', 0}, {'G', 1}, {'T', 0} }; + + const auto actual = dna.nucleotide_counts(); + + REQUIRE(expected == actual); +} + TEST_CASE("strand_with_repeated_nucleotide") { const nucleotide_count::counter dna("GGGGGGG"); From 756537e04eed6b7807eedd4829d679b8a5f8690f Mon Sep 17 00:00:00 2001 From: Katrina Owen Date: Tue, 15 Nov 2022 12:19:30 +0100 Subject: [PATCH 7/7] Simplify nucleotide-count example solution The tests no longer reference the count function. This deletes it. --- exercises/practice/nucleotide-count/.meta/example.cpp | 9 --------- 1 file changed, 9 deletions(-) diff --git a/exercises/practice/nucleotide-count/.meta/example.cpp b/exercises/practice/nucleotide-count/.meta/example.cpp index c8368a1ea..cc4a87100 100644 --- a/exercises/practice/nucleotide-count/.meta/example.cpp +++ b/exercises/practice/nucleotide-count/.meta/example.cpp @@ -16,13 +16,4 @@ counter::counter(std::string const& sequence) } } -int counter::count(char nucleotide) const -{ - const auto it = counts_.find(nucleotide); - if (it == counts_.end()) { - throw std::invalid_argument("Unknown nucleotide"); - } - return it->second; -} - }