|
1 | 1 | package dnacoder |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
4 | 5 | "testing" |
5 | 6 | ) |
6 | 7 |
|
7 | 8 | func TestEncode(t *testing.T) { |
8 | | - data := "Hello, DNA!" |
| 9 | + data := []byte{0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x44, 0x4e, 0x41, 0x21} // "Hello, DNA!" |
9 | 10 | expectedDNA := "GAGAGCACACGTATGATACATCTCTCTACGTCAGCTATATAGATCTCTGATCTGA" |
10 | 11 |
|
11 | 12 | encodedDNA := encode(data) |
12 | | - if encodedDNA != expectedDNA { |
| 13 | + if encodedDNA != expectedDNA { |
13 | 14 | t.Errorf("Encode(%s) = %s; want %s", data, encodedDNA, expectedDNA) |
14 | 15 | } |
15 | 16 | } |
16 | 17 |
|
17 | 18 | func TestDecode(t *testing.T) { |
18 | 19 | dnaSeq := "GAGAGCACACGTATGATACATCTCTCTACGTCAGCTATATAGATCTCTGATCTGA" |
19 | | - expectedString := "Hello, DNA!" |
| 20 | + expectedData := []byte{0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x44, 0x4e, 0x41, 0x21} // "Hello, DNA!" |
20 | 21 |
|
21 | | - decodedString, err := decode(dnaSeq) |
| 22 | + decodedData, err := decode(dnaSeq) |
22 | 23 | if err != nil { |
23 | 24 | t.Fatalf("Error decoding DNA sequence: %v", err) |
24 | 25 | } |
25 | 26 |
|
26 | | - if decodedString != expectedString { |
27 | | - t.Errorf("Decode(%s) = %s; want %s", dnaSeq, decodedString, expectedString) |
| 27 | + if !bytes.Equal(decodedData, expectedData) { |
| 28 | + t.Errorf("Decode(%s) = %s; want %s", dnaSeq, decodedData, expectedData) |
28 | 29 | } |
29 | 30 | } |
30 | 31 |
|
31 | 32 | func TestEncodeAndDecode(t *testing.T) { |
32 | | - data := "Test String" |
| 33 | + data := []byte{0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x2c, 0x20, 0x44, 0x4e, 0x41, 0x21} // "Hello, DNA!" |
33 | 34 |
|
34 | 35 | // Encode the string to DNA |
35 | 36 | encodedDNA := encode(data) |
36 | 37 |
|
37 | 38 | // Decode back to the original string |
38 | | - decodedString, err := decode(encodedDNA) |
| 39 | + decodedData, err := decode(encodedDNA) |
39 | 40 | if err != nil { |
40 | 41 | t.Fatalf("Error decoding DNA sequence: %v", err) |
41 | 42 | } |
42 | 43 |
|
43 | | - if decodedString != data { |
44 | | - t.Errorf("Encode and Decode mismatch: got %s, want %s", decodedString, data) |
| 44 | + if !bytes.Equal(decodedData, data) { |
| 45 | + t.Errorf("Encode and Decode mismatch: got %s, want %s", decodedData, data) |
45 | 46 | } |
46 | 47 | } |
0 commit comments