-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdnacoder_test.go
More file actions
47 lines (37 loc) · 1.33 KB
/
dnacoder_test.go
File metadata and controls
47 lines (37 loc) · 1.33 KB
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
package dnacoder
import (
"bytes"
"testing"
)
func TestEncode(t *testing.T) {
data := []byte{0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x44, 0x4e, 0x41, 0x21} // "Hello, DNA!"
expectedDNA := "GAGAGCACACGTATGATACATCTCTCTACGTCAGCTATATAGATCTCTGATCTGA"
encodedDNA := encode(data)
if encodedDNA != expectedDNA {
t.Errorf("Encode(%s) = %s; want %s", data, encodedDNA, expectedDNA)
}
}
func TestDecode(t *testing.T) {
dnaSeq := "GAGAGCACACGTATGATACATCTCTCTACGTCAGCTATATAGATCTCTGATCTGA"
expectedData := []byte{0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x44, 0x4e, 0x41, 0x21} // "Hello, DNA!"
decodedData, err := decode(dnaSeq)
if err != nil {
t.Fatalf("Error decoding DNA sequence: %v", err)
}
if !bytes.Equal(decodedData, expectedData) {
t.Errorf("Decode(%s) = %s; want %s", dnaSeq, decodedData, expectedData)
}
}
func TestEncodeAndDecode(t *testing.T) {
data := []byte{0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x44, 0x4e, 0x41, 0x21} // "Hello, DNA!"
// Encode the string to DNA
encodedDNA := encode(data)
// Decode back to the original string
decodedData, err := decode(encodedDNA)
if err != nil {
t.Fatalf("Error decoding DNA sequence: %v", err)
}
if !bytes.Equal(decodedData, data) {
t.Errorf("Encode and Decode mismatch: got %s, want %s", decodedData, data)
}
}