Skip to content

Commit

Permalink
Add exercise: rna-transcription (JuliaLang#19)
Browse files Browse the repository at this point in the history
* Init exercise: rna-transcription

* Add exercise: rna-transcription

* Modified formatting and error in config for rna-transcription exercise
  • Loading branch information
andrej-makarov-skrt authored and SaschaMann committed Jan 26, 2017
1 parent 34ba97c commit 1b0fd4a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 0 deletions.
10 changes: 10 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@
"active": false,
"test_pattern": "TODO",
"exercises": [
{
"slug": "rna-transcription",
"difficulty": 1,
"topics": [
"exception handling",
"strings",
"pattern matching",
"filtering"
]
},
{
"slug": "leap",
"difficulty": 1,
Expand Down
10 changes: 10 additions & 0 deletions exercises/rna-transcription/example.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Given a DNA strand, its transcribed RNA strand is formed by replacing each nucleotide with its complement:
# G -> C, C -> G, T -> A, A -> U
function to_rna(dna::AbstractString)
typeof(match(r"^[GCTA]+$", dna)) == Void && error("Invalid RNA strand")
# Define character associations
a_nucleotides = Dict('G'=>'C', 'C'=>'G', 'T'=>'A', 'A'=>'U')
# Replace characters using dictionary
map((x)->a_nucleotides[x], dna)
end

4 changes: 4 additions & 0 deletions exercises/rna-transcription/rna-transcription.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function to_rna(dna::AbstractString)

end

40 changes: 40 additions & 0 deletions exercises/rna-transcription/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using Base.Test

include("rna-transcription.jl")

@testset "basic transformations" begin
@testset "rna complement of cytosine is guanine" begin
@test to_rna("C") == "G"
end

@testset "rna complement of guanine is cytosine" begin
@test to_rna("G") == "C"
end

@testset "rna complement of thymine is adenine" begin
@test to_rna("T") == "A"
end

@testset "rna complement of adenine is uracil" begin
@test to_rna("A") == "U"
end
end

@testset "rna complement" begin
@test to_rna("ACGTGGTCTTAA") == "UGCACCAGAAUU"
end

@testset "error handling" begin
@testset "dna correctly handles invalid input" begin
@test_throws ErrorException to_rna("U")
end

@testset "dna correctly handles completely invalid input" begin
@test_throws ErrorException to_rna("XXX")
end

@testset "dna correctly handles partially invalid input" begin
@test_throws ErrorException to_rna("ACGTXXXCTTAA")
end
end

0 comments on commit 1b0fd4a

Please sign in to comment.