16 func Test(t *testing.T) { check.TestingT(t) }
18 type taglibSuite struct{}
20 var _ = check.Suite(&taglibSuite{})
22 type tagMatch struct {
28 func (s *taglibSuite) TestFindAllTinyData(c *check.C) {
29 pr, pw, err := os.Pipe()
30 c.Assert(err, check.IsNil)
33 fmt.Fprintf(pw, `>0000.00
34 ggagaactgtgctccgccttcaga
35 acacatgctagcgcgtcggggtgg
36 gactctagcagagtggccagccac
41 c.Assert(err, check.IsNil)
42 haystack := []byte(`ggagaactgtgctccgccttcagaccccccccccccccccccccacacatgctagcgcgtcggggtgggggggggggggggggggggggggggactctagcagagtggccagccac`)
43 var matches []tagMatch
44 taglib.FindAll(haystack, func(id tagID, pos, taglen int) {
45 matches = append(matches, tagMatch{id, pos, taglen})
47 c.Check(matches, check.DeepEquals, []tagMatch{{0, 0, 24}, {1, 44, 24}, {2, 92, 24}})
50 func (s *taglibSuite) TestFindAllRealisticSize(c *check.C) {
52 acgt := []byte{'a', 'c', 'g', 't'}
53 haystack := make([]byte, 25000000) // ~1/2 smallest human chromosome
54 c.Logf("@%v haystack", time.Since(start))
56 for i := range haystack {
57 haystack[i] = acgt[int(haystack[i]&3)]
66 w := bufio.NewWriter(pw)
68 used := map[string]bool{}
69 fmt.Fprint(w, ">000\n")
70 for i := 0; len(tags) < tagcount; i += (len(haystack) - tagsize) / tagcount {
72 tag := haystack[i : i+tagsize]
73 for used[string(tag)] {
75 tag = haystack[i : i+tagsize]
77 used[string(tag)] = true
78 tags = append(tags, strings.ToLower(string(tag)))
83 c.Logf("@%v build library", time.Since(start))
85 err := taglib.Load(pr)
86 c.Assert(err, check.IsNil)
87 c.Logf("@%v find tags in input", time.Since(start))
88 var matches []tagMatch
89 taglib.FindAll(haystack, func(id tagID, pos, taglen int) {
90 matches = append(matches, tagMatch{id, pos, taglen})
92 c.Logf("@%v done", time.Since(start))
93 c.Check(matches[0], check.Equals, tagMatch{0, 0, tagsize})
94 c.Check(matches[1].id, check.Equals, tagID(1))