-
-
Notifications
You must be signed in to change notification settings - Fork 366
Add Nucleotide Count Test Generator #416 #456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ErikSchierboom
merged 3 commits into
exercism:master
from
hymccord:nucleotide-count-generator
Oct 4, 2017
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,55 @@ | ||
using System.Collections.Generic; | ||
// This file was auto-generated based on version 1.0.0 of the canonical data. | ||
|
||
using Xunit; | ||
using System.Collections.Generic; | ||
|
||
public class NucleoTideCountTest | ||
public class NucleotideCountTest | ||
{ | ||
[Fact] | ||
public void Has_no_nucleotides() | ||
{ | ||
var dna = new DNA(""); | ||
var expected = new Dictionary<char, int> { { 'A', 0 }, { 'T', 0 }, { 'C', 0 }, { 'G', 0 } }; | ||
Assert.Equal(expected, dna.NucleotideCounts); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Has_no_adenosine() | ||
{ | ||
var dna = new DNA(""); | ||
Assert.Equal(0, dna.Count('A')); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Repetitive_cytidine_gets_counts() | ||
{ | ||
var dna = new DNA("CCCCC"); | ||
Assert.Equal(5, dna.Count('C')); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Repetitive_sequence_has_only_guanosine() | ||
{ | ||
var dna = new DNA("GGGGGGGG"); | ||
var expected = new Dictionary<char, int> { { 'A', 0 }, { 'T', 0 }, { 'C', 0 }, { 'G', 8 } }; | ||
Assert.Equal(expected, dna.NucleotideCounts); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Counts_only_thymidine() | ||
public void Empty_strand() | ||
{ | ||
var dna = new DNA("GGGGTAACCCGG"); | ||
Assert.Equal(1, dna.Count('T')); | ||
var sut = new NucleotideCount(""); | ||
var expected = new Dictionary<char, int> | ||
{ | ||
['A'] = 0, | ||
['C'] = 0, | ||
['G'] = 0, | ||
['T'] = 0 | ||
}; | ||
Assert.Equal(expected, sut.NucleotideCounts); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Counts_a_nucleotide_only_once() | ||
public void Strand_with_repeated_nucleotide() | ||
{ | ||
var dna = new DNA("GGTTGG"); | ||
dna.Count('T'); | ||
Assert.Equal(2, dna.Count('T')); | ||
var sut = new NucleotideCount("GGGGGGG"); | ||
var expected = new Dictionary<char, int> | ||
{ | ||
['A'] = 0, | ||
['C'] = 0, | ||
['G'] = 7, | ||
['T'] = 0 | ||
}; | ||
Assert.Equal(expected, sut.NucleotideCounts); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Validates_nucleotides() | ||
public void Strand_with_multiple_nucleotides() | ||
{ | ||
var dna = new DNA("GGTTGG"); | ||
Assert.Throws<InvalidNucleotideException>(() => dna.Count('X')); | ||
var sut = new NucleotideCount("AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"); | ||
var expected = new Dictionary<char, int> | ||
{ | ||
['A'] = 20, | ||
['C'] = 12, | ||
['G'] = 17, | ||
['T'] = 21 | ||
}; | ||
Assert.Equal(expected, sut.NucleotideCounts); | ||
} | ||
|
||
[Fact(Skip = "Remove to run test")] | ||
public void Counts_all_nucleotides() | ||
public void Strand_with_invalid_nucleotides() | ||
{ | ||
var dna = new DNA("AGCTTTTCATTCTGACTGCAACGGGCAATATGTCTCTGTGTGGATTAAAAAAAGAGTGTCTGATAGCAGC"); | ||
var expected = new Dictionary<char, int> { { 'A', 20 }, { 'T', 21 }, { 'C', 12 }, { 'G', 17 } }; | ||
Assert.Equal(expected, dna.NucleotideCounts); | ||
Assert.Throws<InvalidNucleotideException>(() => new NucleotideCount("AGXXACT")); | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using Generators.Input; | ||
using Generators.Output; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace Generators.Exercises | ||
{ | ||
class NucleotideCount : Exercise | ||
{ | ||
protected override void UpdateCanonicalData(CanonicalData canonicalData) | ||
{ | ||
foreach (var canonicalDataCase in canonicalData.Cases) | ||
{ | ||
if (!((Dictionary<string, object>)canonicalDataCase.Expected).ContainsKey("error")) | ||
{ | ||
canonicalDataCase.UseVariableForExpected = true; | ||
canonicalDataCase.SetConstructorInputParameters("strand"); | ||
canonicalDataCase.Expected = ConvertExpected(canonicalDataCase.Expected); | ||
} | ||
} | ||
} | ||
|
||
private static dynamic ConvertExpected(dynamic expected) | ||
=> ((Dictionary<string, object>)expected).ToDictionary(kv => kv.Key[0], kv => int.Parse($"{kv.Value}")); | ||
|
||
protected override HashSet<string> AddAdditionalNamespaces() => new HashSet<string>() { typeof(Dictionary<char, int>).Namespace }; | ||
|
||
protected override string RenderTestMethodBodyAssert(TestMethodBody testMethodBody) | ||
{ | ||
if (testMethodBody.UseVariableForExpected) | ||
{ | ||
return RenderEqualBodyAssert(testMethodBody); | ||
} | ||
return RenderThrowsBodyAssert(testMethodBody); | ||
} | ||
|
||
private string RenderEqualBodyAssert(TestMethodBody testMethodBody) | ||
{ | ||
const string template = @"Assert.Equal(expected, sut.{{ TestedMethodName }});"; | ||
|
||
var templateParameters = new | ||
{ | ||
TestedMethodName = testMethodBody.CanonicalDataCase.Property.ToTestedMethodName() | ||
}; | ||
|
||
return TemplateRenderer.RenderInline(template, templateParameters); | ||
} | ||
|
||
private string RenderThrowsBodyAssert(TestMethodBody testMethodBody) | ||
{ | ||
const string template = @"Assert.Throws<InvalidNucleotideException>(() => new NucleotideCount(""{{ Input }}""));"; | ||
|
||
var templateParameters = new | ||
{ | ||
Input = testMethodBody.CanonicalDataCase.Input["strand"] | ||
}; | ||
|
||
return TemplateRenderer.RenderInline(template, templateParameters); | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add the
public
modifier (for consistency)?