What about this function is wrong ?
@spec of_rna(String.t()) :: {atom, list(String.t())}
def of_rna(rna) do
data = rna |> String.codepoints
|> Enum.chunk_every(3)
|> Enum.map(fn(x) -> Enum.join(x) end)
do_rna(data, [])
end
def do_rna([head | tail] , Result) do
case @proteins[head] do
STOP -> {:ok, Result}
_ -> do_rna(tail, Result ++ [@proteins[head]])
end
end
The test I am using is:
test "stops translation if stop codon present" do
strand = "AUGUUUUAA"
assert ProteinTranslation.of_rna(strand) == {:ok, ~w(Methionine Phenylalanine)}
end
The error I am seeing is:
1) test stops translation if stop codon present (ProteinTranslationTest)
protein_translation_test.exs:67
** (FunctionClauseError) no function clause matching in ProteinTranslation.do_rna/2
The following arguments were given to ProteinTranslation.do_rna/2:
# 1
["AUG", "UUU", "UAA"]
# 2
[]
code: assert ProteinTranslation.of_rna(strand) == {:ok, ~w(Methionine Phenylalanine)}
stacktrace:
protein_translation.exs:37: ProteinTranslation.do_rna/2
protein_translation_test.exs:69: (test)
I don't understand why the function call does not match. Please help.
Result
in the second argument ofdo_rna/2
. That is an atom in Elixir. – Justin Wood