Skip to content
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

Add test generator for rna transcription exercise #353

Merged
merged 3 commits into from
Aug 19, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 6 additions & 1 deletion exercises/rna-transcription/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,13 @@ public class Complement
{ 'G', 'C' }, { 'C', 'G' }, { 'T', 'A' }, { 'A', 'U' }
};

public static string OfDna(string nucleotide)
public static string ToRna(string nucleotide)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build fails because this (example) class' name has not been renamed to RnaTranscription.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I fixed that and updated the PR.

{
if (nucleotide.Any(x => !DnaToRna.ContainsKey(x)))
{
return null;
}

return string.Concat(nucleotide.Select(x => DnaToRna[x]));
}
}
4 changes: 2 additions & 2 deletions exercises/rna-transcription/RnaTranscription.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;

public static class Complement
public static class RnaTranscription
{
public static string OfDna(string nucleotide)
public static string ToRna(string nucleotide)
{
throw new NotImplementedException("You need to implement this function.");
}
Expand Down
32 changes: 26 additions & 6 deletions exercises/rna-transcription/RnaTranscriptionTest.cs
Original file line number Diff line number Diff line change
@@ -1,34 +1,54 @@
// This file was auto-generated based on version 1.0.1 of the canonical data.

using Xunit;

public class ComplementTest
public class RnaTranscriptionTest
{
[Fact]
public void Rna_complement_of_cytosine_is_guanine()
{
Assert.Equal("G", Complement.OfDna("C"));
Assert.Equal("G", RnaTranscription.ToRna("C"));
}

[Fact(Skip = "Remove to run test")]
public void Rna_complement_of_guanine_is_cytosine()
{
Assert.Equal("C", Complement.OfDna("G"));
Assert.Equal("C", RnaTranscription.ToRna("G"));
}

[Fact(Skip = "Remove to run test")]
public void Rna_complement_of_thymine_is_adenine()
{
Assert.Equal("A", Complement.OfDna("T"));
Assert.Equal("A", RnaTranscription.ToRna("T"));
}

[Fact(Skip = "Remove to run test")]
public void Rna_complement_of_adenine_is_uracil()
{
Assert.Equal("U", Complement.OfDna("A"));
Assert.Equal("U", RnaTranscription.ToRna("A"));
}

[Fact(Skip = "Remove to run test")]
public void Rna_complement()
{
Assert.Equal("UGCACCAGAAUU", Complement.OfDna("ACGTGGTCTTAA"));
Assert.Equal("UGCACCAGAAUU", RnaTranscription.ToRna("ACGTGGTCTTAA"));
}

[Fact(Skip = "Remove to run test")]
public void Correctly_handles_invalid_input_rna_instead_of_dna_()
{
Assert.Equal(null, RnaTranscription.ToRna("U"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we return null or throw an exception?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way has it's pros and cons, but now that I think about other exercises they're mostly throwing exceptions, so for consistency it probably makes sense to head in that direction.

}

[Fact(Skip = "Remove to run test")]
public void Correctly_handles_completely_invalid_dna_input()
{
Assert.Equal(null, RnaTranscription.ToRna("XXX"));
}

[Fact(Skip = "Remove to run test")]
public void Correctly_handles_partially_invalid_dna_input()
{
Assert.Equal(null, RnaTranscription.ToRna("ACGTXXXCTTAA"));
}
}
16 changes: 16 additions & 0 deletions generators/Exercises/RnaTranscription.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Generators.Input;
using Generators.Output;

namespace Generators.Exercises
{
public class RnaTranscription : Exercise
{
protected override void UpdateCanonicalData(CanonicalData canonicalData)
{
foreach (var canonicalDataCase in CanonicalData.Cases)
{
canonicalDataCase.Expected = canonicalDataCase.Expected ?? new UnescapedValue("null");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not ideal and should not be necessary. A null value should be displayed as null. I'll try and fix that.

}
}
}
}