diff --git a/exercises/practice/protein-translation/.meta/example.jl b/exercises/practice/protein-translation/.meta/example.jl index 21d6a1d9..c151a6a9 100644 --- a/exercises/practice/protein-translation/.meta/example.jl +++ b/exercises/practice/protein-translation/.meta/example.jl @@ -26,7 +26,11 @@ macro rna_str(str) n = 3 result = [] for i=1:n:length(str) - substring = SubString(str, i, i+n-1) + substring = try + SubString(str, i, i+n-1) + catch + throw(TranslationError("invalid rna string")) + end protein = string_to_protein(substring) protein == "STOP" && break push!(result, protein) @@ -39,4 +43,4 @@ function string_to_protein(str) p = get(codon_protein_dict, str, nothing) p === nothing && throw(TranslationError("invalid codon")) return p -end \ No newline at end of file +end diff --git a/exercises/practice/protein-translation/runtests.jl b/exercises/practice/protein-translation/runtests.jl index e066ec86..0930b12f 100644 --- a/exercises/practice/protein-translation/runtests.jl +++ b/exercises/practice/protein-translation/runtests.jl @@ -55,7 +55,7 @@ include("protein-translation.jl") end @testset "Sequence of two different codons translates into proteins" begin - @test rna"UUAUUG" == ["Leucine", "Phenylalanine"] + @test rna"UUAUUU" == ["Leucine", "Phenylalanine"] end @testset "Translation stops if STOP codon appears in middle of sequence" begin @@ -71,11 +71,11 @@ include("protein-translation.jl") end @testset "Non existent codon causes translation exception" begin - @test_throws TranslationError rna"AAA" + @test_throws TranslationError @macroexpand rna"AAA" end @testset "Incomplete codon causes translation exception" begin - @test_throws TranslationError rna"UGGU" + @test_throws TranslationError @macroexpand rna"UGGU" end @testset "Incomplete RNA sequence can translate if given a stop codon" begin