Changeset 1214
- Timestamp:
- Mar 7, 2008, 8:40:00 PM (16 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/README
r1180 r1214 28 28 must run './bootstrap' to initialize the build system. Now do 29 29 './configure' to create the Makefiles. Optionally you can run 30 configure with '--enable-debug', which will turn on debug options. If 31 you want to disable debugging options do './configure CXXFLAGS=""', 32 needed since autoconf defaults to adding debug flags to the compiler. 30 configure with '--enable-debug', which will turn on debug options. 33 31 34 32 Issue 'make' to compile the project. -
trunk/test/Makefile.am
r1122 r1214 8 8 # Copyright (C) 2006 Jari Häkkinen, Markus Ringnér, Peter Johansson 9 9 # Copyright (C) 2007 Jari Häkkinen, Peter Johansson 10 # Copyright (C) 2008 Peter Johansson 10 11 # 11 12 # This file is part of the yat library, http://trac.thep.lu.se/yat … … 27 28 28 29 SUBDIRS = data 30 31 noinst_HEADERS = Suite.h 29 32 30 33 TESTS = alignment_test averager_test \ … … 53 56 54 57 alignment_test_SOURCES = alignment_test.cc 55 averager_test_SOURCES = averager_test.cc 58 averager_test_SOURCES = averager_test.cc Suite.cc 56 59 commandline_test_SOURCES = commandline_test.cc 57 60 consensus_inputranker_test_SOURCES = consensus_inputranker_test.cc -
trunk/test/averager_test.cc
r1210 r1214 24 24 */ 25 25 26 #include "Suite.h" 27 26 28 #include "yat/statistics/Averager.h" 27 29 #include "yat/statistics/AveragerPair.h" … … 36 38 #include <set> 37 39 40 using namespace theplu::yat; 38 41 using namespace theplu::yat::statistics; 39 42 43 using theplu::yat::test::Suite; 44 40 45 //Forward declarations 41 bool equal(const Averager&, const Averager&); 42 bool equal(const AveragerWeighted&, const AveragerWeighted&, const double, 43 std::ostream* error); 44 bool equal(const Averager&, const AveragerWeighted&, const double, 45 std::ostream* error); 46 bool equal(const AveragerPair&, const AveragerPair&, 47 const double, std::ostream* error); 48 bool equal(const AveragerPair&, const AveragerPairWeighted&, 49 const double, std::ostream* error); 50 bool equal(const AveragerPairWeighted&, const AveragerPairWeighted&, 51 const double, std::ostream* error); 52 53 54 int main(const int argc,const char* argv[]) 46 bool equal(const Averager&, const Averager&, u_int, Suite&); 47 bool equal(const AveragerWeighted&, const AveragerWeighted&, u_int, 48 Suite& suite); 49 bool equal(const Averager&, const AveragerWeighted&, u_int, Suite& suite); 50 bool equal(const AveragerPair&, const AveragerPair&, u_int, Suite& suite); 51 bool equal(const AveragerPair&, const AveragerPairWeighted&, u_int, 52 Suite& suite); 53 bool equal(const AveragerPairWeighted&, const AveragerPairWeighted&, u_int, 54 Suite& suite); 55 56 57 int main(int argc, char* argv[]) 55 58 { 56 59 57 std::ostream* error; 58 if (argc>1 && argv[1]==std::string("-v")) 59 error = &std::cerr; 60 else { 61 error = new std::ofstream("/dev/null"); 62 if (argc>1) 63 std::cout << "averager_test -v : for printing extra information\n"; 64 } 65 bool ok = true; 60 Suite suite(argc, argv); 66 61 67 62 // Testing Averager 68 *error<< "testing Averager" << std::endl;63 suite.out() << "testing Averager" << std::endl; 69 64 Averager a; 70 65 a.add(1); … … 72 67 a.add(5); 73 68 if (a.n()!=3 || a.mean()!=3 || a.sum_xx()!=35){ 74 ok=false;75 *error<< "error: add\n";69 suite.ok(false); 70 suite.err() << "error: add\n"; 76 71 } 77 72 78 73 79 74 Averager* a1 = new Averager(1.0+3+5,1.0+9+25,3); 80 if (!equal(a,*a1)){81 ok=false;82 s td::cout.precision(25);83 s td::cout << equal(a,*a1) << std::endl;84 s td::cout<< a.sum_x() << '\t' << a1->sum_x() << std::endl;85 s td::cout<< a.sum_xx() << '\t' << a1->sum_xx() << std::endl;86 s td::cout<< a.n() << '\t' << a1->n() << std::endl;87 s td::cout<< a.variance() << '\t' << a1->variance() << std::endl;88 s td::cout<< a.mean() << '\t' << a1->mean() << std::endl;89 s td::cout<< a.mean() - a1->mean() << std::endl;90 s td::cout<< a.variance() - a1->variance() << std::endl;91 *error<< "error: Averager(double x, double xx, u_long n)\n";75 u_int tol = 10; 76 if (!equal(a,*a1, tol, suite)){ 77 suite.ok(false); 78 suite.err().precision(25); 79 suite.err() << a.sum_x() << '\t' << a1->sum_x() << std::endl; 80 suite.err() << a.sum_xx() << '\t' << a1->sum_xx() << std::endl; 81 suite.err() << a.n() << '\t' << a1->n() << std::endl; 82 suite.err() << a.variance() << '\t' << a1->variance() << std::endl; 83 suite.err() << a.mean() << '\t' << a1->mean() << std::endl; 84 suite.err() << a.mean() - a1->mean() << std::endl; 85 suite.err() << a.variance() - a1->variance() << std::endl; 86 suite.err() << "error: Averager(double x, double xx, u_long n)\n"; 92 87 } 93 88 delete a1; 94 89 95 90 a1 = new Averager(a); 96 if (!equal(a,*a1 )){97 ok=false;98 *error<< "error: Copy constructor\n";91 if (!equal(a,*a1, tol, suite)){ 92 suite.ok(false); 93 suite.err() << "error: Copy constructor\n"; 99 94 } 100 95 delete a1; 101 96 102 97 a.add(3,5); 103 if (! a.standard_error()==sqrt(a.variance()/a.n())){ 104 ok=false; 105 *error << "error: standard_error\n"; 98 if (std::abs(a.standard_error()-sqrt(a.variance()/a.n()))> 99 std::numeric_limits<double>().round_error() ){ 100 suite.ok(false); 101 suite.err() << "error: standard_error\n"; 106 102 } 107 103 … … 109 105 if ( std::abs(a.variance() - a.std()*a.std())> 110 106 std::numeric_limits<double>().round_error() ){ 111 ok=false;112 *error<< "error: std squared should be variance" << std::endl;113 *error<< "std2: " << a.std()*a.std() << std::endl;114 *error<< "variance: " << a.variance() << std::endl;115 *error<< "difference is: " << a.std()*a.std()-a.variance() << std::endl;107 suite.ok(false); 108 suite.err() << "error: std squared should be variance" << std::endl; 109 suite.err() << "std2: " << a.std()*a.std() << std::endl; 110 suite.err() << "variance: " << a.variance() << std::endl; 111 suite.err() << "difference is: " << a.std()*a.std()-a.variance() << std::endl; 116 112 } 117 113 118 114 if ( a.variance() != a.variance(a.mean()) ){ 119 ok=false;120 *error<< "error: variance incorrect\n" << std::endl;121 *error<< "variance: " << a.variance() << std::endl;122 *error<< "mean: " << a.mean() << std::endl;123 *error<< "variance(mean) " << a.variance(a.mean()) << std::endl;115 suite.ok(false); 116 suite.err() << "error: variance incorrect\n" << std::endl; 117 suite.err() << "variance: " << a.variance() << std::endl; 118 suite.err() << "mean: " << a.mean() << std::endl; 119 suite.err() << "variance(mean) " << a.variance(a.mean()) << std::endl; 124 120 } 125 121 theplu::yat::utility::Vector* tmp_vec = new theplu::yat::utility::Vector(10); … … 134 130 135 131 // Testing AveragerWeighted 136 *error<< "testing AveragerWeighted" << std::endl;132 suite.err() << "testing AveragerWeighted" << std::endl; 137 133 theplu::yat::utility::Vector x(3,0); 138 134 x(0)=0; … … 144 140 a.reset(); 145 141 add(a, x.begin(), x.end()); 146 const double tol=std::numeric_limits<double>().round_error(); 147 if (!equal(a,aw,tol,error)){ 148 *error << "error: AveragerWeighted with unitary weights should " 142 if (!equal(a,aw,tol,suite)){ 143 suite.err() << "error: AveragerWeighted with unitary weights should " 149 144 << "be equal to Averager" << std::endl; 150 ok=false;145 suite.ok(false); 151 146 } 152 147 153 148 AveragerWeighted* aw2 = new AveragerWeighted(aw); 154 if (!equal(aw,*aw2,tol, error)){155 *error<< "error: AveragerWeighted copy constructor " << std::endl;156 ok=false;149 if (!equal(aw,*aw2,tol,suite)){ 150 suite.err() << "error: AveragerWeighted copy constructor " << std::endl; 151 suite.ok(false); 157 152 } 158 153 159 154 aw2->add(12,0); 160 if (!equal(aw,*aw2,tol, error)){161 *error<< "error: AveragerWeighted adding a data point with weight=0 "155 if (!equal(aw,*aw2,tol,suite)){ 156 suite.err() << "error: AveragerWeighted adding a data point with weight=0 " 162 157 << "should make no change " << std::endl; 163 ok=false;158 suite.ok(false); 164 159 } 165 160 … … 167 162 w*=17; 168 163 add(*aw2, x.begin(), x.end(), w.begin()); 169 if (!equal(aw,*aw2,tol, error)){170 *error<< "error: AveragerWeighted rescaling weights "164 if (!equal(aw,*aw2,tol,suite)){ 165 suite.err() << "error: AveragerWeighted rescaling weights " 171 166 << "should make no change " << std::endl; 172 ok=false;167 suite.ok(false); 173 168 } 174 169 delete aw2; … … 185 180 186 181 187 *error<< "testing AveragerPair" << std::endl;182 suite.out() << "testing AveragerPair" << std::endl; 188 183 AveragerPair ap; 189 184 for (int i=0; i<10; i++) 190 185 ap.add(static_cast<double>(i),i); 191 186 if (std::abs(ap.correlation()-1)>tol){ 192 ok=false;193 *error<< "correlation: " << ap.correlation() << std::endl;194 *error<< "error: correlation between identical vectors should be unity"187 suite.ok(false); 188 suite.err() << "correlation: " << ap.correlation() << std::endl; 189 suite.err() << "error: correlation between identical vectors should be unity" 195 190 << std::endl; 196 191 } 197 192 if (ap.x_averager().variance()!=ap.covariance()){ 198 ok=false;199 *error<< "error: covariance of identical vectors should equal to variance"193 suite.ok(false); 194 suite.err() << "error: covariance of identical vectors should equal to variance" 200 195 << std::endl; 201 196 } … … 203 198 delete ap2; 204 199 205 *error<< "testing AveragerPairWeighted" << std::endl;200 suite.out() << "testing AveragerPairWeighted" << std::endl; 206 201 AveragerPairWeighted apw; 207 202 x(0)=0; x(1)=1; x(2)=2; … … 211 206 ap.reset(); 212 207 add(ap, x.begin(), x.end(), y.begin()); 213 if (!equal(ap,apw,tol, error)){214 *error<< "error: AveragerPairWeighted with unitary weights should "208 if (!equal(ap,apw,tol,suite)){ 209 suite.err() << "error: AveragerPairWeighted with unitary weights should " 215 210 << "be equal to AveragerPair" << std::endl; 216 ok=false;211 suite.ok(false); 217 212 } 218 213 219 214 AveragerPairWeighted* apw2 = new AveragerPairWeighted(apw); 220 if (!equal(apw,*apw2,tol, error)){221 *error<< "error: AveragerPairWeighted copy constructor " << std::endl;222 ok=false;215 if (!equal(apw,*apw2,tol,suite)){ 216 suite.err() << "error: AveragerPairWeighted copy constructor " << std::endl; 217 suite.ok(false); 223 218 } 224 219 225 220 apw2->add(12,23222.03,32.3,0); 226 if (!equal(apw,*apw2,tol, error)){227 *error<< "error: AveragerWeighted adding a data point with weight=0 "221 if (!equal(apw,*apw2,tol,suite)){ 222 suite.err() << "error: AveragerWeighted adding a data point with weight=0 " 228 223 << "should make no change " << std::endl; 229 ok=false;224 suite.ok(false); 230 225 } 231 226 … … 233 228 w*=17; 234 229 add(*apw2, x.begin(), x.end(), y.begin(), w.begin(), w.begin()); 235 if (!equal(apw,*apw2,tol, error)){236 *error<< "error: AveragerWeighted rescaling weights "230 if (!equal(apw,*apw2,tol,suite)){ 231 suite.err() << "error: AveragerWeighted rescaling weights " 237 232 << "should make no change " << std::endl; 238 ok=false;233 suite.ok(false); 239 234 } 240 235 delete apw2; 241 236 242 if (error!=&std::cerr) 243 delete error; 244 245 if (!ok) 246 return -1; 247 return 0; 248 } 249 250 bool equal(const Averager& a, const Averager& b) 237 return !suite.ok(); 238 } 239 240 bool equal(const Averager& a, const Averager& b, u_int tol, 241 Suite& suite) 251 242 { 252 243 // std::cout << (a.n()==b.n()) << std::endl; 253 244 // std::cout << (a.mean()==b.mean()) << std::endl; 254 245 // std::cout << (std::abs(a.variance()-b.variance()<1e-15)) << std::endl; 255 return (a.n()==b.n() && a.mean()==b.mean() &&256 std::abs(a.variance()-b.variance()<1e-15));246 return (a.n()==b.n() && test::equal(a.mean(),b.mean(),tol) && 247 test::equal(a.variance(),b.variance(),tol)); 257 248 } 258 249 259 250 bool equal(const AveragerWeighted& a, const AveragerWeighted& b, 260 const double tol, std::ostream* error)251 const u_int tol, Suite& suite) 261 252 { 262 253 bool equal = true; 263 if ( std::abs(a.mean()-b.mean())>tol){254 if ( !test::equal(a.mean(),b.mean(),tol)){ 264 255 equal=false; 265 *error << "mean:\t" << a.mean() << "\t" << b.mean() << std::endl; 266 } 267 if ( std::abs(a.variance()-b.variance())>tol ) { 256 suite.err() << "mean:\t" << a.mean() << "\t" << b.mean() << std::endl; 257 suite.err() << "difference:\t" << a.mean()-b.mean() << std::endl; 258 } 259 if ( !test::equal(a.variance(),b.variance(),tol) ) { 268 260 equal=false; 269 *error << "error for variance:\t" << a.variance() << " " << b.variance()270 << std::endl;271 } 272 if ( std::abs(a.standard_error()-b.standard_error())>tol) {261 suite.err() << "error for variance:\t" << a.variance() << " " 262 << b.variance() << std::endl; 263 } 264 if ( !test::equal(a.standard_error(),b.standard_error(),tol) ) { 273 265 equal =false; 274 *error<< "error for standard error:\t" << std::endl;266 suite.err() << "error for standard error:\t" << std::endl; 275 267 } 276 268 return equal; 277 269 } 278 270 279 bool equal(const Averager& a, const AveragerWeighted& b, const doubletol,280 std::ostream* error)271 bool equal(const Averager& a, const AveragerWeighted& b, const u_int tol, 272 Suite& suite) 281 273 { 282 274 bool equal = true; 283 if ( std::abs(a.mean()-b.mean())>tol){275 if ( !test::equal(a.mean(),b.mean(),tol)){ 284 276 equal=false; 285 *error<< "mean:\t" << a.mean() << "\t" << b.mean() << std::endl;286 } 287 if ( std::abs(a.variance()-b.variance())>tol) {277 suite.err() << "mean:\t" << a.mean() << "\t" << b.mean() << std::endl; 278 } 279 if ( !test::equal(a.variance(),b.variance(),tol) ) { 288 280 equal=false; 289 *error << "error for variance:\t" << a.variance() << " " << b.variance()290 << std::endl;291 } 292 if ( std::abs(a.standard_error()-b.standard_error())>tol) {281 suite.err() << "error for variance:\t" << a.variance() << " " 282 << b.variance() << std::endl; 283 } 284 if ( !test::equal(a.standard_error(), b.standard_error(),tol) ) { 293 285 equal =false; 294 *error<< "error for standard error:\t" << std::endl;286 suite.err() << "error for standard error:\t" << std::endl; 295 287 } 296 288 return equal; … … 298 290 299 291 bool equal(const AveragerPair& a, const AveragerPair& b, 300 const double tol, std::ostream* error)292 const u_int tol, Suite& suite) 301 293 { 302 294 bool ok = true; 303 295 if ( std::abs(a.covariance()-b.covariance())>tol){ 304 ok=false;305 *error<< "error covariance: " << a.covariance() << "\t"296 suite.ok(false); 297 suite.err() << "error covariance: " << a.covariance() << "\t" 306 298 << b.covariance() << std::endl; 307 299 } 308 300 if ( std::abs(a.correlation()-b.correlation())>tol ) { 309 ok=false;310 *error<< "error correlation" << std::endl;301 suite.ok(false); 302 suite.err() << "error correlation" << std::endl; 311 303 } 312 304 return ok; … … 314 306 315 307 bool equal(const AveragerPair& a, const AveragerPairWeighted& b, 316 const double tol, std::ostream* error)308 const u_int tol, Suite& suite) 317 309 { 318 310 bool ok = true; 319 311 if ( std::abs(a.covariance()-b.covariance())>tol){ 320 ok=false;321 *error<< "error covariance: " << a.covariance() << "\t"312 suite.ok(false); 313 suite.err() << "error covariance: " << a.covariance() << "\t" 322 314 << b.covariance() << std::endl; 323 315 } 324 316 if ( std::abs(a.correlation()-b.correlation())>tol ) { 325 ok=false;326 *error<< "error correlation" << std::endl;327 } 328 if ( !equal(a.x_averager(),b.x_averager(),tol, error)) {317 suite.ok(false); 318 suite.err() << "error correlation" << std::endl; 319 } 320 if ( !equal(a.x_averager(),b.x_averager(),tol,suite)) { 329 321 ok =false; 330 *error<< "error for x_averager():\t" << std::endl;322 suite.err() << "error for x_averager():\t" << std::endl; 331 323 } 332 324 return ok; 333 325 } 334 326 bool equal(const AveragerPairWeighted& a, const AveragerPairWeighted& b, 335 const double tol, std::ostream* error)327 const u_int tol, Suite& suite) 336 328 { 337 329 bool ok = true; 338 if ( std::abs(a.covariance()-b.covariance())>tol){339 ok=false;340 *error<< "error covariance: " << a.covariance() << "\t"330 if ( !test::equal(a.covariance(),b.covariance(),tol) ){ 331 suite.ok(false); 332 suite.err() << "error covariance: " << a.covariance() << "\t" 341 333 << b.covariance() << std::endl; 342 334 } 343 if ( std::abs(a.correlation()-b.correlation())>tol) {344 ok=false;345 *error<< "error correlation" << std::endl;346 } 347 if ( !equal(a.x_averager(),b.x_averager(),tol, error)) {335 if ( test::equal(a.correlation(), b.correlation(), tol) ) { 336 suite.ok(false); 337 suite.err() << "error correlation" << std::endl; 338 } 339 if ( !equal(a.x_averager(),b.x_averager(),tol,suite)) { 348 340 ok =false; 349 *error<< "error for x_averager():\t" << std::endl;341 suite.err() << "error for x_averager():\t" << std::endl; 350 342 } 351 343 return ok;
Note: See TracChangeset
for help on using the changeset viewer.