Fix up websocket locking.
[lightning.git] / tilelib_test.go
1 package main
2
3 import (
4         "bytes"
5
6         "gopkg.in/check.v1"
7 )
8
9 type tilelibSuite struct{}
10
11 var _ = check.Suite(&tilelibSuite{})
12
13 func (s *tilelibSuite) TestSkipOOO(c *check.C) {
14         var taglib tagLibrary
15         err := taglib.Load(bytes.NewBufferString(`>0000.00
16 ggagaactgtgctccgccttcaga
17 acacatgctagcgcgtcggggtgg
18 gactctagcagagtggccagccac
19 cctcccgagccgagccacccgtca
20 gttattaataataacttatcatca
21 `))
22         c.Assert(err, check.IsNil)
23
24         // tags appear in seq: 4, 0, 2 (but skipOOO is false)
25         tilelib := &tileLibrary{taglib: &taglib, skipOOO: false}
26         tseq, err := tilelib.TileFasta("test-label", bytes.NewBufferString(`>test-seq
27 gttattaataataacttatcatca
28 ggggggggggggggggggggggg
29 ggagaactgtgctccgccttcaga
30 cccccccccccccccccccc
31 gactctagcagagtggccagccac
32 `))
33         c.Assert(err, check.IsNil)
34         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{4, 1}, {0, 1}, {2, 1}}})
35
36         // tags appear in seq: 0, 1, 2 -> don't skip
37         tilelib = &tileLibrary{taglib: &taglib, skipOOO: true}
38         tseq, err = tilelib.TileFasta("test-label", bytes.NewBufferString(`>test-seq
39 ggagaactgtgctccgccttcaga
40 cccccccccccccccccccc
41 acacatgctagcgcgtcggggtgg
42 ggggggggggggggggggggggg
43 gactctagcagagtggccagccac
44 `))
45         c.Assert(err, check.IsNil)
46         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{0, 1}, {1, 1}, {2, 1}}})
47
48         // tags appear in seq: 2, 3, 4 -> don't skip
49         tilelib = &tileLibrary{taglib: &taglib, skipOOO: true}
50         tseq, err = tilelib.TileFasta("test-label", bytes.NewBufferString(`>test-seq
51 gactctagcagagtggccagccac
52 cccccccccccccccccccc
53 cctcccgagccgagccacccgtca
54 ggggggggggggggggggggggg
55 gttattaataataacttatcatca
56 `))
57         c.Assert(err, check.IsNil)
58         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{2, 1}, {3, 1}, {4, 1}}})
59
60         // tags appear in seq: 4, 0, 2 -> skip 4
61         tilelib = &tileLibrary{taglib: &taglib, skipOOO: true}
62         tseq, err = tilelib.TileFasta("test-label", bytes.NewBufferString(`>test-seq
63 gttattaataataacttatcatca
64 cccccccccccccccccccc
65 ggagaactgtgctccgccttcaga
66 ggggggggggggggggggggggg
67 gactctagcagagtggccagccac
68 `))
69         c.Assert(err, check.IsNil)
70         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{0, 1}, {2, 1}}})
71
72         // tags appear in seq: 0, 2, 1 -> skip 2
73         tilelib = &tileLibrary{taglib: &taglib, skipOOO: true}
74         tseq, err = tilelib.TileFasta("test-label", bytes.NewBufferString(`>test-seq
75 ggagaactgtgctccgccttcaga
76 cccccccccccccccccccc
77 gactctagcagagtggccagccac
78 ggggggggggggggggggggggg
79 acacatgctagcgcgtcggggtgg
80 `))
81         c.Assert(err, check.IsNil)
82         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{0, 1}, {1, 1}}})
83
84         // tags appear in seq: 0, 1, 1, 2 -> skip second tag1
85         tilelib = &tileLibrary{taglib: &taglib, skipOOO: true}
86         tseq, err = tilelib.TileFasta("test-label", bytes.NewBufferString(`>test-seq
87 ggagaactgtgctccgccttcaga
88 cccccccccccccccccccc
89 acacatgctagcgcgtcggggtgg
90 ggggggggggggggggggggggg
91 acacatgctagcgcgtcggggtgg
92 ggggggggggggggggggggggg
93 gactctagcagagtggccagccac
94 `))
95         c.Assert(err, check.IsNil)
96         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{0, 1}, {1, 1}, {2, 1}}})
97
98         // tags appear in seq: 0, 1, 3 -> don't skip
99         tilelib = &tileLibrary{taglib: &taglib, skipOOO: true}
100         tseq, err = tilelib.TileFasta("test-label", bytes.NewBufferString(`>test-seq
101 ggagaactgtgctccgccttcaga
102 cccccccccccccccccccc
103 acacatgctagcgcgtcggggtgg
104 ggggggggggggggggggggggg
105 cctcccgagccgagccacccgtca
106 `))
107         c.Assert(err, check.IsNil)
108         c.Check(tseq, check.DeepEquals, tileSeq{"test-seq": []tileLibRef{{0, 1}, {1, 1}, {3, 1}}})
109 }