Continue loop a bit earlier.
[lightning.git] / tilelib_test.go
1 package main
2
3 import (
4         "bytes"
5         "strings"
6
7         "gopkg.in/check.v1"
8 )
9
10 type tilelibSuite struct {
11         tag    []string
12         taglib tagLibrary
13 }
14
15 var _ = check.Suite(&tilelibSuite{})
16
17 func (s *tilelibSuite) SetUpSuite(c *check.C) {
18         fasta := `>0000.00
19 ggagaactgtgctccgccttcaga
20 acacatgctagcgcgtcggggtgg
21 gactctagcagagtggccagccac
22 cctcccgagccgagccacccgtca
23 gttattaataataacttatcatca
24 `
25         err := s.taglib.Load(bytes.NewBufferString(fasta))
26         c.Assert(err, check.IsNil)
27         for _, seq := range strings.Split(fasta, "\n") {
28                 if len(seq) > 0 && seq[0] != '>' {
29                         s.tag = append(s.tag, seq+"\n")
30                 }
31         }
32 }
33
34 func (s *tilelibSuite) TestSkipOOO(c *check.C) {
35         // tags appear in seq: 4, 0, 2 (but skipOOO is false)
36         tilelib := &tileLibrary{taglib: &s.taglib, skipOOO: false}
37         tseq, _, err := tilelib.TileFasta("test-label", bytes.NewBufferString(">test-seq\n"+
38                 s.tag[4]+
39                 "ggggggggggggggggggggggg\n"+
40                 s.tag[0]+
41                 "cccccccccccccccccccc\n"+
42                 s.tag[2]+
43                 "\n"))
44         c.Assert(err, check.IsNil)
45         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{4, 1}, {0, 1}, {2, 1}}})
46
47         // tags appear in seq: 0, 1, 2 -> don't skip
48         tilelib = &tileLibrary{taglib: &s.taglib, skipOOO: true}
49         tseq, _, err = tilelib.TileFasta("test-label", bytes.NewBufferString(">test-seq\n"+
50                 s.tag[0]+
51                 "cccccccccccccccccccc\n"+
52                 s.tag[1]+
53                 "ggggggggggggggggggggggg\n"+
54                 s.tag[2]+
55                 "\n"))
56         c.Assert(err, check.IsNil)
57         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{0, 1}, {1, 1}, {2, 1}}})
58
59         // tags appear in seq: 2, 3, 4 -> don't skip
60         tilelib = &tileLibrary{taglib: &s.taglib, skipOOO: true}
61         tseq, _, err = tilelib.TileFasta("test-label", bytes.NewBufferString(">test-seq\n"+
62                 s.tag[2]+
63                 "cccccccccccccccccccc\n"+
64                 s.tag[3]+
65                 "ggggggggggggggggggggggg\n"+
66                 s.tag[4]+
67                 "\n"))
68         c.Assert(err, check.IsNil)
69         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{2, 1}, {3, 1}, {4, 1}}})
70
71         // tags appear in seq: 4, 0, 2 -> skip 4
72         tilelib = &tileLibrary{taglib: &s.taglib, skipOOO: true}
73         tseq, _, err = tilelib.TileFasta("test-label", bytes.NewBufferString(">test-seq\n"+
74                 s.tag[4]+
75                 "cccccccccccccccccccc\n"+
76                 s.tag[0]+
77                 "ggggggggggggggggggggggg\n"+
78                 s.tag[2]+
79                 "\n"))
80         c.Assert(err, check.IsNil)
81         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{0, 1}, {2, 1}}})
82
83         // tags appear in seq: 0, 2, 1 -> skip 2
84         tilelib = &tileLibrary{taglib: &s.taglib, skipOOO: true}
85         tseq, _, err = tilelib.TileFasta("test-label", bytes.NewBufferString(">test-seq\n"+
86                 s.tag[0]+
87                 "cccccccccccccccccccc\n"+
88                 s.tag[2]+
89                 "ggggggggggggggggggggggg\n"+
90                 s.tag[1]+
91                 "\n"))
92         c.Assert(err, check.IsNil)
93         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{0, 1}, {1, 1}}})
94
95         // tags appear in seq: 0, 1, 1, 2 -> skip second tag1
96         tilelib = &tileLibrary{taglib: &s.taglib, skipOOO: true}
97         tseq, _, err = tilelib.TileFasta("test-label", bytes.NewBufferString(">test-seq\n"+
98                 s.tag[0]+
99                 "cccccccccccccccccccc\n"+
100                 s.tag[1]+
101                 "ggggggggggggggggggggggg\n"+
102                 s.tag[1]+
103                 "ggggggggggggggggggggggg\n"+
104                 s.tag[2]+
105                 "\n"))
106         c.Assert(err, check.IsNil)
107         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{0, 1}, {1, 1}, {2, 1}}})
108
109         // tags appear in seq: 0, 1, 3, 0, 4 -> skip second tag0
110         tilelib = &tileLibrary{taglib: &s.taglib, skipOOO: true}
111         tseq, _, err = tilelib.TileFasta("test-label", bytes.NewBufferString(">test-seq\n"+
112                 s.tag[0]+
113                 "cccccccccccccccccccc\n"+
114                 s.tag[1]+
115                 "ggggggggggggggggggggggg\n"+
116                 s.tag[3]+
117                 "ggggggggggggggggggggggg\n"+
118                 s.tag[0]+
119                 "ggggggggggggggggggggggg\n"+
120                 s.tag[4]+
121                 "\n"))
122         c.Assert(err, check.IsNil)
123         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{0, 1}, {1, 1}, {3, 1}, {4, 1}}})
124
125         // tags appear in seq: 0, 1, 3 -> don't skip
126         tilelib = &tileLibrary{taglib: &s.taglib, skipOOO: true}
127         tseq, _, err = tilelib.TileFasta("test-label", bytes.NewBufferString(">test-seq\n"+
128                 s.tag[0]+
129                 "cccccccccccccccccccc\n"+
130                 s.tag[1]+
131                 "ggggggggggggggggggggggg\n"+
132                 s.tag[3]+
133                 "\n"))
134         c.Assert(err, check.IsNil)
135         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{0, 1}, {1, 1}, {3, 1}}})
136 }