File: test_stree_iterators.h

package info (click to toggle)
seqan2 2.4.0+dfsg-11~bpo9+1
  • links: PTS, VCS
  • area: main
  • in suites: stretch-backports
  • size: 223,500 kB
  • sloc: cpp: 256,886; ansic: 91,672; python: 8,339; sh: 995; xml: 570; makefile: 251; awk: 51
file content (772 lines) | stat: -rw-r--r-- 24,381 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
// ==========================================================================
//                 SeqAn - The Library for Sequence Analysis
// ==========================================================================
// Copyright (c) 2006-2018, Knut Reinert, FU Berlin
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
//     * Redistributions of source code must retain the above copyright
//       notice, this list of conditions and the following disclaimer.
//     * Redistributions in binary form must reproduce the above copyright
//       notice, this list of conditions and the following disclaimer in the
//       documentation and/or other materials provided with the distribution.
//     * Neither the name of Knut Reinert or the FU Berlin nor the names of
//       its contributors may be used to endorse or promote products derived
//       from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
// DAMAGE.
//
// ==========================================================================
// Author: David Weese <david.weese@fu-berlin.de>
// ==========================================================================

#ifndef TESTS_INDEX_TEST_STREE_ITERATORS_H
#define TESTS_INDEX_TEST_STREE_ITERATORS_H


//////////////////////////////////////////////////////////////////////////////

