Improve logging.
[lightning.git] / hgvs / diff_test.go
1 // Copyright (C) The Lightning Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package hgvs
6
7 import (
8         "strings"
9         "testing"
10
11         "gopkg.in/check.v1"
12 )
13
14 func Test(t *testing.T) { check.TestingT(t) }
15
16 type diffSuite struct{}
17
18 var _ = check.Suite(&diffSuite{})
19
20 func (s *diffSuite) TestDiff(c *check.C) {
21         for _, trial := range []struct {
22                 a      string
23                 b      string
24                 expect []string
25         }{
26                 {
27                         a:      "aaaaaaaaaa",
28                         b:      "aaaaCaaaaa",
29                         expect: []string{"5A>C"},
30                 },
31                 {
32                         a:      "aaaacGcaaa",
33                         b:      "aaaaccaaa",
34                         expect: []string{"6del"},
35                 },
36                 {
37                         a:      "aaaacGGcaaa",
38                         b:      "aaaaccaaa",
39                         expect: []string{"6_7del"},
40                 },
41                 {
42                         a:      "aaaac",
43                         b:      "aaaa",
44                         expect: []string{"5del"},
45                 },
46                 {
47                         a:      "aaaa",
48                         b:      "aaCaa",
49                         expect: []string{"2_3insC"},
50                 },
51                 {
52                         a:      "aaGGGtt",
53                         b:      "aaCCCtt",
54                         expect: []string{"3_5delinsCCC"},
55                 },
56                 {
57                         a:      "aa",
58                         b:      "aaCCC",
59                         expect: []string{"2_3insCCC"},
60                 },
61                 {
62                         a:      "aaGGttAAtttt",
63                         b:      "aaCCttttttC",
64                         expect: []string{"3_4delinsCC", "7_8del", "12_13insC"},
65                 },
66                 {
67                         // without cleanup, diffmatchpatch solves this as {"3del", "=A", "4_5insA"}
68                         a:      "aggaggggg",
69                         b:      "agAaggggg",
70                         expect: []string{"3G>A"},
71                 },
72                 {
73                         // without cleanup, diffmatchpatch solves this as {"3_4del", "=A", "5_6insAA"}
74                         a:      "agggaggggg",
75                         b:      "agAAaggggg",
76                         expect: []string{"3_4delinsAA"},
77                 },
78                 {
79                         // without cleanup, diffmatchpatch solves this as {"3_4del", "=A", "5_6insCA"}
80                         a:      "agggaggggg",
81                         b:      "agACaggggg",
82                         expect: []string{"3_4delinsAC"},
83                 },
84                 {
85                         // without cleanup, diffmatchpatch solves this as {"3_7del", "=A", "8_9insAAACA"}
86                         a:      "aggggggaggggg",
87                         b:      "agAAAACaggggg",
88                         expect: []string{"3_7delinsAAAAC"},
89                 },
90                 {
91                         // without cleanup, diffmatchpatch solves this as {"3_7del", "=AAAA", "11_12insCAAAA"}
92                         a:      "aggggggaaaaggggg",
93                         b:      "agAAAACaaaaggggg",
94                         expect: []string{"3_7delinsAAAAC"},
95                 },
96                 {
97                         a:      "agggaggggg",
98                         b:      "agCAaggggg",
99                         expect: []string{"3_4delinsCA"},
100                 },
101                 {
102                         a:      "agggg",
103                         b:      "agAAg",
104                         expect: []string{"3_4delinsAA"},
105                 },
106                 {
107                         a:      "acgtgaa",
108                         b:      "acTtgaa",
109                         expect: []string{"3G>T"},
110                 },
111                 {
112                         a:      "tcagaagac",
113                         b:      "tcaAaagac",
114                         expect: []string{"4G>A"},
115                 },
116         } {
117                 c.Log(trial)
118                 var vars []string
119                 diffs, _ := Diff(strings.ToUpper(trial.a), strings.ToUpper(trial.b), 0)
120                 for _, v := range diffs {
121                         vars = append(vars, v.String())
122                 }
123                 c.Check(vars, check.DeepEquals, trial.expect)
124         }
125 }