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

Version Path
trackler-2.1.0.25 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d
trackler-2.1.0.24 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d
trackler-2.1.0.23 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d
trackler-2.1.0.22 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d
trackler-2.1.0.21 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d
trackler-2.1.0.20 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d
trackler-2.1.0.19 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d
trackler-2.1.0.18 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d
trackler-2.1.0.17 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d
trackler-2.1.0.16 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d
trackler-2.1.0.15 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d
trackler-2.1.0.14 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d
trackler-2.1.0.13 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d
trackler-2.1.0.12 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d
trackler-2.1.0.11 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d
trackler-2.1.0.10 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d
trackler-2.1.0.9 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d
trackler-2.1.0.8 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d
trackler-2.1.0.7 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d
trackler-2.1.0.6 tracks/dlang/exercises/nucleotide-count/nucleotide_count.d