Merge branch 'main' into 19868-pca-in-ml
[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:      "aGACGGACAGGGCCCggatgcaa",
197                         b:      "aggatgcaa",
198                         expect: []string{"2_15del"},
199                 },
200                 {
201                         a:      "aGACGGACAGGGCCCgt",
202                         b:      "agt",
203                         expect: []string{"2_15del"},
204                 },
205                 {
206                         a:      "aGACGGACAGGGCCCgacggacagggccctag",
207                         b:      "agacggacagggccctag",
208                         expect: []string{"2_15del"},
209                 },
210                 {
211                         a:      "cagacggacgtggggacccaGACGGACAGGGCCCggtaacc",
212                         b:      "cagacggacgtggggacccaggtaacc",
213                         expect: []string{"21_34del"},
214                 },
215                 {
216                         a:      "cagacggacgtggggacccaggtaacc",
217                         b:      "cagacggacgtggggacccaGACGGACAGGGCCCggtaacc",
218                         expect: []string{"20_21insGACGGACAGGGCCC"},
219                 },
220                 {
221                         a:      "aggGac",
222                         b:      "aggAac",
223                         expect: []string{"4G>A"},
224                 },
225                 {
226                         a:      "atttTc",
227                         b:      "atttCc",
228                         expect: []string{"5T>C"},
229                 },
230                 {
231                         a:      "atatataTAcgcgaa",
232                         b:      "atatataCGcgcgaa",
233                         expect: []string{"8T>C", "9A>G"},
234                 },
235                 {
236                         a:      "gtaacccc",
237                         b:      "gTAAtaacccc",
238                         expect: []string{"1_2insTAA"},
239                 },
240                 {
241                         a:      "cttaaa",
242                         b:      "cTTCGttaaa",
243                         expect: []string{"1_2insTTCG"},
244                 },
245                 {
246                         a:      "tCAACAggg",
247                         b:      "tCAggg",
248                         expect: []string{"2_4del"},
249                 },
250                 {
251                         a:      "caaAc",
252                         b:      "caaCc",
253                         expect: []string{"4A>C"},
254                 },
255                 {
256                         a:      "aGGgaca",
257                         b:      "agaca",
258                         expect: []string{"2_3del"},
259                 },
260         } {
261                 c.Log(trial)
262                 var vars []string
263                 diffs, _ := Diff(strings.ToUpper(trial.a), strings.ToUpper(trial.b), 0)
264                 c.Logf("%v", diffs)
265                 for _, v := range diffs {
266                         vars = append(vars, v.String())
267                 }
268                 c.Check(vars, check.DeepEquals, trial.expect)
269         }
270 }