1
exercism fetch elixir protein-translation

protein_translation_test.exs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
if !System.get_env("EXERCISM_TEST_EXAMPLES") do
  Code.load_file("protein_translation.exs", __DIR__)
end

ExUnit.start()
ExUnit.configure(exclude: :pending, trace: true)

defmodule ProteinTranslationTest do
  use ExUnit.Case

  # @tag :pending
  test "AUG translates to methionine" do
    assert ProteinTranslation.of_codon("AUG") == {:ok, "Methionine"}
  end

  @tag :pending
  test "identifies Phenylalanine codons" do
    assert ProteinTranslation.of_codon("UUU") == {:ok, "Phenylalanine"}
    assert ProteinTranslation.of_codon("UUC") == {:ok, "Phenylalanine"}
  end

  @tag :pending
  test "identifies Leucine codons" do
    assert ProteinTranslation.of_codon("UUA") == {:ok, "Leucine"}
    assert ProteinTranslation.of_codon("UUG") == {:ok, "Leucine"}
  end

  @tag :pending
  test "identifies Serine codons" do
    assert ProteinTranslation.of_codon("UCU") == {:ok, "Serine"}
    assert ProteinTranslation.of_codon("UCC") == {:ok, "Serine"}
    assert ProteinTranslation.of_codon("UCA") == {:ok, "Serine"}
    assert ProteinTranslation.of_codon("UCG") == {:ok, "Serine"}
  end

  @tag :pending
  test "identifies Tyrosine codons" do
    assert ProteinTranslation.of_codon("UAU") == {:ok, "Tyrosine"}
    assert ProteinTranslation.of_codon("UAC") == {:ok, "Tyrosine"}
  end

  @tag :pending
  test "identifies Cysteine codons" do
    assert ProteinTranslation.of_codon("UGU") == {:ok, "Cysteine"}
    assert ProteinTranslation.of_codon("UGC") == {:ok, "Cysteine"}
  end

  @tag :pending
  test "identifies Tryptophan codons" do
    assert ProteinTranslation.of_codon("UGG") == {:ok, "Tryptophan"}
  end

  @tag :pending
  test "identifies stop codons" do
    assert ProteinTranslation.of_codon("UAA") == {:ok, "STOP"}
    assert ProteinTranslation.of_codon("UAG") == {:ok, "STOP"}
    assert ProteinTranslation.of_codon("UGA") == {:ok, "STOP"}
  end

  @tag :pending
  test "translates rna strand into correct protein" do
    strand = "AUGUUUUGG"
    assert ProteinTranslation.of_rna(strand) == {:ok, ~w(Methionine Phenylalanine Tryptophan)}
  end

  @tag :pending
  test "stops translation if stop codon present" do
    strand = "AUGUUUUAA"
    assert ProteinTranslation.of_rna(strand) == {:ok, ~w(Methionine Phenylalanine)}
  end

  @tag :pending
  test "stops translation of longer strand" do
    strand = "UGGUGUUAUUAAUGGUUU"
    assert ProteinTranslation.of_rna(strand) == {:ok, ~w(Tryptophan Cysteine Tyrosine)}
  end

  @tag :pending
  test "invalid RNA" do
    assert ProteinTranslation.of_rna("CARROT") == {:error, "invalid RNA"}
  end

  @tag :pending
  test "invalid codon at end of RNA" do
    assert ProteinTranslation.of_rna("UUUROT") == {:error, "invalid RNA"}
  end

  @tag :pending
  test "invalid codon" do
    assert ProteinTranslation.of_codon("INVALID") == {:error, "invalid codon"}
  end
end