1 // ==========================================================================
2 //                 SeqAn - The Library for Sequence Analysis
3 // ==========================================================================
4 // Copyright (c) 2006-2018, Knut Reinert, FU Berlin
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 //
10 //     * Redistributions of source code must retain the above copyright
11 //       notice, this list of conditions and the following disclaimer.
12 //     * Redistributions in binary form must reproduce the above copyright
13 //       notice, this list of conditions and the following disclaimer in the
14 //       documentation and/or other materials provided with the distribution.
15 //     * Neither the name of Knut Reinert or the FU Berlin nor the names of
16 //       its contributors may be used to endorse or promote products derived
17 //       from this software without specific prior written permission.
18 //
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 // ARE DISCLAIMED. IN NO EVENT SHALL KNUT REINERT OR THE FU BERLIN BE LIABLE
23 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
29 // DAMAGE.
30 //
31 // ==========================================================================
32 // Author: David Weese <david.weese@fu-berlin.de>
33 // ==========================================================================
34 
35 #ifndef SEQAN_HEADER_TEST_PIPE_H
36 #define SEQAN_HEADER_TEST_PIPE_H
37 
38 namespace seqan
39 {
40 
41 template < typename TBuffer >
permute(TBuffer buf)42 void permute(TBuffer buf)
43 {
44     typename Size<TBuffer>::Type i, j, s = length(buf);
45 //  srand( (unsigned)time( NULL ) );
46 
47     for(i = 0; i < s; i++)
48         buf[i] = s - i - 1;
49 
50     for (i = 0; i < s; i++)
51     {
52         if (i > 0)
53         {
54             j = i - (rand() % i) - 1;
55             SEQAN_ASSERT_LT(j, s);
56         }
57         else
58         {
59             j = 0;
60         }
61         std::swap(buf[i], buf[j]);
62     }
63 }
64 
65 template < typename TBuffer >
randomize(TBuffer buf)66 void randomize(TBuffer buf)
67 {
68     typename Size<TBuffer>::Type i, s = length(buf);
69     for(i = 0; i < s; i++)
70         buf[i] = rand() % s;
71 }
72 
73 template < typename TValue >
74 struct IdentityMap : public std::unary_function< TValue, TValue >
75 {
operatorIdentityMap76     inline TValue operator() (TValue const i)
77     {
78         return i;
79     }
80 };
81 
82 template < typename TValue >
83 struct SimpleCompare : public std::binary_function< TValue const, TValue const, int >
84 {
operatorSimpleCompare85     inline int operator() (TValue const a, TValue const b) const
86     {
87         if (a < b) return -1;
88         if (a > b) return 1;
89         return 0;
90     }
91 };
92 
93 template <typename TPipe1, typename TPipe2>
comparePipes(TPipe1 & pipe1,TPipe2 & pipe2)94 void comparePipes(TPipe1 &pipe1, TPipe2 &pipe2)
95 {
96     typedef typename Size<TPipe1>::Type TSize;
97 
98     SEQAN_ASSERT_EQ(length(pipe1), length(pipe2));
99     beginRead(pipe1);
100     beginRead(pipe2);
101     TSize actualLen;
102     for (actualLen = 0; !eof(pipe1) && !eof(pipe2); ++actualLen)
103     {
104         SEQAN_ASSERT_EQ(eos(pipe1), eos(pipe2));
105         SEQAN_ASSERT_EQ(*pipe1, *pipe2);
106         ++pipe1;
107         ++pipe2;
108     }
109     SEQAN_ASSERT_EQ(eos(pipe1), eos(pipe2));
110     SEQAN_ASSERT_EQ(eof(pipe1), eof(pipe2));
111     SEQAN_ASSERT_EQ(actualLen, length(pipe1));
112     endRead(pipe1);
113     endRead(pipe2);
114 }
115 
116 }
117 
118 #endif
119