Skip to content

Commit

Permalink
Sync nucleotide-count with problem-specifications (#550)
Browse files Browse the repository at this point in the history
* Rectify tests.toml for nucleotide-count

This removes an unimplemented test from the tests.toml.

* Remove extraneous tests from nucleotide-count

This deletes some tests that are not in the canonical-data in
problem-specifications.

* Reorder nucleotide-count tests

This reorders the tests to match the order in the canonical-data.

* Run configlet fmt on nucleotide-count

This reformats the config.json to make configlet happy.

* Normalize nucleotide-count tests

This updates the existing tests to use the inputs and test names from
canonical-data.

* 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.

* Simplify nucleotide-count example solution

The tests no longer reference the count function.
This deletes it.
  • Loading branch information
kytrinyx authored Nov 15, 2022
1 parent d424593 commit 4f60551
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 60 deletions.
8 changes: 5 additions & 3 deletions exercises/practice/nucleotide-count/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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
```
4 changes: 2 additions & 2 deletions exercises/practice/nucleotide-count/.meta/config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
"blurb": "Given a DNA string, compute how many times each nucleotide occurs in the string.",
"authors": [
"LegalizeAdulthood"
],
Expand All @@ -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/"
"source_url": "https://rosalind.info/problems/dna/"
}
9 changes: 0 additions & 9 deletions exercises/practice/nucleotide-count/.meta/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
13 changes: 10 additions & 3 deletions exercises/practice/nucleotide-count/.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.

[3e5c30a8-87e2-4845-a815-a49671ade970]
description = "empty strand"
Expand Down
60 changes: 17 additions & 43 deletions exercises/practice/nucleotide-count/nucleotide_count_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,76 +7,50 @@
#include <map>
#include <stdexcept>

TEST_CASE("has_no_nucleotides")
TEST_CASE("empty_strand")
{
const nucleotide_count::counter dna("");
const std::map<char, int> expected{ {'A', 0}, {'T', 0}, {'C', 0}, {'G', 0} };
const std::map<char, int> expected{ {'A', 0}, {'C', 0}, {'G', 0}, {'T', 0} };

const auto actual = dna.nucleotide_counts();

REQUIRE(expected == actual);
}

#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")
TEST_CASE("can_count_one_nucleotide_in_single_character_input")
{
const nucleotide_count::counter dna("GGGGGGGG");
const std::map<char, int> expected{ {'A', 0}, {'T', 0}, {'C', 0}, {'G', 8} };
const nucleotide_count::counter dna("G");
const std::map<char, int> expected{ {'A', 0}, {'C', 0}, {'G', 1}, {'T', 0} };

const auto actual = dna.nucleotide_counts();

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")
TEST_CASE("strand_with_repeated_nucleotide")
{
const nucleotide_count::counter dna("GGTTGG");
const nucleotide_count::counter dna("GGGGGGG");
const std::map<char, int> expected{ {'A', 0}, {'C', 0}, {'G', 7}, {'T', 0} };

dna.count('T');
const auto actual = dna.nucleotide_counts();

REQUIRE(2 == dna.count('T'));
REQUIRE(expected == actual);
}

TEST_CASE("validates_nucleotides")
TEST_CASE("strand_with_multiple_nucleotides")
{
const nucleotide_count::counter dna("GGTTGG");
const nucleotide_count::counter dna("AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC");
const std::map<char, int> expected{ {'A', 20}, {'C', 12}, {'G', 17}, {'T', 21} };

REQUIRE_THROWS_AS(dna.count('X'), std::invalid_argument);
}
const auto actual = dna.nucleotide_counts();

TEST_CASE("validates_nucleotides_on_construction")
{
REQUIRE_THROWS_AS(nucleotide_count::counter("GGTTGGX"), std::invalid_argument);
REQUIRE(expected == actual);
}

TEST_CASE("counts_all_nucleotides")
TEST_CASE("strand_with_invalid_nucleotides")
{
const nucleotide_count::counter dna("AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC");
std::map<char, int> expected{ {'A', 20}, {'T', 21}, {'G', 17}, {'C', 12} };

auto actual = dna.nucleotide_counts();

REQUIRE(expected == actual);
REQUIRE_THROWS_AS(nucleotide_count::counter("AGXXACT"), std::invalid_argument);
}
#endif

0 comments on commit 4f60551

Please sign in to comment.