Sha256: 206ecadfd90ce396fee14e135352cdf99c1c41208ef1f632934df2e8e96a55e7
Contents?: true
Size: 1.83 KB
Versions: 181
Compression:
Stored size: 1.83 KB
Contents
module nucleotide_count; import std.string; import std.array; import std.algorithm.sorting: sort; import std.algorithm.comparison: equal; unittest { // test associative array equality bool aaEqual (const int[char] lhs, const int[char] rhs) { auto lhs_pairs = lhs.byKeyValue.array; auto rhs_pairs = rhs.byKeyValue.array; lhs_pairs.sort!(q{a.key < b.key}); rhs_pairs.sort!(q{a.key < b.key}); return equal!("a.key == b.key && a.value == b.value")(lhs_pairs, rhs_pairs); } immutable int allTestsEnabled = 0; // has_no_nucleotides { const Counter dna = new Counter(""); const ulong[char] expected = ['A': 0, 'T': 0, 'C': 0, 'G':0]; auto actual = dna.nucleotideCounts(); assert(aaEqual(expected, actual)); } static if (allTestsEnabled) { // has_no_adenosine { const Counter dna = new Counter(""); assert(dna.countOne('A') == 0); } // repetitive_cytidine_gets_count { const Counter dna = new Counter("CCCCC"); assert(dna.countOne('C') == 5); } // repetitive_sequence_has_only_guanosine { const Counter dna = new Counter("GGGGGGGG"); const ulong[char] expected = ['A': 0, 'T': 0, 'C': 0, 'G': 8]; const auto actual = dna.nucleotideCounts(); assert(aaEqual(expected, actual)); } // count_only_thymidine { const Counter dna = new Counter("GGGGTAACCCGG"); assert(dna.countOne('T') == 1); } // count_a_nucleotide_only_once { const Counter dna = new Counter("GGTTGG"); dna.countOne('T'); assert(dna.countOne('T') == 2); } // validates_nucleotides { const Counter dna = new Counter("GGTTGG"); assertThrown(dna.countOne('X')); } // count_all_nucleotides) { const Counter dna = new Counter("AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"); const ulong[char] expected = ['A': 20, 'T': 21, 'G': 17, 'C': 12 ]; auto actual = dna.nucleotideCounts(); assert(aaEqual(expected, actual)); } } } void main () { }
Version data entries
181 entries across 181 versions & 1 rubygems