Fix diff case
[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{"3G>C", "4G>C", "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{"3G>A", "4G>A"},
77                 },
78                 {
79                         // without cleanup, diffmatchpatch solves this as {"3_4del", "=A", "5_6insCA"}
80                         a:      "agggaggggg",
81                         b:      "agACaggggg",
82                         expect: []string{"3G>A", "4G>C"},
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{"3G>C", "4G>A"},
100                 },
101                 {
102                         a:      "agggg",
103                         b:      "agAAg",
104                         expect: []string{"3G>A", "4G>A"},
105                 },
106                 {
107                         a:      "aggggg",
108                         b:      "agAAAg",
109                         expect: []string{"3_5delinsAAA"},
110                 },
111                 {
112                         a:      "acgtgaa",
113                         b:      "acTtgaa",
114                         expect: []string{"3G>T"},
115                 },
116                 {
117                         a:      "tcagaagac",
118                         b:      "tcaAaagac",
119                         expect: []string{"4G>A"},
120                 },
121                 {
122                         a:      "tcagatggac",
123                         b:      "tcaAaCggac",
124                         expect: []string{"4G>A", "6T>C"},
125                 },
126                 {
127                         a:      "tcagatggac",
128                         b:      "tcaAaCggTc",
129                         expect: []string{"4G>A", "6T>C", "9A>T"},
130                 },
131                 {
132                         a:      "tcagatggac",
133                         b:      "tcaAaCCggTc",
134                         expect: []string{"4G>A", "6delinsCC", "9A>T"},
135                 },
136                 {
137                         a:      "tcatagagac",
138                         b:      "tcacaagac",
139                         expect: []string{"4T>C", "6del"},
140                 },
141                 {
142                         a:      "tcatcgagac",
143                         b:      "tcGCcgagac",
144                         expect: []string{"3A>G", "4T>C"},
145                 },
146                 {
147                         a:      "tcatcgagac",
148                         b:      "tcGCcggac",
149                         expect: []string{"3A>G", "4T>C", "7del"},
150                 },
151                 {
152                         // should delete leftmost
153                         a:      "acgacaTTtttacac",
154                         b:      "acgacatttacac",
155                         expect: []string{"7_8del"},
156                 },
157                 {
158                         // should delete leftmost
159                         a:      "acgacATatatacac",
160                         b:      "acgacatatacac",
161                         expect: []string{"6_7del"},
162                 },
163                 {
164                         // should insert leftmost
165                         a:      "acgacatttacac",
166                         b:      "acgacaTTtttacac",
167                         expect: []string{"6_7insTT"},
168                 },
169                 {
170                         // should insert leftmost
171                         a:      "acgacatatacac",
172                         b:      "acgacATatatacac",
173                         expect: []string{"5_6insAT"},
174                 },
175                 {
176                         a:      "cccacGATAtatcc",
177                         b:      "cccactatcc",
178                         expect: []string{"6_9del"},
179                 },
180                 {
181                         a:      "acGATAtatcc",
182                         b:      "actatcc",
183                         expect: []string{"3_6del"},
184                 },
185                 {
186                         a:      "acTTTTTatcc",
187                         b:      "acGTTTatcc",
188                         expect: []string{"3_4delinsG"},
189                 },
190                 {
191                         a:      "acTTTTatcc",
192                         b:      "acGTTTTTatcc",
193                         expect: []string{"2_3insGT"},
194                 },
195                 {
196                         a:      "aGACGGACAGGGCCCgg",
197                         b:      "agg",
198                         expect: []string{"3_15del"},
199                 },
200                 {
201                         a:      "aggGac",
202                         b:      "aggAac",
203                         expect: []string{"4G>A"},
204                 },
205                 {
206                         a:      "atttTc",
207                         b:      "atttCc",
208                         expect: []string{"5T>C"},
209                 },
210                 {
211                         a:      "atatataTAcgcgaa",
212                         b:      "atatataCGcgcgaa",
213                         expect: []string{"8T>C", "9A>G"},
214                 },
215                 {
216                         a:      "gtaacccc",
217                         b:      "gTAAtaacccc",
218                         expect: []string{"1_2insTAA"},
219                 },
220                 {
221                         a:      "cttaaa",
222                         b:      "cTTCGttaaa",
223                         expect: []string{"1_2insTTCG"},
224                 },
225         } {
226                 c.Log(trial)
227                 var vars []string
228                 diffs, _ := Diff(strings.ToUpper(trial.a), strings.ToUpper(trial.b), 0)
229                 for _, v := range diffs {
230                         vars = append(vars, v.String())
231                 }
232                 c.Check(vars, check.DeepEquals, trial.expect)
233         }
234 }