[3] | 1 | /* |
---|
| 2 | * Copyright (c) 2011-2012, Attila Gobi |
---|
| 3 | * All rights reserved. |
---|
| 4 | * |
---|
| 5 | * This software was developed by Attila Gobi. |
---|
| 6 | * The project was supported by the European Union and co-financed by the |
---|
| 7 | * European Social Fund (grant agreement no. TAMOP 4.2.1./B-09/1/KMR-2010-0003) |
---|
| 8 | * |
---|
| 9 | * Redistribution and use in source and binary forms, with or without |
---|
| 10 | * modification, are permitted provided that the following conditions are met: |
---|
| 11 | * 1. Redistributions of source code must retain the above copyright |
---|
| 12 | * notice, this list of conditions and the following disclaimer. |
---|
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
---|
| 14 | * notice, this list of conditions and the following disclaimer in the |
---|
| 15 | * documentation and/or other materials provided with the distribution. |
---|
| 16 | * |
---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS "AS IS" AND ANY |
---|
| 18 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
---|
| 19 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
---|
| 20 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
---|
| 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
---|
| 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
---|
| 23 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
---|
| 24 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
---|
| 25 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
---|
| 26 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
---|
| 27 | */ |
---|
| 28 | |
---|
[2] | 29 | #ifndef __TEST_COMMON_H__ |
---|
| 30 | #define __TEST_COMMON_H__ |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | template<typename T> |
---|
| 34 | void prints(const stream<T> &s, size_t n=10) |
---|
| 35 | { |
---|
| 36 | typename stream<T>::iterator it=s.begin(); |
---|
| 37 | for(size_t i=1; i<n; ++i) |
---|
| 38 | { |
---|
| 39 | std::cout<<*it<<" "; |
---|
| 40 | ++it; |
---|
| 41 | } |
---|
| 42 | std::cout<<std::endl; |
---|
| 43 | } |
---|
| 44 | |
---|
| 45 | template<typename T> |
---|
| 46 | void stress(const stream<T> &s) |
---|
| 47 | { |
---|
| 48 | clock_t t1,t2; |
---|
| 49 | t1=clock(); |
---|
| 50 | typename stream<T>::iterator it=s.begin(); |
---|
| 51 | for(int i=1; i<10000; ++i) { |
---|
| 52 | *it; |
---|
| 53 | ++it; |
---|
| 54 | } |
---|
| 55 | t2=clock(); |
---|
| 56 | std::cout<<(double(t2)-double(t1))/CLOCKS_PER_SEC<<std::endl; |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | template<typename T> |
---|
| 60 | void compare(const stream<T> &s, const std::initializer_list<T> &a, int pass=3) |
---|
| 61 | { |
---|
| 62 | |
---|
| 63 | typename stream<T>::iterator sit = s.begin(); |
---|
| 64 | for(int i=0; i<pass; ++i) |
---|
| 65 | { |
---|
| 66 | typename std::initializer_list<T>::iterator ait = a.begin(); |
---|
| 67 | |
---|
| 68 | while(ait != a.end()) |
---|
| 69 | { |
---|
| 70 | assert(*ait==*sit); |
---|
| 71 | std::cout<<*ait<<" "; |
---|
| 72 | ++ait; ++sit; |
---|
| 73 | } |
---|
| 74 | } |
---|
| 75 | std::cout<<std::endl; |
---|
| 76 | } |
---|
| 77 | |
---|
| 78 | #endif//__TEST_COMMON_H__ |
---|