1
exercism fetch go protein-translation

protein_translation_test.go

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
package protein

import (
	"reflect"
	"testing"
)

type codonCase struct {
	input    string
	expected string
}

var codonTestCases = []codonCase{
	{"AUG", "Methionine"},
	{"UUU", "Phenylalanine"},
	{"UUC", "Phenylalanine"},
	{"UUA", "Leucine"},
	{"UUG", "Leucine"},
	{"UCU", "Serine"},
	{"UCC", "Serine"},
	{"UCA", "Serine"},
	{"UCG", "Serine"},
	{"UAU", "Tyrosine"},
	{"UAC", "Tyrosine"},
	{"UGU", "Cysteine"},
	{"UGC", "Cysteine"},
	{"UGG", "Tryptophan"},
	{"UAA", "STOP"},
	{"UAG", "STOP"},
	{"UGA", "STOP"},
}

type rnaCase struct {
	input    string
	expected []string
}

var proteinTestCases = []rnaCase{
	{"AUGUUUUCUUAAAUG", []string{"Methionine", "Phenylalanine", "Serine"}},
	{"AUGUUUUGG", []string{"Methionine", "Phenylalanine", "Tryptophan"}},
	{"AUGUUUUAA", []string{"Methionine", "Phenylalanine"}},
	{"UGGUGUUAUUAAUGGUUU", []string{"Tryptophan", "Cysteine", "Tyrosine"}},
}

func TestCodon(t *testing.T) {
	for _, test := range codonTestCases {
		actual := FromCodon(test.input)
		if actual != test.expected {
			t.Errorf("Protein Translation test [%s], expected [%s], actual [%s]", test.input, test.expected, actual)
		}
	}
}

func TestProtein(t *testing.T) {
	for _, test := range proteinTestCases {
		actual := FromRNA(test.input)
		if !reflect.DeepEqual(actual, test.expected) {
			t.Errorf("Protein Translation test [%s], expected %q, actual %q", test.input, test.expected, actual)
		}
	}
}