Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions nucleotide-count/Example.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;

public class DNA
{
public IDictionary<char, int> NucleotideCounts { get; private set; }

public DNA(string sequence)
{
InitializeNucleotideCounts(sequence);
}

private void InitializeNucleotideCounts(string sequence)
{
NucleotideCounts = new Dictionary<char, int> { { 'A', 0 }, { 'T', 0 }, { 'C', 0 }, { 'G', 0 } };
foreach (var s in sequence)
NucleotideCounts[s] += 1;
}

public int Count(char nucleotide)
{
if (IsUracil(nucleotide))
return 0;

int count;
if (!NucleotideCounts.TryGetValue(nucleotide, out count))
throw new InvalidNucleotideException();
return count;
}

private static bool IsUracil(char nucleotide)
{
return nucleotide == 'U';
}
}

public class InvalidNucleotideException : Exception { }
73 changes: 73 additions & 0 deletions nucleotide-count/NucleotideCountTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using System.Collections.Generic;
using NUnit.Framework;

[TestFixture]
public class NucleoTideCountTest
{
[Test]
public void HasNoNucleotides()
{
var dna = new DNA("");
var expected = new Dictionary<char, int> { { 'A', 0 }, { 'T', 0 }, { 'C', 0 }, { 'G', 0 } };
Assert.That(dna.NucleotideCounts, Is.EquivalentTo(expected));
}

[Test]
public void HasNoAdenosine()
{
var dna = new DNA("");
Assert.That(dna.Count('A'), Is.EqualTo(0));
}

[Test]
public void RepetitiveCytidineGetsCounts()
{
var dna = new DNA("CCCCC");
Assert.That(dna.Count('C'), Is.EqualTo(5));
}

[Test]
public void RepetitiveSequenceHasOnlyGuanosine()
{
var dna = new DNA("GGGGGGGG");
var expected = new Dictionary<char, int> { { 'A', 0 }, { 'T', 0 }, { 'C', 0 }, { 'G', 8 } };
Assert.That(dna.NucleotideCounts, Is.EquivalentTo(expected));
}

[Test]
public void CountsOnlyThymidine()
{
var dna = new DNA("GGGGTAACCCGG");
Assert.That(dna.Count('T'), Is.EqualTo(1));
}

[Test]
public void CountsANucleotideOnlyOnce()
{
var dna = new DNA("GGTTGG");
dna.Count('T');
Assert.That(dna.Count('T'), Is.EqualTo(2));
}

[Test]
public void HasNoUracil()
{
var dna = new DNA("GGTTGG");
Assert.That(dna.Count('U'), Is.EqualTo(0));
}

[Test]
public void ValidatesNucleotides()
{
var dna = new DNA("GGTTGG");
Assert.Throws<InvalidNucleotideException>(() => dna.Count('X'));
}

[Test]
public void CountsAllNucleotides()
{
var dna = new DNA("AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC");
var expected = new Dictionary<char, int> { { 'A', 20 }, { 'T', 21 }, { 'C', 12 }, { 'G', 17 } };
Assert.That(dna.NucleotideCounts, Is.EquivalentTo(expected));
}
}
2 changes: 1 addition & 1 deletion word-count/WordCountTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using NUnit.Framework;

[TestFixture]
public class BobTest
public class WordCountTest
{
[Test]
public void CountOneWord ()
Expand Down