namespace seqan
{

SEQAN_DEFINE_TEST(testEmptyIndex)
{
    typedef String<Dna5> TString;
    typedef Index<TString> TIndex;

    TIndex index;

    Iterator<TIndex, TopDown<> >::Type iterator(index);

}

SEQAN_DEFINE_TEST(testIssue509)
{
    // goDown causes assertion on small index #509
    // Originally by John on Trac
    typedef String<Dna5> TString;
    typedef StringSet<TString> TStrings;
    typedef Index<TStrings> TIndex;

    TStrings seqs;
    TString seq("A");
    appendValue(seqs, seq);
    TIndex index(seqs);

    Iterator<TIndex, TopDown<> >::Type iterator(index);
    SEQAN_ASSERT(isRoot(iterator));
    SEQAN_ASSERT_NOT(isLeaf(iterator));

    SEQAN_ASSERT(goDown(iterator));
    SEQAN_ASSERT_NOT(isRoot(iterator));
    SEQAN_ASSERT(isLeaf(iterator));

    goRoot(iterator);
    SEQAN_ASSERT(isRoot(iterator));
    SEQAN_ASSERT_NOT(isLeaf(iterator));
    SEQAN_ASSERT(goDown(iterator, seq));
}

SEQAN_DEFINE_TEST(testIssue509b)
{
    // goDown causes assertion on small index #509
    // Originally by John on Trac
    typedef String<Dna5> TString;
    typedef Index<TString> TIndex;

    TString seq("A");
    TIndex index(seq);

    Iterator<TIndex, TopDown<> >::Type iterator(index);
    SEQAN_ASSERT(isRoot(iterator));
    SEQAN_ASSERT_NOT(isLeaf(iterator));

    SEQAN_ASSERT(goDown(iterator));
    SEQAN_ASSERT_NOT(isRoot(iterator));
    SEQAN_ASSERT(isLeaf(iterator));

    goRoot(iterator);
    SEQAN_ASSERT(isRoot(iterator));
    SEQAN_ASSERT_NOT(isLeaf(iterator));
    SEQAN_ASSERT(goDown(iterator, seq));
}

SEQAN_DEFINE_TEST(goDownOnEmptyString)
{
    typedef Index<DnaString, FMIndex<> > TIndex;
    typedef Iter<TIndex, VSTree<TopDown<> > > TIter;

    DnaString text("GCCTC");
    TIndex index(text);
    TIter it(index);

    goDown(it, "C");
    goDown(it);
    goDown(it, "");
    goRight(it);
    SEQAN_ASSERT_EQ(representative(it), DnaString("GC"));
    goRight(it);
    SEQAN_ASSERT_EQ(representative(it), DnaString("TC"));
}

SEQAN_DEFINE_TEST(testBuild)
{
        typedef String<char> TText;
        typedef StringSet< TText, Owner<ConcatDirect<> > > TMulti;

        String<char> gen1, gen2, gen3;
        std::cout << open(gen1, "corpus/NC_000117.txt");
        std::cout << open(gen2, "corpus/NC_002620.txt");
        std::cout << open(gen3, "corpus/NC_007429.txt");

        Index<TMulti> esa;
        appendValue(indexText(esa), gen1);
        appendValue(indexText(esa), gen2);
        appendValue(indexText(esa), gen3);


        indexRequire(esa, EsaSA());
        indexRequire(esa, EsaLcp());
        indexRequire(esa, EsaBwt());
        indexRequire(esa, EsaChildtab());

        save(esa, "corpus/chlamydia");
}

template <typename TIter>
inline void _printNode(TIter const it)
{
        std::cout << countOccurrences(it) << "\t";
        std::cout << representative(it) << "\t";
//        std::cout << "parentEdgeLabel:" << parentEdgeLabel(it);
        std::cout << std::endl;
}

SEQAN_DEFINE_TEST(testMultiIndex)
{
        typedef String<Dna5> TText;
        typedef StringSet< TText, Owner<> > TMulti;

        String<Dna5> t[6];
        //t[0] = "caterpillar";
        //t[1] = "catwoman";
        //t[2] = "pillow";
        //t[3] = "willow";
        //t[4] = "ill";
        //t[5] = "wow";

        // test empty stringsets
        {
            typedef Index<TMulti> TIndex;
            TMulti emptyStringSet;

            TIndex index(emptyStringSet);
            Iterator<
                TIndex,
                TopDown<>
            >::Type iterator(index);
        }

        t[0] = "caggctcgcgt";
        t[1] = "caggaacg";
        t[2] = "tcgttg";
        t[3] = "tggtcg";
        t[4] = "agg";
        t[5] = "ctg";

        t[0] = "ac";
        t[1] = "ac";
//        t[2] = "aatt";

        Index<TMulti> esa;
        for(unsigned i=0; i<2; ++i)
            appendValue(indexText(esa), t[i]);

        // efficient dfs iterator (hiding edges with empty labels)
        {
            std::cout << "BottomUp without empty edges" << std::endl;
            Iter<Index<TMulti>, VSTree< BottomUp<> > > it(esa);
            while (!atEnd(it)) {
                _printNode(it);
                goNext(it);
            }
        }

        // efficient dfs iterator
        {
            std::cout << std::endl << "BottomUp with empty edges" << std::endl;
            Iter<Index<TMulti>, VSTree< BottomUp<PostorderEmptyEdges> > > it(esa);
            while (!atEnd(it)) {
                _printNode(it);
                goNext(it);
            }
        }

        // topdown dfs iterator (hiding edges with empty labels)
        {
            std::cout << std::endl << "TopDown postorder without empty edges" << std::endl;
            Iter<Index<TMulti>, VSTree< TopDown<ParentLinks<Postorder> > > > it(esa);
            while (goDown(it)) ;
            while (!atEnd(it)) {
                _printNode(it);
                goNext(it);
            }
        }

        // topdown dfs iterator
        {
            std::cout << std::endl << "TopDown postorder with empty edges" << std::endl;
            Iter<Index<TMulti>, VSTree< TopDown<ParentLinks<PostorderEmptyEdges> > > > it(esa);
            while (goDown(it)) ;
            while (!atEnd(it)) {
                _printNode(it);
                goNext(it);
            }
        }

        // topdown dfs iterator (hiding edges with empty labels)
        {
            std::cout << std::endl << "TopDown preorder without empty edges" << std::endl;
            Iter<Index<TMulti>, VSTree< TopDown<ParentLinks<Preorder> > > > it(esa);
            goDown(it,'c');
            while (!atEnd(it)) {
                _printNode(it);
                goNext(it);
            }
        }

        // topdown dfs iterator
        {
            std::cout << std::endl << "TopDown preorder with empty edges" << std::endl;
            Iter<Index<TMulti>, VSTree< TopDown<ParentLinks<PreorderEmptyEdges> > > > it(esa);
            while (!atEnd(it)) {
                _printNode(it);
                goNext(it);
            }
        }

        // topdown iterator w/o parent links (hiding edges with empty labels)
        {
            std::cout << std::endl << "TopDown with empty edges" << std::endl;
            Iter<Index<TMulti>, VSTree< TopDown<HideEmptyEdges> > > it(esa);
            _printNode(it);
            while (goDown(it))
                _printNode(it);
        }

        // topdown iterator w/o parent links
        {
            std::cout << std::endl << "TopDown with empty edges" << std::endl;
            Iter<Index<TMulti>, VSTree< TopDown<EmptyEdges> > > it(esa);
            _printNode(it);
            while (goDown(it))
                _printNode(it);
        }

//        indexRequire(esa, EsaSA());
//        indexRequire(esa, EsaBwt());
//        for(int i=0; i<length(indexRawSA(esa)); ++i)
//            std::cout << saAt(i,esa) << " " << bwtAt(i,esa) << "    " << suffix(t[getValueI1(saAt(i,esa))], getValueI2(saAt(i,esa))) << std::endl;
//
////        resize(indexLcp(esa), length(indexRawText(esa)));
////        createLcpTableExt(indexLcp(esa), indexText(esa), indexSA(esa), Kasai());
//        indexRequire(esa, EsaLcp());
//        for(int i=0; i<length(indexRawSA(esa)); ++i)
//            std::cout << lcpAt(i,esa) << "    " << suffix(t[getValueI1(saAt(i,esa))], getValueI2(saAt(i,esa))) << std::endl;
//
//        for(int i=0; i<length(indexRawSA(esa)); ++i)
//            std::cout << saAt(i,esa) << " = " << indexRawSA(esa)[i] << "    " << std::endl;
//        for(int i=0; i<length(indexRawSA(esa)); ++i)
//            std::cout << bwtAt(i,esa) << " = " << indexBwt(esa).tab[i] << "    " << std::endl;
//        for(int i=0; i<length(indexRawSA(esa)); ++i)
//            std::cout << lcpAt(i,esa) << " = " << indexLcp(esa)[i] << "    " << std::endl;


//        resize(sa, length(indexRawText(esa)));
//        createSuffixArrayExt(sa, indexText(esa), Skew7());
//
//        for(int i=0; i<length(indexRawText(esa)); ++i)
//            std::cout << indexRawText(esa)[i] << "    ";
//
//        String<unsigned> lcp;
//        resize(lcp, length(indexRawText(esa)));
//        createLcpTableExt(lcp, indexText(esa), sa, Kasai());
}

template <typename TIndex1, typename TIndex2>
void compareTreeIterators(TIndex1 &index1, TIndex2 &index2)
{
    Iter<TIndex1, VSTree< TopDown< ParentLinks<Preorder> > > > it1(index1);
    Iter<TIndex2, VSTree< TopDown< ParentLinks<Preorder> > > > it2(index2);

    while (!atEnd(it1) && !atEnd(it2))
    {
        SEQAN_ASSERT_EQ(representative(it1), representative(it2));
        SEQAN_ASSERT_EQ(parentEdgeLabel(it1), parentEdgeLabel(it2));
        SEQAN_ASSERT_EQ(countOccurrences(it1), countOccurrences(it2));
        SEQAN_ASSERT_EQ(isRoot(it1), isRoot(it2));
//        SEQAN_ASSERT_EQ(isLeaf(it1), isLeaf(it2));
        goNext(it1);
        goNext(it2);
    }

    SEQAN_ASSERT_EQ(atEnd(it1), atEnd(it1));
}

template <typename TIndexSpec1, typename TIndexSpec2>
void compareIndices()
{
    {
        CharString text("mississippi");
        Index<CharString, TIndexSpec1> index1(text);
        Index<CharString, TIndexSpec2> index2(text);
        compareTreeIterators(index1, index2);
    }
    {
        DnaString text("acaaacatat");
        Index<DnaString, TIndexSpec1> index1(text);
        Index<DnaString, TIndexSpec2> index2(text);
        compareTreeIterators(index1, index2);
    }
    {
        StringSet<CharString> t;
        resize(t, 6);
        t[0] = "caterpillar";
        t[1] = "catwoman";
        t[2] = "pillow";
        t[3] = "willow";
        t[4] = "ill";
        t[5] = "wow";
        Index<StringSet<CharString>, TIndexSpec1> index1(t);
        Index<StringSet<CharString>, TIndexSpec2> index2(t);
        compareTreeIterators(index1, index2);
    }
    {
        StringSet<DnaString> t;
        resize(t, 6);
        t[0] = "caggctcgcgt";
        t[1] = "caggaacg";
        t[2] = "tcgttg";
        t[3] = "tggtcg";
        t[4] = "agg";
        t[5] = "ctg";
        Index<StringSet<DnaString>, TIndexSpec1> index1(t);
        Index<StringSet<DnaString>, TIndexSpec2> index2(t);
        compareTreeIterators(index1, index2);
    }
}

SEQAN_DEFINE_TEST(testCompareIndices_Esa_Wotd)
{
    compareIndices<IndexEsa<>, IndexWotd<> >();
}


template <typename TIndexSpec>
void testSTreeIterators()
{
    typedef Index<String<char>, TIndexSpec> TIndex;
    typedef typename Iterator<TIndex, TopDown<> >::Type TIterator;
    typedef typename Iterator<TIndex, TopDown<ParentLinks<> > >::Type TParentLinkIterator;

    // test empty trees
    {
        TIndex index("");
        TIterator iter(index);
        TParentLinkIterator piter(index);
        SEQAN_ASSERT_NOT(goDown(iter));
        SEQAN_ASSERT_NOT(goRight(iter));
        SEQAN_ASSERT_NOT(goUp(piter));
    }

    {
        String<char> text("acaaacatatz");
//        String<char> text("AAAAAGGGGG");
        TIndex index(text);
        Iter<TIndex, VSTree< TopDown< ParentLinks<Preorder> > > > it(index);
        Iter<TIndex, VSTree< TopDown<> > > itNoLinks(it);    // test conversion
        //Iter<TIndex, VSTree< BottomUp<> > > it(index);

//        while (goDown(it));
        while (!atEnd(it)) {
//            std::cout << countOccurrences(it) << "\t";
            std::cout << representative(it) << "\t";
            std::cout << "parentEdgeLabel: " << parentEdgeLabel(it); // << " " << value(it).node << "  " << value(it).range;
            std::cout << std::endl;
            goNext(it);
        }
            std::cout << std::endl;
        _dump(index);
//        goBegin(it);
//        while (!atEnd(it)) {
//            std::cout << countOccurrences(it) << "\t";
//            std::cout << representative(it) << "\t";
//            std::cout << "parentEdgeLabel: " << parentEdgeLabel(it) << " " << value(it).node << "  " << value(it).range;
//            std::cout << std::endl;
//            goNext(it);
//        }
//        _dump(index);
    }
}

SEQAN_DEFINE_TEST(testSTreeIterators_Wotd)
{
    testSTreeIterators<IndexWotd<> >();
}

SEQAN_DEFINE_TEST(testSTreeIterators_WotdOriginal)
{
    testSTreeIterators<IndexWotd<WotdOriginal> >();
}

SEQAN_DEFINE_TEST(testSTreeIterators_Esa)
{
    testSTreeIterators<IndexEsa<> >();
}


template <typename TPair>
struct PairLess_ :
        public std::binary_function<TPair, TPair, bool>
{
        inline bool
        operator() (TPair const& a1, TPair const& a2) const
        {
                if (a1.i1 == a2.i1) return (a1.i2 < a2.i2);
                else return (a1.i1 < a2.i1);
        }
};

SEQAN_DEFINE_TEST(testMaxRepeats)
{
//        typedef String<char, External<> > TText;
        typedef String<char> TText;

        Index<TText> esa;
//        open(esa, "corpus/NC_000117.txt");
        //                01234567890123456789
        indexText(esa) = "HALLOBALLOHALLEBALLO";

//        FILE* dotFile = fopen("stree.dot","w");
//        writeRecords(dotFile, esa, DotDrawing());
//        fclose(dotFile);

        Iterator< Index<TText>, MaxRepeats >::Type it(esa, 3);
        typedef MaxRepeat< Index<TText> > TRepeat;
        typedef Value<TRepeat>::Type TPair;

        int found = 0;
        while (!atEnd(it))
        {
//            std::cout << representative(it) << ":";
            Iterator<TRepeat, MaxRepeatOccurrences>::Type mit(it);
            String<TPair> occs;
            while (!atEnd(mit)) {
//                std::cout << "\t" << *mit << std::flush;
                appendValue(occs, *mit);
                if (back(occs).i1 > back(occs).i2)
                {
                    Value<TPair, 1>::Type tmp = back(occs).i1;
                    back(occs).i1 = back(occs).i2;
                    back(occs).i2 = tmp;
                }
                ++mit;
            }

            std::sort(begin(occs, Standard()), end(occs, Standard()), PairLess_<TPair>());
            if (representative(it) == "ALL")
            {
                SEQAN_ASSERT_EQ(length(occs), 2u);
                SEQAN_ASSERT_EQ(occs[0], TPair(6,11));
                SEQAN_ASSERT_EQ(occs[1], TPair(11,16));
            } else
            if (representative(it) == "HALL")
            {
                SEQAN_ASSERT_EQ(length(occs), 1u);
                SEQAN_ASSERT_EQ(occs[0], TPair(0,10));
            } else
            if (representative(it) == "BALLO")
            {
                SEQAN_ASSERT_EQ(length(occs), 1u);
                SEQAN_ASSERT_EQ(occs[0], TPair(5,15));
            } else
            if (representative(it) == "ALLO")
            {
                SEQAN_ASSERT_EQ(length(occs), 1u);
                if (occs[0].i2 == 6)
                    SEQAN_ASSERT_EQ(occs[0], TPair(1,6));
                else
                    SEQAN_ASSERT_EQ(occs[0], TPair(1,16));
            } else
            {
                SEQAN_ASSERT_FAIL("Unknown maximal repeat found!");
            }

            ++it;
            ++found;
        }
        SEQAN_ASSERT_EQ(found, 5);
}


SEQAN_DEFINE_TEST(testMultiMEMs)
{
        typedef String<char> TText;
        typedef StringSet< TText, Owner<ConcatDirect<> > > TMulti;

        Index<TMulti> esa;

        String<Dna5> t[6];
        t[0] = "caterpillar";
        t[1] = "catwoman";
        t[2] = "pillow";
        t[3] = "willow";
        t[4] = "ill";
        t[5] = "wow";

        std::ofstream dotFile("stree.dot");
        writeRecords(dotFile, esa, DotDrawing());
        dotFile.close();

        Iterator< Index<TMulti>, MultiMems >::Type it(esa, 3);
        typedef MultiMem< Index<TMulti> > TMultiMEM;
        while (!atEnd(it)) {
            std::cout << representative(it) << ":";
            Iterator<TMultiMEM>::Type mit(it);
            while (!atEnd(mit)) {
                std::cout << "\t" << *mit;
                ++mit;
            }
            std::cout << std::endl;
            ++it;
        }
}

template <typename TIteratorSpec>
void _testSuperMaxRepeats()
{
//        typedef String<char, External<> > TText;
        typedef String<char> TText;

        Index<TText> esa;
//        open(esa, "corpus/NC_000117.txt");
        indexText(esa) = "HALLOBALLOHALLEBALLO";

        typedef Index<TText> TIndex;
        typedef SAValue<TIndex>::Type TSAValue;
        typename Iterator<TIndex, TIteratorSpec >::Type it(esa);

        int found = 0;
        while (!atEnd(it))
        {
            String<TSAValue> occs = getOccurrences(it);
            std::sort(begin(occs, Standard()), end(occs, Standard()));

//            std::cout << representative(it) << ":";
//            for(typename Size<Index<TText> >::Type i = 0; i < countOccurrences(it); ++i)
//                std::cout << "\t" << getOccurrences(it)[i];
//            std::cout << std::endl;

            if (representative(it) == "BALLO")
            {
                SEQAN_ASSERT_EQ(length(occs), 2u);
                SEQAN_ASSERT_EQ(occs[0], 5u);
                SEQAN_ASSERT_EQ(occs[1], 15u);
            } else
            if (representative(it) == "HALL")
            {
                SEQAN_ASSERT_EQ(length(occs), 2u);
                SEQAN_ASSERT_EQ(occs[0], 0u);
                SEQAN_ASSERT_EQ(occs[1], 10u);
            } else
            {
                SEQAN_ASSERT_FAIL("Unknown supermaximal repeat found!");
            }

            ++it;
            ++found;
        }
        SEQAN_ASSERT_EQ(found, 2);
}

SEQAN_DEFINE_TEST(testSuperMaxRepeats)
{
    _testSuperMaxRepeats<SuperMaxRepeats>();
}

SEQAN_DEFINE_TEST(testSuperMaxRepeatsFast)
{
    _testSuperMaxRepeats<SuperMaxRepeatsFast>();
}


SEQAN_DEFINE_TEST(testMUMs)
{
        typedef String<char> TText;
        typedef StringSet< TText, Owner<ConcatDirect<> > > TMulti;
        typedef Index<TMulti, IndexEsa<> > TIndex;

        String<char> t[3];

        t[0] = "fefhalloballo";
        t[1] = "halloballefser";
        t[2] = "grballoballo";

        TIndex esa;
        for(int i = 0; i < 3; ++i)
            appendValue(indexText(esa), t[i]);            // add sequences to multiple index

        Iterator<TIndex, Mums>::Type  it(esa, 3);        // set minimum MUM length to 3
        typedef SAValue<TIndex>::Type TPair;
        String<TPair> occs;                                // temp. string storing the hit positions

        int found = 0;
//        std::cout << std::resetiosflags(std::ios::left);
        while (!atEnd(it))
        {
            occs = getOccurrences(it);                    // gives hit positions (seqNo,seqOfs)
            orderOccurrences(occs);                        // order them by seqNo

//            std::cout << representative(it) << ":";
//            for(unsigned i = 0; i < length(occs); ++i)
//                std::cout << "\t" << getValueI2(occs[i]);
//            std::cout << std::endl;
//            std::cout << alignment(it) << std::endl;

            if (representative(it) == "alloball")
            {
                SEQAN_ASSERT_EQ(length(occs), 3u);
                SEQAN_ASSERT_EQ(occs[0], TPair(0,4));
                SEQAN_ASSERT_EQ(occs[1], TPair(1,1));
                SEQAN_ASSERT_EQ(occs[2], TPair(2,3));
            } else {
                SEQAN_ASSERT_FAIL("Unknown MUM found!");
            }


            ++it;
            ++found;
        }
        SEQAN_ASSERT_EQ(found, 1);
}


template <typename TAlgorithmSpec>
void testFind()
{
        String<unsigned int> pos;

    //____________________________________________________________________________
    // Test1 - small needle

        String<char> haystack("Dies ist ein Haystack. Ja, das ist wirklich einer!");
        Index<String<char> > index(haystack);

        Finder<Index< String<char> >, TAlgorithmSpec> finder(index);

        String<char> needle1("ist");
        seqan::Pattern<String<char> > pattern(needle1);

        while (find(finder, pattern))
            appendValue(pos,position(finder));

        SEQAN_ASSERT_EQ(length(pos), 2u);
        SEQAN_ASSERT(pos[0] == 5u);
        SEQAN_ASSERT(pos[1] == 31u);

    //____________________________________________________________________________
    // Test2 - large needle

        haystack = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgaabcdef";
        clear(index);
        clear(finder);

        needle1 = "abcdefghijklmnopqrstuvwxyzabcdefg";
        setNeedle(pattern, needle1);

        clear(pos);
        while (find(finder, pattern))
            appendValue(pos,position(finder));

        SEQAN_ASSERT_EQ(length(pos), 2u);
        SEQAN_ASSERT(pos[1] == 0u);
        SEQAN_ASSERT(pos[0] == 26u);
}

SEQAN_DEFINE_TEST(testFind_Esa_Mlr)
{
    testFind<FinderMlr>();
}

SEQAN_DEFINE_TEST(testMultipleStrings_Ticket1109)
{
    StringSet<String<char> > text;
    appendValue(text, "How many");
    appendValue(text, " wood would");
    appendValue(text, " a woodchuck chuck?");

    typedef Index<StringSet<CharString> > TIndex;
    TIndex index(text);

    Iterator< TIndex, TopDown<> >::Type it(index);
}

SEQAN_DEFINE_TEST(testTrieIterator)
{
    typedef StringSet<CharString>               TText;
    typedef Index<TText, IndexSa<> >            TIndex;
    typedef Iterator<TIndex, TopDown<> >::Type  TIter;

    TText text;
    appendValue(text, "bananamama");
    appendValue(text, "bananajoe");

    TIndex index(text);
    indexCreate(index, FibreSA(), Trie());
    TIter it(index);
    goDown(it);
    SEQAN_ASSERT_EQ(parentEdgeLabel(it), 'b');
    SEQAN_ASSERT_EQ(countOccurrences(it), 2u);
    goDown(it, "anana");
    goDown(it);
    SEQAN_ASSERT_EQ(parentEdgeLabel(it), 'j');
}

SEQAN_DEFINE_TEST(testRadixTreeIterator)
{
    typedef StringSet<CharString>               TText;
    typedef Index<TText, IndexWotd<> >          TIndex;
    typedef Iterator<TIndex, TopDown<> >::Type  TIter;

    TText text;
    appendValue(text, "bananamama");
    appendValue(text, "bananajoe");

    TIndex index(text);
    indexCreate(index, WotdDir(), Trie());
    TIter it(index);
    goDown(it);
    SEQAN_ASSERT_EQ(parentEdgeLabel(it), "banana");
    SEQAN_ASSERT_EQ(countOccurrences(it), 2u);
    goDown(it);
    SEQAN_ASSERT_EQ(parentEdgeLabel(it), "joe");
}

//////////////////////////////////////////////////////////////////////////////


} //namespace seqan

#endif //#ifndef SEQAN_HEADER_...