1187 |
28 Aug 10 |
peter |
// $Id$ |
1187 |
28 Aug 10 |
peter |
2 |
|
1187 |
28 Aug 10 |
peter |
3 |
/* |
1635 |
30 Mar 23 |
peter |
Copyright (C) 2010, 2011, 2023 Peter Johansson |
1187 |
28 Aug 10 |
peter |
5 |
|
1187 |
28 Aug 10 |
peter |
This file is part of svndigest, http://dev.thep.lu.se/svndigest |
1187 |
28 Aug 10 |
peter |
7 |
|
1187 |
28 Aug 10 |
peter |
svndigest is free software; you can redistribute it and/or modify it |
1187 |
28 Aug 10 |
peter |
under the terms of the GNU General Public License as published by |
1187 |
28 Aug 10 |
peter |
the Free Software Foundation; either version 3 of the License, or |
1187 |
28 Aug 10 |
peter |
(at your option) any later version. |
1187 |
28 Aug 10 |
peter |
12 |
|
1187 |
28 Aug 10 |
peter |
svndigest is distributed in the hope that it will be useful, but |
1187 |
28 Aug 10 |
peter |
WITHOUT ANY WARRANTY; without even the implied warranty of |
1187 |
28 Aug 10 |
peter |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
1187 |
28 Aug 10 |
peter |
General Public License for more details. |
1187 |
28 Aug 10 |
peter |
17 |
|
1187 |
28 Aug 10 |
peter |
You should have received a copy of the GNU General Public License |
1187 |
28 Aug 10 |
peter |
along with svndigest. If not, see <http://www.gnu.org/licenses/>. |
1187 |
28 Aug 10 |
peter |
20 |
*/ |
1187 |
28 Aug 10 |
peter |
21 |
|
1619 |
12 Mar 23 |
peter |
22 |
#include <config.h> |
1619 |
12 Mar 23 |
peter |
23 |
|
1187 |
28 Aug 10 |
peter |
24 |
#include "Suite.h" |
1187 |
28 Aug 10 |
peter |
25 |
|
1187 |
28 Aug 10 |
peter |
26 |
#include "lib/Vector.h" |
1187 |
28 Aug 10 |
peter |
27 |
|
1187 |
28 Aug 10 |
peter |
28 |
#include <iostream> |
1187 |
28 Aug 10 |
peter |
29 |
#include <vector> |
1187 |
28 Aug 10 |
peter |
30 |
|
1187 |
28 Aug 10 |
peter |
31 |
using namespace theplu::svndigest; |
1187 |
28 Aug 10 |
peter |
32 |
|
1187 |
28 Aug 10 |
peter |
33 |
template<class T> |
1187 |
28 Aug 10 |
peter |
34 |
void run_test(T, test::Suite&); |
1187 |
28 Aug 10 |
peter |
35 |
void test_accumulate(test::Suite&); |
1187 |
28 Aug 10 |
peter |
36 |
|
1187 |
28 Aug 10 |
peter |
37 |
int main(int argc, char* argv[]) |
1187 |
28 Aug 10 |
peter |
38 |
{ |
1187 |
28 Aug 10 |
peter |
39 |
test::Suite suite(argc, argv); |
1187 |
28 Aug 10 |
peter |
40 |
|
1187 |
28 Aug 10 |
peter |
41 |
run_test(SparseVector(), suite); |
1187 |
28 Aug 10 |
peter |
42 |
run_test(SumVector(), suite); |
1187 |
28 Aug 10 |
peter |
43 |
test_accumulate(suite); |
1187 |
28 Aug 10 |
peter |
44 |
|
1187 |
28 Aug 10 |
peter |
45 |
return suite.exit_status(); |
1187 |
28 Aug 10 |
peter |
46 |
} |
1187 |
28 Aug 10 |
peter |
47 |
|
1187 |
28 Aug 10 |
peter |
48 |
template<class T> |
1194 |
03 Oct 10 |
peter |
49 |
void run_test(T vec, test::Suite& suite) |
1187 |
28 Aug 10 |
peter |
50 |
{ |
1187 |
28 Aug 10 |
peter |
51 |
vec.begin(); |
1187 |
28 Aug 10 |
peter |
52 |
vec.end(); |
1187 |
28 Aug 10 |
peter |
53 |
vec.size(); |
1187 |
28 Aug 10 |
peter |
54 |
vec[0]; |
1187 |
28 Aug 10 |
peter |
55 |
vec.set(0, 0); |
1194 |
03 Oct 10 |
peter |
56 |
|
1194 |
03 Oct 10 |
peter |
57 |
vec.set(5,10); |
1194 |
03 Oct 10 |
peter |
58 |
T vec2(vec); |
1194 |
03 Oct 10 |
peter |
59 |
vec2.set(7,11); |
1194 |
03 Oct 10 |
peter |
60 |
T vec3; |
1194 |
03 Oct 10 |
peter |
61 |
vec3 = vec2; |
1194 |
03 Oct 10 |
peter |
62 |
suite.out() << "testing assignment\n"; |
1194 |
03 Oct 10 |
peter |
63 |
if (vec3.size()!=vec2.size()) { |
1194 |
03 Oct 10 |
peter |
64 |
suite.add(false); |
1194 |
03 Oct 10 |
peter |
65 |
suite.out() << "incorrect size: " << vec3.size() << " expected: " |
1194 |
03 Oct 10 |
peter |
66 |
<< vec2.size() << "\n"; |
1194 |
03 Oct 10 |
peter |
67 |
} |
1194 |
03 Oct 10 |
peter |
68 |
|
1196 |
04 Oct 10 |
peter |
69 |
suite.out() << "testing back()\n"; |
1196 |
04 Oct 10 |
peter |
70 |
vec.resize(0); |
1196 |
04 Oct 10 |
peter |
71 |
vec.resize(10); |
1196 |
04 Oct 10 |
peter |
72 |
vec.set(9,71); |
1196 |
04 Oct 10 |
peter |
73 |
if (!suite.add(vec.back()==vec[9])) { |
1196 |
04 Oct 10 |
peter |
74 |
suite.out() << "vec.back(): " << vec.back() |
1196 |
04 Oct 10 |
peter |
75 |
<< "\nexpected: " << vec[9] << "\n"; |
1196 |
04 Oct 10 |
peter |
76 |
} |
1196 |
04 Oct 10 |
peter |
77 |
vec.resize(20); |
1196 |
04 Oct 10 |
peter |
78 |
if (!suite.add(vec.back()==vec[19])) { |
1196 |
04 Oct 10 |
peter |
79 |
suite.out() << "vec.back(): " << vec.back() |
1196 |
04 Oct 10 |
peter |
80 |
<< "\nexpected: " << vec[19] << "\n"; |
1196 |
04 Oct 10 |
peter |
81 |
} |
1187 |
28 Aug 10 |
peter |
82 |
} |
1187 |
28 Aug 10 |
peter |
83 |
|
1187 |
28 Aug 10 |
peter |
84 |
void test_accumulate(test::Suite& suite) |
1187 |
28 Aug 10 |
peter |
85 |
{ |
1187 |
28 Aug 10 |
peter |
86 |
SparseVector vec; |
1187 |
28 Aug 10 |
peter |
87 |
vec.set(5, 1); |
1187 |
28 Aug 10 |
peter |
88 |
vec.set(9, 12); |
1187 |
28 Aug 10 |
peter |
89 |
|
1187 |
28 Aug 10 |
peter |
90 |
SumVector result; |
1187 |
28 Aug 10 |
peter |
91 |
accumulate(vec, result); |
1187 |
28 Aug 10 |
peter |
92 |
std::vector<unsigned int> expected; |
1187 |
28 Aug 10 |
peter |
93 |
expected.resize(10); |
1187 |
28 Aug 10 |
peter |
94 |
expected[5]=1; |
1187 |
28 Aug 10 |
peter |
95 |
expected[6]=1; |
1187 |
28 Aug 10 |
peter |
96 |
expected[7]=1; |
1187 |
28 Aug 10 |
peter |
97 |
expected[8]=1; |
1187 |
28 Aug 10 |
peter |
98 |
expected[9]=13; |
1418 |
25 Oct 11 |
peter |
99 |
if (static_cast<size_t>(result.size()) != expected.size()) { |
1187 |
28 Aug 10 |
peter |
100 |
suite.add(false); |
1187 |
28 Aug 10 |
peter |
101 |
suite.out() << "error: size: " << result.size() << " expected: " |
1187 |
28 Aug 10 |
peter |
102 |
<< expected.size() << "\n"; |
1187 |
28 Aug 10 |
peter |
103 |
} |
1187 |
28 Aug 10 |
peter |
104 |
else { |
1418 |
25 Oct 11 |
peter |
105 |
for (svn_revnum_t i=0; i<result.size(); ++i) { |
1187 |
28 Aug 10 |
peter |
106 |
if (result[i]!=expected[i]) { |
1187 |
28 Aug 10 |
peter |
107 |
suite.add(false); |
1187 |
28 Aug 10 |
peter |
108 |
suite.out() << "error: result[" << i << "]: " << result[i] |
1187 |
28 Aug 10 |
peter |
109 |
<< " expected: " << expected[i] << "\n"; |
1187 |
28 Aug 10 |
peter |
110 |
} |
1187 |
28 Aug 10 |
peter |
111 |
} |
1187 |
28 Aug 10 |
peter |
112 |
} |
1187 |
28 Aug 10 |
peter |
113 |
|
1187 |
28 Aug 10 |
peter |
114 |
} |