Skip to content

Commit

Permalink
fixed example to pass tests
Browse files Browse the repository at this point in the history
  • Loading branch information
golanor committed Jan 30, 2024
1 parent a06f438 commit 7bbbe61
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
8 changes: 6 additions & 2 deletions exercises/practice/protein-translation/.meta/example.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
end
6 changes: 3 additions & 3 deletions exercises/practice/protein-translation/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 7bbbe61

Please sign in to comment.