16 func Test(t *testing.T) { check.TestingT(t) }
18 type taglibSuite struct{}
20 var _ = check.Suite(&taglibSuite{})
22 func (s *taglibSuite) TestFindAllTinyData(c *check.C) {
23 pr, pw, err := os.Pipe()
24 c.Assert(err, check.IsNil)
27 fmt.Fprintf(pw, `>0000.00
28 ggagaactgtgctccgccttcaga
29 acacatgctagcgcgtcggggtgg
30 gactctagcagagtggccagccac
35 c.Assert(err, check.IsNil)
36 haystack := []byte(`ggagaactgtgctccgccttcagaccccccccccccccccccccacacatgctagcgcgtcggggtgggggggggggggggggggggggggggactctagcagagtggccagccac`)
37 var matches []tagMatch
38 taglib.FindAll(haystack, func(id tagID, pos int) {
39 matches = append(matches, tagMatch{id, pos})
41 c.Check(matches, check.DeepEquals, []tagMatch{{0, 0}, {1, 44}, {2, 92}})
44 func (s *taglibSuite) TestFindAllRealisticSize(c *check.C) {
46 acgt := []byte{'a', 'c', 'g', 't'}
47 haystack := make([]byte, 25000000) // ~1/2 smallest human chromosome
48 c.Logf("@%v haystack", time.Since(start))
50 for i := range haystack {
51 haystack[i] = acgt[int(haystack[i]&3)]
60 w := bufio.NewWriter(pw)
62 used := map[string]bool{}
63 fmt.Fprint(w, ">000\n")
64 for i := 0; len(tags) < tagcount; i += (len(haystack) - tagsize) / tagcount {
66 tag := haystack[i : i+tagsize]
67 for used[string(tag)] {
69 tag = haystack[i : i+tagsize]
71 used[string(tag)] = true
72 tags = append(tags, strings.ToLower(string(tag)))
77 c.Logf("@%v build library", time.Since(start))
79 err := taglib.Load(pr)
80 c.Assert(err, check.IsNil)
81 c.Logf("@%v find tags in input", time.Since(start))
82 var matches []tagMatch
83 taglib.FindAll(haystack, func(id tagID, pos int) {
84 matches = append(matches, tagMatch{id, pos})
86 c.Logf("@%v done", time.Since(start))
87 c.Check(matches[0], check.Equals, tagMatch{0, 0})
88 c.Check(matches[1].id, check.Equals, tagID(1))