1
exercism fetch cpp nucleotide-count

nucleotide_count_test.cpp

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#include "nucleotide_count.h"
#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>
#include <map>
#include <stdexcept>

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

    const auto actual = dna.nucleotide_counts();

    BOOST_TEST(expected == actual);
}

#if defined(EXERCISM_RUN_ALL_TESTS)
BOOST_AUTO_TEST_CASE(has_no_adenosine)
{
    const dna::counter dna("");

    BOOST_REQUIRE_EQUAL(0, dna.count('A'));
}

BOOST_AUTO_TEST_CASE(repetitive_cytidine_gets_counts)
{
    const dna::counter dna("CCCCC");

    BOOST_REQUIRE_EQUAL(5, dna.count('C'));
}

BOOST_AUTO_TEST_CASE(repetitive_sequence_has_only_guanosine)
{
    const dna::counter dna("GGGGGGGG");
    const std::map<char, int> expected{ {'A', 0}, {'T', 0}, {'C', 0}, {'G', 8} };

    const auto actual = dna.nucleotide_counts();

    BOOST_TEST(expected == actual);
}

BOOST_AUTO_TEST_CASE(counts_only_thymidine)
{
    const dna::counter dna("GGGGTAACCCGG");

    BOOST_REQUIRE_EQUAL(1, dna.count('T'));
}

BOOST_AUTO_TEST_CASE(counts_a_nucleotide_only_once)
{
    const dna::counter dna("GGTTGG");

    dna.count('T');

    BOOST_REQUIRE_EQUAL(2, dna.count('T'));
}

BOOST_AUTO_TEST_CASE(validates_nucleotides)
{
    const dna::counter dna("GGTTGG");

    BOOST_REQUIRE_THROW(dna.count('X'), std::invalid_argument);
}

BOOST_AUTO_TEST_CASE(validates_nucleotides_on_construction)
{
    BOOST_REQUIRE_THROW(dna::counter("GGTTGGX"), std::invalid_argument);
}

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

    auto actual = dna.nucleotide_counts();

    BOOST_TEST(expected == actual);
}
#endif