diff --git a/config.json b/config.json index 3f16ab1e7bfaf..ed6424a3b3a70 100644 --- a/config.json +++ b/config.json @@ -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, diff --git a/exercises/rna-transcription/example.jl b/exercises/rna-transcription/example.jl new file mode 100644 index 0000000000000..06f5d63bbde46 --- /dev/null +++ b/exercises/rna-transcription/example.jl @@ -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 + diff --git a/exercises/rna-transcription/rna-transcription.jl b/exercises/rna-transcription/rna-transcription.jl new file mode 100644 index 0000000000000..d9a8366968a79 --- /dev/null +++ b/exercises/rna-transcription/rna-transcription.jl @@ -0,0 +1,4 @@ +function to_rna(dna::AbstractString) + +end + diff --git a/exercises/rna-transcription/runtests.jl b/exercises/rna-transcription/runtests.jl new file mode 100644 index 0000000000000..5e4f9c43342aa --- /dev/null +++ b/exercises/rna-transcription/runtests.jl @@ -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 +