Changeset 1248
- Timestamp:
- Mar 20, 2008, 12:07:30 AM (15 years ago)
- Location:
- trunk/test
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/fileutil_test.cc
r1207 r1248 22 22 */ 23 23 24 #include "Suite.h" 25 24 26 #include "yat/utility/FileUtil.h" 25 27 #include "yat/utility/Exception.h" … … 29 31 #include <string> 30 32 31 int main(const int argc,const char* argv[]) 32 33 int main(int argc,char* argv[]) 33 34 { 34 35 using namespace theplu::yat; 35 36 std::ostream* error; 37 if (argc>1 && argv[1]==std::string("-v")) 38 error = &std::cerr; 39 else { 40 error = new std::ofstream("/dev/null"); 41 if (argc>1) 42 std::cout << "fileio_test -v : for printing extra information\n"; 43 } 44 *error << "testing FileUtil ... " << std::endl; 45 46 bool ok = true; 36 test::Suite suite(argc, argv); 37 suite.err() << "testing FileUtil ... " << std::endl; 47 38 48 39 // checking permissions for current directory 49 40 try { 50 *error<< "FileUtil Test 1" << std::endl;41 suite.err() << "FileUtil Test 1" << std::endl; 51 42 bool testval=true; 52 43 utility::FileUtil file("."); 53 44 if (testval=file.exists()) 54 *error<< "\tfile exists: " << file.path() << std::endl;55 ok&=testval;45 suite.err() << "\tfile exists: " << file.path() << std::endl; 46 suite.add(testval); 56 47 if (!(testval=file.permissions("rwx"))) 57 *error<< "\trwx permissions on " << file.path() << std::endl;58 ok&=!testval;48 suite.err() << "\trwx permissions on " << file.path() << std::endl; 49 suite.add(!testval); 59 50 if (!(testval=file.permissions("rx"))) 60 *error<< "\trx permissions on " << file.path() << std::endl;61 ok&=!testval;51 suite.err() << "\trx permissions on " << file.path() << std::endl; 52 suite.add(!testval); 62 53 if (!(testval=file.permissions("d"))) 63 *error<< "\td permissions on " << file.path() << std::endl;64 ok&=!testval;54 suite.err() << "\td permissions on " << file.path() << std::endl; 55 suite.add(!testval); 65 56 } 66 57 catch (utility::IO_error e) { 67 ok=false;68 *error<< e.what() << std::endl;58 suite.add(false); 59 suite.err() << e.what() << std::endl; 69 60 } 70 61 71 62 // checking permissions on non-existent file with ./ in path 72 63 try { 73 *error<< "FileUtil Test 2" << std::endl;64 suite.err() << "FileUtil Test 2" << std::endl; 74 65 bool testval=true; 75 66 // filename below should be unique 76 67 utility::FileUtil file("./fileio_test.sdf34DSF"); 77 *error<< "\tpath: " << std::endl;68 suite.err() << "\tpath: " << std::endl; 78 69 if (!(testval=file.exists())) 79 *error<< "\tfile does not exist: " << file.path() << std::endl;80 ok&=!testval;70 suite.err() << "\tfile does not exist: " << file.path() << std::endl; 71 suite.add(!testval); 81 72 if (!(testval=file.permissions("r"))) 82 *error<< "\tr permission on " << file.path() << std::endl;83 ok&=!testval;73 suite.err() << "\tr permission on " << file.path() << std::endl; 74 suite.add(!testval); 84 75 if (!(testval=file.permissions("rwx"))) 85 *error<< "\trwx permissions on " << file.path() << std::endl;86 ok&=!testval;76 suite.err() << "\trwx permissions on " << file.path() << std::endl; 77 suite.add(!testval); 87 78 if (!(testval=file.permissions("w"))) 88 *error<< "\tw permission on " << file.path() << std::endl;89 ok&=!testval; // 'w' on non-existent file ok if directory writeable79 suite.err() << "\tw permission on " << file.path() << std::endl; 80 suite.add(!testval); // 'w' on non-existent file ok if directory writeable 90 81 if (!(testval=file.permissions("d"))) 91 *error<< "\td permission on " << file.path() << std::endl;92 ok&=!testval;82 suite.err() << "\td permission on " << file.path() << std::endl; 83 suite.add(!testval); 93 84 } 94 85 catch (utility::IO_error e) { 95 ok=false;96 *error<< e.what() << std::endl;86 suite.add(false); 87 suite.err() << e.what() << std::endl; 97 88 } 98 89 99 90 // checking permissions on non-existent file without ./ in path 100 91 try { 101 *error<< "FileUtil Test 3" << std::endl;92 suite.err() << "FileUtil Test 3" << std::endl; 102 93 bool testval=true; 103 94 // filename below should be unique 104 95 utility::FileUtil file("fileio_test.sdf34DSF"); 105 96 if (!(testval=file.exists())) 106 *error<< "\tfile does not exist: " << file.path() << std::endl;107 ok&=!testval;97 suite.err() << "\tfile does not exist: " << file.path() << std::endl; 98 suite.add(!testval); 108 99 if (!(testval=file.permissions("r"))) 109 *error<< "\tr permission on " << file.path() << std::endl;110 ok&=!testval;100 suite.err() << "\tr permission on " << file.path() << std::endl; 101 suite.add(!testval); 111 102 if (!(testval=file.permissions("rwx"))) 112 *error<< "\trwx permissions on " << file.path() << std::endl;113 ok&=!testval;103 suite.err() << "\trwx permissions on " << file.path() << std::endl; 104 suite.add(!testval); 114 105 if (!(testval=file.permissions("w"))) 115 *error<< "\tw permission on " << file.path() << std::endl;116 ok&=!testval; // 'w' on non-existent file ok if directory writeable106 suite.err() << "\tw permission on " << file.path() << std::endl; 107 suite.add(!testval); // 'w' on non-existent file ok if directory writeable 117 108 if (!(testval=file.permissions("d"))) 118 *error<< "\td permission on " << file.path() << std::endl;119 ok&=!testval;109 suite.err() << "\td permission on " << file.path() << std::endl; 110 suite.add(!testval); 120 111 } 121 112 catch (utility::IO_error e) { 122 ok=false;123 *error<< e.what() << std::endl;113 suite.add(false); 114 suite.err() << e.what() << std::endl; 124 115 } 125 116 … … 127 118 // directories in path 128 119 try { 129 *error<< "FileUtil Test 4" << std::endl;120 suite.err() << "FileUtil Test 4" << std::endl; 130 121 bool testval=true; 131 122 // intermediate dir must be unique! 132 123 utility::FileUtil file("./fileio_test.sdf34DSF/file"); 133 124 if (!(testval=file.exists())) 134 *error<< "\tfile does not exist: " << file.path() << std::endl;135 ok&=!testval;125 suite.err() << "\tfile does not exist: " << file.path() << std::endl; 126 suite.add(!testval); 136 127 if ((testval=file.permissions("r"))) 137 *error<< "\tr permission failed on " << file.path() << std::endl;138 ok&=testval;128 suite.err() << "\tr permission failed on " << file.path() << std::endl; 129 suite.add(testval); 139 130 if (testval=file.permissions("rwx")) 140 *error<< "\trwx permissions failed on " << file.path() << std::endl;141 ok&=testval;131 suite.err() << "\trwx permissions failed on " << file.path() << std::endl; 132 suite.add(testval); 142 133 if (testval=file.permissions("w")) 143 *error<< "\tw permission failed on " << file.path() << std::endl;144 ok&=testval;134 suite.err() << "\tw permission failed on " << file.path() << std::endl; 135 suite.add(testval); 145 136 if (testval=file.permissions("d")) 146 *error<< "\td permission failed on " << file.path() << std::endl;147 ok&=testval;137 suite.err() << "\td permission failed on " << file.path() << std::endl; 138 suite.add(testval); 148 139 } 149 140 catch (utility::IO_error e) { 150 ok=false;151 *error<< e.what() << std::endl;141 suite.add(false); 142 suite.err() << e.what() << std::endl; 152 143 } 153 144 … … 155 146 // has been checked 156 147 try { 157 *error<< "FileUtil Test 5" << std::endl;148 suite.err() << "FileUtil Test 5" << std::endl; 158 149 bool testval=true; 159 150 // intermediate dir must be unique! 160 151 utility::FileUtil file("./fileio_test.sdf34DSF/file"); 161 152 if (!(testval=file.exists())) 162 *error<< "\tfile does not exist: " << file.path() << std::endl;163 ok&=!testval;153 suite.err() << "\tfile does not exist: " << file.path() << std::endl; 154 suite.add(!testval); 164 155 utility::FileUtil file2("fileutil_test.cc"); 165 156 if (!(testval=!file2.exists())) 166 *error<< "\tfile does exist: " << file2.path() << std::endl;167 ok&=!testval;157 suite.err() << "\tfile does exist: " << file2.path() << std::endl; 158 suite.add(!testval); 168 159 } 169 160 catch (utility::IO_error e) { 170 ok=false;171 *error<< e.what() << std::endl;161 suite.add(false); 162 suite.err() << e.what() << std::endl; 172 163 } 173 164 174 165 try { 175 *error<< "FileUtil Test 6" << std::endl;166 suite.err() << "FileUtil Test 6" << std::endl; 176 167 utility::FileUtil file("fileutil_test.cc"); 177 168 file.permissions("rxwa"); // should throw 178 ok = false;169 suite.add(false); 179 170 } 180 171 catch (std::invalid_argument& e) { 181 *error<< "Expected exception thrown with what: " << e.what() << std::endl;172 suite.err() << "Expected exception thrown with what: " << e.what() << std::endl; 182 173 } 183 174 184 185 186 187 *error << (ok ? "OK" : "Failed") << std::endl; 188 if (error!=&std::cerr) 189 delete error; 190 191 return (ok ? 0 : -1); 175 return suite.return_value(); 192 176 } -
trunk/test/score_test.cc
r1121 r1248 22 22 */ 23 23 24 #include "Suite.h" 25 24 26 #include "yat/classifier/Target.h" 25 27 #include "yat/statistics/FoldChange.h" … … 41 43 using namespace theplu::yat; 42 44 43 int main( const int argc,constchar* argv[])45 int main(int argc, char* argv[]) 44 46 { 45 std::ostream* error; 46 if (argc>1 && argv[1]==std::string("-v")) 47 error = &std::cerr; 48 else { 49 error = new std::ofstream("/dev/null"); 50 if (argc>1) 51 std::cout << "score_test -v : for printing extra information\n"; 52 } 53 *error << "testing score classes" << std::endl; 54 bool ok = true; 47 test::Suite suite(argc, argv); 55 48 56 *error << "testing AUC" << std::endl; 49 suite.err() << "testing score classes" << std::endl; 50 51 suite.err() << "testing AUC" << std::endl; 57 52 utility::Vector value(31); 58 53 std::vector<std::string> label(31,"negative"); … … 64 59 statistics::AUC auc(false); 65 60 double area = auc.score(target, value); 66 if ( area!=0.0){67 *error<< "test_auc: area is " << area << " should be 0.0"61 if (!(suite.equal(1-area,1))){ 62 suite.err() << "test_auc: area is " << area << " should be 0.0" 68 63 << std::endl; 69 ok = false;64 suite.add(false); 70 65 } 71 66 target.set_binary(0,false); 72 67 target.set_binary(1,true); 73 68 area = auc.score(target, value); 74 if ( area!=1.0){75 *error<< "test_auc: area is " << area << " should be 1.0"69 if (!suite.equal(area,1.0)){ 70 suite.err() << "test_auc: area is " << area << " should be 1.0" 76 71 << std::endl; 77 ok = false;72 suite.add(false); 78 73 } 79 74 … … 91 86 correct_area(2)=0.0; 92 87 93 const double tol = 0.001;94 88 for (size_t i=0; i<data.rows(); i++){ 95 89 utility::VectorView vec(data,i); 96 90 if (vec.size()!=target2.size()){ 97 *error<< "vec.size() is " << vec.size() << " and target2.size() is "91 suite.err() << "vec.size() is " << vec.size() << " and target2.size() is " 98 92 << target2.size() << ". Should be equal." << std::endl; 99 ok=false;93 suite.add(false); 100 94 } 101 95 area = auc.score(target2,vec); 102 if ( area<correct_area(i)-tol || area>correct_area(i)+tol){103 *error<< "test_roc: area is " << area << " should be "96 if (!suite.equal(area, correct_area(i)) ){ 97 suite.err() << "test_roc: area is " << area << " should be " 104 98 << correct_area(i) << std::endl; 105 ok=false;99 suite.add(false); 106 100 } 107 101 } … … 111 105 utility::VectorView vec = data.row_view(i); 112 106 area = auc.score(target2, vec, weight); 113 if ( area<correct_area(i)-tol || area>correct_area(i)+tol){114 *error<< "test_roc: weighted area is " << area << " should be "107 if (!suite.equal(area,correct_area(i)) ){ 108 suite.err() << "test_roc: weighted area is " << area << " should be " 115 109 << correct_area(i) << std::endl; 116 ok=false;110 suite.add(false); 117 111 } 118 112 } 119 113 120 *error<< "testing FoldChange" << std::endl;114 suite.err() << "testing FoldChange" << std::endl; 121 115 statistics::FoldChange fold_change(true); 122 116 123 *error<< "testing tScore" << std::endl;117 suite.err() << "testing tScore" << std::endl; 124 118 statistics::tScore t_score(true); 125 119 126 *error<< "testing Pearson" << std::endl;120 suite.err() << "testing Pearson" << std::endl; 127 121 statistics::Pearson pearson(true); 128 122 129 *error<< "testing WilcoxonFoldChange" << std::endl;123 suite.err() << "testing WilcoxonFoldChange" << std::endl; 130 124 statistics::WilcoxonFoldChange wfc(true); 131 125 132 *error<< "testing SAMScore" << std::endl;126 suite.err() << "testing SAMScore" << std::endl; 133 127 statistics::SAMScore sam(1.0,true); 134 128 135 *error<< "testing SNRScore" << std::endl;129 suite.err() << "testing SNRScore" << std::endl; 136 130 statistics::SNRScore snr(true); 137 131 138 132 139 if (ok) 140 return 0; 141 return -1; 133 return suite.return_value(); 142 134 } -
trunk/test/smart_ptr_test.cc
r1121 r1248 22 22 */ 23 23 24 #include "Suite.h" 25 24 26 #include "yat/utility/SmartPtr.h" 25 27 #include "yat/utility/Matrix.h" … … 28 30 #include <iostream> 29 31 30 int main(const int argc,const char* argv[]) 31 32 int main(int argc, char* argv[]) 32 33 { 33 34 using namespace theplu::yat; 34 35 35 std::ostream* error; 36 if (argc>1 && argv[1]==std::string("-v")) 37 error = &std::cerr; 38 else { 39 error = new std::ofstream("/dev/null"); 40 if (argc>1) 41 std::cout << "smart_ptr_test -v : for printing extra information\n"; 42 } 43 *error << "testing smart_ptr" << std::endl; 36 test::Suite suite(argc, argv); 44 37 45 bool ok = true;38 suite.err() << "testing smart_ptr" << std::endl; 46 39 47 40 utility::SmartPtr<utility::Matrix> m(new utility::Matrix(10,10)); … … 51 44 } 52 45 else 53 ok = false;46 suite.add(false); 54 47 55 48 m = m; … … 57 50 58 51 if (m->columns()!=10) 59 ok = false;52 suite.add(false); 60 53 61 if(ok) 62 *error << "OK" << std::endl; 63 else 64 *error << "Failed" << std::endl; 65 if (error!=&std::cerr) 66 delete error; 67 68 69 if (ok) 70 return 0; 71 return -1; 72 54 return suite.return_value(); 73 55 } -
trunk/test/statistics_test.cc
r1210 r1248 24 24 */ 25 25 26 #include "Suite.h" 27 26 28 #include "yat/statistics/utility.h" 27 29 #include "yat/utility/Vector.h" … … 32 34 #include <cmath> 33 35 34 int main( )36 int main(int argc, char* argv[]) 35 37 { 36 38 using namespace theplu::yat; 39 test::Suite suite(argc, argv); 40 37 41 utility::Vector gsl_vec(10); 38 42 std::vector<double> data; … … 45 49 double m_gsl=statistics::median(gsl_vec.begin(), gsl_vec.end()); 46 50 if (m!=4.5 || m!=m_gsl) 47 return -1;51 suite.add(false); 48 52 statistics::percentile(data.begin(), data.end(), 100); 49 53 data.resize(1); 50 54 statistics::median(data.begin(), data.end()); 51 55 52 double tolerance=1e-10;53 56 double skewness_gsl=statistics::skewness(gsl_vec); 54 if ( std::abs(skewness_gsl)>tolerance)55 return -1;57 if (!suite.equal(1-skewness_gsl, 1.0) ) 58 suite.add(false); 56 59 double kurtosis_gsl=statistics::kurtosis(gsl_vec); 57 if ( std::abs(kurtosis_gsl+1.5616363636363637113)>tolerance)58 return -1;60 if (!(std::abs(kurtosis_gsl+1.5616363636363637113)<1e-10) ) 61 suite.add(false); 59 62 return 0; 60 63 } -
trunk/test/subset_generator_test.cc
r1173 r1248 22 22 02111-1307, USA. 23 23 */ 24 25 #include "Suite.h" 24 26 25 27 #include "yat/classifier/BootstrapSampler.h" … … 41 43 using namespace theplu::yat; 42 44 43 bool class_count_test(const std::vector<size_t>&, std::ostream*);44 bool sample_count_test(const std::vector<size_t>&, std::ostream*);45 bool test_nested( std::ostream* error);46 bool test_cv( std::ostream*);47 bool test_creation( std::ostream* error);48 bool test_bootstrap( std::ostream* error);49 50 51 int main( const int argc,constchar* argv[])45 bool class_count_test(const std::vector<size_t>&, test::Suite&); 46 bool sample_count_test(const std::vector<size_t>&, test::Suite&); 47 bool test_nested(test::Suite&); 48 bool test_cv(test::Suite&); 49 bool test_creation(test::Suite&); 50 bool test_bootstrap(test::Suite&); 51 52 53 int main(int argc, char* argv[]) 52 54 { 53 std::ostream* error; 54 if (argc>1 && argv[1]==std::string("-v")) 55 error = &std::cerr; 56 else { 57 error = new std::ofstream("/dev/null"); 58 if (argc>1) 59 std::cout << "subset_generator -v : for printing extra information\n"; 60 } 61 *error << "testing subset_generator" << std::endl; 62 bool ok = true; 63 64 ok = ok && test_creation(error); 65 ok = ok && test_nested(error); 66 ok = ok && test_cv(error); 67 68 if (ok) 69 return 0; 70 return -1; 71 } 72 73 74 bool test_creation(std::ostream* error) 55 test::Suite suite(argc, argv); 56 suite.err() << "testing subset_generator" << std::endl; 57 58 test_creation(suite); 59 test_nested(suite); 60 test_cv(suite); 61 62 return suite.return_value(); 63 } 64 65 66 bool test_creation(test::Suite& suite) 75 67 { 76 68 bool ok=true; 77 69 std::ifstream is("data/nm_target_bin.txt"); 78 *error<< "loading target " << std::endl;70 suite.err() << "loading target " << std::endl; 79 71 classifier::Target target(is); 80 72 is.close(); 81 *error<< "number of targets: " << target.size() << std::endl;82 *error<< "number of classes: " << target.nof_classes() << std::endl;73 suite.err() << "number of targets: " << target.size() << std::endl; 74 suite.err() << "number of classes: " << target.nof_classes() << std::endl; 83 75 is.open("data/nm_data_centralized.txt"); 84 *error<< "loading data " << std::endl;76 suite.err() << "loading data " << std::endl; 85 77 utility::Matrix m(is); 86 78 is.close(); 87 79 classifier::MatrixLookup data(m); 88 *error<< "number of samples: " << data.columns() << std::endl;89 *error<< "number of features: " << data.rows() << std::endl;80 suite.err() << "number of samples: " << data.columns() << std::endl; 81 suite.err() << "number of features: " << data.rows() << std::endl; 90 82 assert(data.columns()==target.size()); 91 83 92 *error<< "building kernel" << std::endl;84 suite.err() << "building kernel" << std::endl; 93 85 classifier::PolynomialKernelFunction kf(1); 94 86 classifier::Kernel_SEV kernel_core(data,kf); 95 87 classifier::KernelLookup kernel(kernel_core); 96 *error<< "building Sampler" << std::endl;88 suite.err() << "building Sampler" << std::endl; 97 89 classifier::CrossValidationSampler sampler(target, 30, 3); 98 90 99 91 statistics::AUC score; 100 92 classifier::FeatureSelectorIR fs(score, 96, 0); 101 *error<< "building SubsetGenerator" << std::endl;93 suite.err() << "building SubsetGenerator" << std::endl; 102 94 classifier::SubsetGenerator<classifier::MatrixLookup> 103 95 subset_data(sampler, data, fs); … … 107 99 } 108 100 109 bool test_nested( std::ostream* error)101 bool test_nested(test::Suite& suite) 110 102 { 111 103 bool ok=true; … … 114 106 // 115 107 116 *error<< "\ntesting two nested crossplitters" << std::endl;108 suite.err() << "\ntesting two nested crossplitters" << std::endl; 117 109 std::vector<std::string> label(9); 118 110 label[0]=label[1]=label[2]="0"; … … 156 148 if(test_target(i)!=target(test_index[i])) { 157 149 ok=false; 158 *error<< "ERROR: incorrect mapping of test indices" << std:: endl;150 suite.err() << "ERROR: incorrect mapping of test indices" << std:: endl; 159 151 } 160 152 } … … 180 172 || test_index.size()+v_index.size()+t_index.size() != target.size()){ 181 173 ok = false; 182 *error<< "ERROR: size of training samples, validation samples "174 suite.err() << "ERROR: size of training samples, validation samples " 183 175 << "and test samples in is invalid." 184 176 << std::endl; … … 187 179 v_index.size()!=3){ 188 180 ok = false; 189 *error<< "ERROR: size of training, validation, and test samples"181 suite.err() << "ERROR: size of training, validation, and test samples" 190 182 << " is invalid." 191 183 << " Expected sizes to be 3" << std::endl; … … 211 203 } 212 204 213 ok = ok && sample_count_test(tv_sample_count, error);214 215 } 216 ok = ok && sample_count_test(v_sample_count, error);217 ok = ok && sample_count_test(t_sample_count, error);205 ok = ok && sample_count_test(tv_sample_count,suite); 206 207 } 208 ok = ok && sample_count_test(v_sample_count,suite); 209 ok = ok && sample_count_test(t_sample_count,suite); 218 210 219 ok = ok && class_count_test(t_class_count, error);220 ok = ok && class_count_test(t_class_count2, error);221 ok = ok && class_count_test(v_class_count, error);222 223 224 } 225 ok = ok && sample_count_test(test_sample_count, error);226 ok = ok && class_count_test(test_class_count, error);211 ok = ok && class_count_test(t_class_count,suite); 212 ok = ok && class_count_test(t_class_count2,suite); 213 ok = ok && class_count_test(v_class_count,suite); 214 215 216 } 217 ok = ok && sample_count_test(test_sample_count,suite); 218 ok = ok && class_count_test(test_class_count,suite); 227 219 228 220 if(test_value1[0]!=135 || test_value1[1]!=36 || test_value1[2]!=45 || 229 221 test_value1[3]!=54) { 230 222 ok=false; 231 *error<< "ERROR: incorrect sums of test values in row 1"223 suite.err() << "ERROR: incorrect sums of test values in row 1" 232 224 << " found: " << test_value1[0] << ", " << test_value1[1] 233 225 << ", " << test_value1[2] << " and " << test_value1[3] … … 239 231 test_value2[3]!=84) { 240 232 ok=false; 241 *error<< "ERROR: incorrect sums of test values in row 2"233 suite.err() << "ERROR: incorrect sums of test values in row 2" 242 234 << " found: " << test_value2[0] << ", " << test_value2[1] 243 235 << ", " << test_value2[2] << " and " << test_value2[3] … … 247 239 if(t_value[0]!=270 || t_value[1]!=72 || t_value[2]!=90 || t_value[3]!=108) { 248 240 ok=false; 249 *error<< "ERROR: incorrect sums of training values in row 1"241 suite.err() << "ERROR: incorrect sums of training values in row 1" 250 242 << " found: " << t_value[0] << ", " << t_value[1] 251 243 << ", " << t_value[2] << " and " << t_value[3] … … 255 247 if(v_value[0]!=270 || v_value[1]!=72 || v_value[2]!=90 || v_value[3]!=108) { 256 248 ok=false; 257 *error<< "ERROR: incorrect sums of validation values in row 1"249 suite.err() << "ERROR: incorrect sums of validation values in row 1" 258 250 << " found: " << v_value[0] << ", " << v_value[1] 259 251 << ", " << v_value[2] << " and " << v_value[3] … … 264 256 265 257 bool class_count_test(const std::vector<size_t>& class_count, 266 std::ostream* error)258 test::Suite& suite) 267 259 { 268 260 bool ok=true; … … 270 262 if (class_count[i]==0){ 271 263 ok = false; 272 *error<< "ERROR: class " << i << " was not in set."264 suite.err() << "ERROR: class " << i << " was not in set." 273 265 << " Expected at least one sample from each class." 274 266 << std::endl; … … 278 270 279 271 bool sample_count_test(const std::vector<size_t>& sample_count, 280 std::ostream* error)272 test::Suite& suite) 281 273 { 282 274 bool ok=true; … … 284 276 if (sample_count[i]!=1){ 285 277 ok = false; 286 *error<< "ERROR: sample " << i << " was in a group " << sample_count[i]278 suite.err() << "ERROR: sample " << i << " was in a group " << sample_count[i] 287 279 << " times." << " Expected to be 1 time" << std::endl; 288 280 } … … 292 284 293 285 294 bool test_bootstrap( std::ostream* error)286 bool test_bootstrap(test::Suite& suite) 295 287 { 296 288 bool ok=true; … … 309 301 310 302 311 bool test_cv( std::ostream* error)303 bool test_cv(test::Suite& suite) 312 304 { 313 305 bool ok=true; … … 330 322 target.size()){ 331 323 ok = false; 332 *error<< "ERROR: size of training samples plus "324 suite.err() << "ERROR: size of training samples plus " 333 325 << "size of validation samples is invalid." << std::endl; 334 326 } 335 327 if (cv.validation_index(j).size()!=3 && cv.validation_index(j).size()!=4){ 336 328 ok = false; 337 *error<< "ERROR: size of validation samples is invalid."329 suite.err() << "ERROR: size of validation samples is invalid." 338 330 << "expected size to be 3 or 4" << std::endl; 339 331 } … … 345 337 class_count[target(cv.training_index(j)[i])]++; 346 338 } 347 ok = ok && class_count_test(class_count, error);348 } 349 ok = ok && sample_count_test(sample_count, error);350 351 return ok; 352 } 339 ok = ok && class_count_test(class_count,suite); 340 } 341 ok = ok && sample_count_test(sample_count,suite); 342 343 return ok; 344 } -
trunk/test/svd_test.cc
r1151 r1248 25 25 */ 26 26 27 #include "Suite.h" 28 27 29 #include "yat/random/random.h" 28 30 #include "yat/utility/Matrix.h" … … 32 34 using namespace theplu::yat; 33 35 34 double this_norm(const utility::Matrix& A) 36 void do_test(size_t m, size_t n, utility::SVD::SVDalgorithm algo, 37 test::Suite& suite) 35 38 { 36 double sum=0.0;37 for (size_t i=0; i<A.rows(); ++i)38 for (size_t j=0; j<A.columns(); ++j)39 sum += A(i,j)*A(i,j);40 return sum;41 }42 43 44 45 bool test(size_t m, size_t n, utility::SVD::SVDalgorithm algo)46 {47 double MAXTOL=1e-13; // accepted error48 49 39 // initialise a random test-matrix 50 40 theplu::yat::random::ContinuousUniform rnd; 41 42 // set seed to make test deterministic 43 theplu::yat::random::RNG::instance()->seed(20); 44 51 45 utility::Matrix A(m,n); 52 46 for (size_t i=0; i<m; ++i) … … 66 60 Areconstruct*=S; 67 61 Areconstruct*=Vtranspose; 68 Areconstruct-=A; // Expect null matrix 69 double error = this_norm(Areconstruct); 70 bool testerror=false; 71 if (error>MAXTOL) { 72 std::cerr << "test_svd: FAILED, algorithm " << algo 73 << " recontruction error (" 74 << error << ") > tolerance (" << MAXTOL << "), matrix dimension (" 75 << m << ',' << n << ')' << std::endl; 76 testerror=true; 62 if (!suite.equal_range(A.begin(), A.end(), Areconstruct.begin(), 1000)) { 63 suite.err() << "test_svd: FAILED, algorithm " << algo << std::endl; 64 suite.err() << "reconstruction error" << std::endl; 65 suite.add(false); 77 66 } 78 67 79 68 Vtranspose*=svd.V(); // Expect unity matrix 80 error=this_norm(Vtranspose)-n; 81 if (error>MAXTOL) { 82 std::cerr << "test_svd: FAILED, algorithm " << algo 83 << " V orthogonality error (" 84 << error << ") > tolerance (" << MAXTOL << ')' << std::endl; 85 testerror=true; 69 Vtranspose += 1.0; 70 utility::Matrix eye(Vtranspose.rows(), Vtranspose.columns(), 1.0); 71 for (size_t i=0; i<eye.rows() && i<eye.columns(); ++i) 72 eye(i,i)=2.0; 73 if (!suite.equal_range(eye.begin(), eye.end(), Vtranspose.begin(), 100) ) { 74 suite.err() << "test_svd: FAILED, algorithm " << algo 75 << " V orthogonality error " << std::endl; 76 suite.add(false); 86 77 } 87 78 … … 89 80 Utranspose.transpose(); 90 81 Utranspose*=svd.U(); // Expect unity matrix 91 error=this_norm(Utranspose)-n; 92 if (error>MAXTOL) { 93 std::cerr << "test_svd: FAILED, algorithm " << algo 94 << " U orthogonality error (" 95 << error << ") > tolerance (" << MAXTOL << ')' << std::endl; 96 testerror=true; 82 Utranspose += 1.0; 83 eye = utility::Matrix(Utranspose.rows(), Utranspose.columns(), 1.0); 84 for (size_t i=0; i<eye.rows() && i<eye.columns(); ++i) 85 eye(i,i)=2.0; 86 if (!suite.equal_range(eye.begin(), eye.end(), Utranspose.begin(), 100) ) { 87 suite.err() << "test_svd: FAILED, algorithm " << algo 88 << " U orthogonality error " << std::endl; 89 suite.add(false); 97 90 } 98 return testerror;99 91 } 100 92 101 93 102 94 103 int main( const int argc,constchar* argv[])95 int main(int argc, char* argv[]) 104 96 { 105 bool testfail=false;97 theplu::yat::test::Suite suite(argc, argv); 106 98 107 99 // The GSL Jacobi, Golub-Reinsch, and modified Golub-Reinsch 108 100 // implementations supports rows>=columns matrix dimensions only 109 testfail|=test(12,12,utility::SVD::GolubReinsch);110 testfail|=test(12,4,utility::SVD::GolubReinsch);111 testfail|=test(12,12,utility::SVD::ModifiedGolubReinsch);112 testfail|=test(12,4,utility::SVD::ModifiedGolubReinsch);113 testfail|=test(12,12,utility::SVD::Jacobi);114 testfail|=test(12,4,utility::SVD::Jacobi);101 do_test(12,12,utility::SVD::GolubReinsch, suite); 102 do_test(12,4,utility::SVD::GolubReinsch, suite); 103 do_test(12,12,utility::SVD::ModifiedGolubReinsch, suite); 104 do_test(12,4,utility::SVD::ModifiedGolubReinsch, suite); 105 do_test(12,12,utility::SVD::Jacobi, suite); 106 do_test(12,4,utility::SVD::Jacobi, suite); 115 107 116 return (testfail ? -1 : 0);108 return suite.return_value(); 117 109 } -
trunk/test/svm_test.cc
r1210 r1248 24 24 */ 25 25 26 #include "Suite.h" 27 26 28 #include "yat/classifier/SVM.h" 27 29 #include "yat/classifier/Kernel.h" … … 43 45 using namespace theplu::yat; 44 46 45 int main( const int argc,constchar* argv[])47 int main( int argc, char* argv[]) 46 48 { 47 48 std::ostream* error; 49 if (argc>1 && argv[1]==std::string("-v")) 50 error = &std::cerr; 51 else { 52 error = new std::ofstream("/dev/null"); 53 if (argc>1) 54 std::cout << "svm_test -v : for printing extra information\n"; 55 } 56 *error << "testing svm" << std::endl; 57 bool ok = true; 49 test::Suite suite(argc, argv); 50 suite.err() << "testing svm" << std::endl; 58 51 59 52 utility::Matrix data2_core(2,3); … … 77 70 for (size_t i=0; i<3; i++){ 78 71 for (size_t j=0; j<3; j++) 79 *error<< kernel2(i,j) << " ";80 *error<< std::endl;72 suite.err() << kernel2(i,j) << " "; 73 suite.err() << std::endl; 81 74 } 82 75 classifier::KernelLookup kv2(kernel2); 83 *error<< "testing with linear kernel" << std::endl;76 suite.err() << "testing with linear kernel" << std::endl; 84 77 assert(kv2.rows()==target2.size()); 85 78 classifier::SVM classifier2; 86 *error<< "training...";79 suite.err() << "training..."; 87 80 classifier2.train(kv2, target2); 88 *error<< " done!" << std::endl;81 suite.err() << " done!" << std::endl; 89 82 90 83 double tmp=0; … … 96 89 97 90 if (tmp){ 98 *error<< "ERROR: found " << tmp << " expected zero" << std::endl;91 suite.err() << "ERROR: found " << tmp << " expected zero" << std::endl; 99 92 return -1; 100 93 } … … 103 96 if (std::abs(classifier2.alpha()(1)-2)>tol || 104 97 std::abs(classifier2.alpha()(2)-2)>tol){ 105 *error<< "wrong alpha" << std::endl;106 *error<< "alpha: " << classifier2.alpha() << std::endl;107 *error<< "expected: 4 2 2" << std::endl;98 suite.err() << "wrong alpha" << std::endl; 99 suite.err() << "alpha: " << classifier2.alpha() << std::endl; 100 suite.err() << "expected: 4 2 2" << std::endl; 108 101 109 102 return -1; … … 139 132 theplu::yat::utility::Vector diff_alpha(alpha); 140 133 diff_alpha-=alpha_matlab; 141 if ( diff_alpha*diff_alpha> 1e-10){142 *error<< "Difference to matlab alphas too large\n";143 ok=false;134 if (!(diff_alpha*diff_alpha<1e-10) ){ 135 suite.err() << "Difference to matlab alphas too large\n"; 136 suite.add(false); 144 137 } 145 138 … … 157 150 double slack_bound=2e-7; 158 151 if (slack > slack_bound || std::isnan(slack)){ 159 *error<< "Slack too large. Is the bias correct?\n";160 *error<< "slack: " << slack << std::endl;161 *error<< "expected less than " << slack_bound << std::endl;162 ok = false;152 suite.err() << "Slack too large. Is the bias correct?\n"; 153 suite.err() << "slack: " << slack << std::endl; 154 suite.err() << "expected less than " << slack_bound << std::endl; 155 suite.add(false); 163 156 } 164 157 … … 166 159 delete kf2; 167 160 168 if (error!=&std::cerr) 169 delete error; 170 171 if(ok) 172 return 0; 173 return -1; 174 161 return suite.return_value(); 175 162 } -
trunk/test/target_test.cc
r1134 r1248 22 22 */ 23 23 24 #include "Suite.h" 25 24 26 #include "yat/classifier/Target.h" 25 27 #include "yat/utility/Index.h" … … 32 34 using namespace theplu::yat; 33 35 34 int main( const int argc,constchar* argv[])36 int main( int argc, char* argv[]) 35 37 { 36 std::ostream* error; 37 if (argc>1 && argv[1]==std::string("-v")) 38 error = &std::cerr; 39 else { 40 error = new std::ofstream("/dev/null"); 41 if (argc>1) 42 std::cout << "target_test -v : for printing extra information\n"; 43 } 44 *error << "testing target" << std::endl; 45 bool ok = true; 38 test::Suite suite(argc, argv); 39 suite.err() << "testing target" << std::endl; 46 40 47 41 // This test assumes classes are introduced in order of appearence … … 60 54 for (size_t i=0; i<facit.size(); i++){ 61 55 if (target3(i)!=facit[i]){ 62 ok=false;63 *error<< "target(" << i << ") is " << target3(0) << " expected "56 suite.add(false); 57 suite.err() << "target(" << i << ") is " << target3(0) << " expected " 64 58 << facit[i] << std::endl; 65 59 } … … 70 64 classifier::Target sub_target(target3,utility::Index(sub)); 71 65 if (target3(sub[0])!=sub_target(0) || target3(sub[1])!=sub_target(1)){ 72 ok = false;73 *error<< "error in constructor Target(const Target&, std::vector<size_t>&)"66 suite.add(false); 67 suite.err() << "error in constructor Target(const Target&, std::vector<size_t>&)" 74 68 << "\nclasses are not preserved" << std::endl; 75 69 } 76 70 if (target3.binary(sub[0])!=sub_target.binary(0) || 77 71 target3.binary(sub[1])!=sub_target.binary(1)){ 78 ok = false;79 *error<< "error in constructor Target(const Target&, std::vector<size_t>&)"72 suite.add(false); 73 suite.err() << "error in constructor Target(const Target&, std::vector<size_t>&)" 80 74 << "\nbinary classes are not preserved" << std::endl; 81 75 } … … 88 82 classifier::Target target(label); 89 83 if (target.nof_classes()!=3){ 90 ok=false;91 *error<< "Expected number of classes to be 3" << std::endl;84 suite.add(false); 85 suite.err() << "Expected number of classes to be 3" << std::endl; 92 86 } 93 87 if (target(0)!=0){ 94 ok=false;95 *error<< "Error: target(0)!=0" << std::endl;88 suite.add(false); 89 suite.err() << "Error: target(0)!=0" << std::endl; 96 90 } 97 91 if (target(20)!=2){ 98 ok=false;99 *error<< "Error: target(20)!=2" << std::endl;92 suite.add(false); 93 suite.err() << "Error: target(20)!=2" << std::endl; 100 94 } 101 95 if (!target.binary(0)){ 102 ok=false;103 *error<< "Error: target.binary(0) not true" << std::endl;96 suite.add(false); 97 suite.err() << "Error: target.binary(0) not true" << std::endl; 104 98 } 105 99 if (target.binary(20)){ 106 ok=false;107 *error<< "Error: target.binary(20) not false" << std::endl;100 suite.add(false); 101 suite.err() << "Error: target.binary(20) not false" << std::endl; 108 102 } 109 103 target.set_binary(2,true); 110 104 if (!target.binary(20)){ 111 ok=false;112 *error<< "Error: target.binary(20) not true" << std::endl;105 suite.add(false); 106 suite.err() << "Error: target.binary(20) not true" << std::endl; 113 107 } 114 108 std::ifstream is("data/rank_target.txt"); … … 116 110 is.close(); 117 111 if (target2.size()!=6){ 118 ok=false;119 *error << "ERROR: size of target is " << target2.size() << " expected 6."120 << std::endl;112 suite.add(false); 113 suite.err() << "ERROR: size of target is " << target2.size() 114 << " expected 6." << std::endl; 121 115 } 122 116 123 if (ok) 124 return 0; 125 return -1; 117 suite.return_value(); 126 118 } -
trunk/test/ttest_test.cc
r1145 r1248 22 22 */ 23 23 24 #include "Suite.h" 25 24 26 #include "yat/classifier/Target.h" 25 27 #include "yat/statistics/tTest.h" … … 34 36 using namespace theplu::yat; 35 37 36 int main( const int argc,constchar* argv[])38 int main(int argc, char* argv[]) 37 39 { 38 std::ostream* error; 39 if (argc>1 && argv[1]==std::string("-v")) 40 error = &std::cerr; 41 else { 42 error = new std::ofstream("/dev/null"); 43 if (argc>1) 44 std::cout << "ttest_test -v : for printing extra information\n"; 45 } 46 bool ok = true; 40 test::Suite suite(argc, argv); 47 41 48 *error<< "testing ttest" << std::endl;42 suite.err() << "testing ttest" << std::endl; 49 43 utility::Vector value(31); 50 44 std::vector<std::string> label(31,"positive"); … … 60 54 double p = test.p_value_one_sided(); 61 55 double p2 = test.p_value(); 62 if ( p2 != 2*p){63 ok = false;64 *error<< "Two-sided P-value should equal 2 * one-sided P-value.\n";56 if (!suite.equal(p2, 2*p) ){ 57 suite.add(false); 58 suite.err() << "Two-sided P-value should equal 2 * one-sided P-value.\n"; 65 59 } 66 60 67 if (ok) 68 return 0; 69 return -1; 61 return suite.return_value(); 70 62 } -
trunk/test/utility_test.cc
r1195 r1248 22 22 */ 23 23 24 #include "Suite.h" 25 24 26 #include "yat/utility/utility.h" 25 27 … … 28 30 #include <string> 29 31 30 int main(const int argc,const char* argv[]) 31 32 int main(int argc, char* argv[]) 32 33 { 33 34 using namespace theplu::yat; 34 35 std::ostream* error; 36 if (argc>1 && argv[1]==std::string("-v")) 37 error = &std::cerr; 38 else { 39 error = new std::ofstream("/dev/null"); 40 if (argc>1) 41 std::cout << "utility_test -v : for printing extra information\n"; 42 } 43 *error << "testing utility ... " << std::endl; 44 45 bool ok = true; 35 test::Suite suite(argc, argv); 36 suite.err() << "testing utility ... " << std::endl; 46 37 47 38 // test float/double 48 39 std::string s("1.2"); 49 40 if (!utility::is_double(s)){ 50 ok=false;41 suite.add(false); 51 42 } 52 43 else if (!utility::is_float(s)) { 53 ok=false;44 suite.add(false); 54 45 } 55 46 else if (utility::is_int(s)) { 56 ok=false;47 suite.add(false); 57 48 } 58 49 else if (utility::is_nan(s)) { 59 ok=false;50 suite.add(false); 60 51 } 61 52 … … 63 54 s="23"; 64 55 if (!utility::is_double(s)){ 65 ok=false;56 suite.add(false); 66 57 } 67 58 else if (!utility::is_float(s)) { 68 ok=false;59 suite.add(false); 69 60 } 70 61 else if (!utility::is_int(s)) { 71 ok=false;62 suite.add(false); 72 63 } 73 64 else if (utility::is_nan(s)) { 74 ok=false;65 suite.add(false); 75 66 } 76 67 … … 78 69 s=" nAn "; 79 70 if (!utility::is_double(s)){ 80 ok=false;71 suite.add(false); 81 72 } 82 73 else if (!utility::is_float(s)) { 83 ok=false;74 suite.add(false); 84 75 } 85 76 else if (!utility::is_int(s)) { 86 ok=false;77 suite.add(false); 87 78 } 88 79 else if (!utility::is_nan(s)) { 89 ok=false;80 suite.add(false); 90 81 } 91 82 … … 93 84 s=" 23 23 "; 94 85 if (utility::is_double(s)){ 95 ok=false;86 suite.add(false); 96 87 } 97 88 else if (utility::is_float(s)) { 98 ok=false;89 suite.add(false); 99 90 } 100 91 else if (utility::is_int(s)) { 101 ok=false;92 suite.add(false); 102 93 } 103 94 else if (utility::is_nan(s)) { 104 ok=false;95 suite.add(false); 105 96 } 106 97 107 98 if (utility::convert<double>("1.23")!=1.23) 108 ok = false;99 suite.add(false); 109 100 utility::convert<double>("-inf"); 110 101 utility::convert<double>("inf"); 111 102 utility::convert<double>("NaN"); 112 103 113 if(ok) 114 *error << "OK" << std::endl; 115 else 116 *error << "Failed" << std::endl; 117 if (error!=&std::cerr) 118 delete error; 119 120 121 if (ok) 122 return 0; 123 return -1; 124 104 return suite.return_value(); 125 105 } -
trunk/test/vector_test.cc
r1151 r1248 24 24 02111-1307, USA. 25 25 */ 26 27 #include "Suite.h" 26 28 27 29 #include "yat/utility/Exception.h" … … 46 48 } 47 49 48 int main( const int argc,constchar* argv[])50 int main(int argc,char* argv[]) 49 51 { 50 std::ostream* message; 51 if (argc>1 && argv[1]==std::string("-v")) 52 message = &std::cerr; 53 else { 54 message = new std::ofstream("/dev/null"); 55 if (argc>1) 56 std::cout << "vector_test -v : for printing extra " << "information\n"; 57 } 58 *message << "testing vector" << std::endl; 59 bool ok = true; 52 test::Suite suite(argc, argv); 53 suite.err() << "testing vector" << std::endl; 60 54 61 55 utility::Vector vec(12); … … 64 58 65 59 // checking that shuffle works 66 *message<< "shuffle" << std::endl;60 suite.err() << "shuffle" << std::endl; 67 61 double sum_before = utility::sum(vec); 68 62 shuffle(vec); 69 63 double sum_after = utility::sum(vec); 70 64 if (sum_after!=sum_before){ 71 *message<< "shuffle failed" << std::endl;72 ok = false;65 suite.err() << "shuffle failed" << std::endl; 66 suite.add(false); 73 67 } 74 68 75 69 // checking that view works 76 *message<< "view" << std::endl;70 suite.err() << "view" << std::endl; 77 71 sum_before=0; 78 72 for (size_t i=0; i<vec.size(); i+=2) … … 80 74 utility::VectorView vec_view(vec,0,6,2); 81 75 sum_after=utility::sum(vec_view); 82 ok &= (sum_after==sum_before);76 suite.add(suite.equal(sum_after, sum_before)); 83 77 vec(0)=0; 84 78 vec_view(0)=24; 85 ok &= (vec(0)==vec_view(0));79 suite.add(suite.equal(vec(0), vec_view(0))); 86 80 87 81 // Test of const view implementation (make sure no zero pointer is … … 90 84 // core dump! 91 85 { 92 *message<< "const view implementation" << std::endl;86 suite.err() << "const view implementation" << std::endl; 93 87 const utility::Vector vv(10,3.0); 94 88 utility::VectorConstView vview(vv,0,5,1); … … 97 91 vv2.mul(vview); // should work even without const since const arg passing 98 92 vv2.div(vview); // should work even without const since const arg passing 99 ok &= (vview*vview == 3.0*3.0*vview.size());93 suite.add(suite.equal(vview*vview, 3.0*3.0*vview.size())); 100 94 } 101 95 … … 103 97 // a non-view vector is copied 104 98 { 105 *message<< "copy constructor" << std::endl;99 suite.err() << "copy constructor" << std::endl; 106 100 utility::Vector vec2(vec); 107 ok &=(vec.size()==vec2.size());108 ok &= (vec2==vec);109 ok &=(&vec2 != &vec);110 ok &= !vec2.isview();101 suite.add(vec.size()==vec2.size()); 102 suite.add(suite.equal_range(vec2.begin(), vec2.end(), vec.begin())); 103 suite.add(&vec2 != &vec); 104 suite.add(!vec2.isview()); 111 105 } 112 106 … … 114 108 // a view vector is copied 115 109 { 116 *message<< "copy contructor on view" << std::endl;110 suite.err() << "copy contructor on view" << std::endl; 117 111 utility::Vector vec3(vec_view); 118 ok &=(vec_view.size()==vec3.size());119 ok &= (vec3 == vec_view);120 ok &= !vec3.isview();112 suite.add(vec_view.size()==vec3.size()); 113 suite.add(suite.equal_range(vec3.begin(), vec3.end(), vec_view.begin())); 114 suite.add(!vec3.isview()); 121 115 } 122 116 … … 124 118 // differ in size 125 119 { 126 *message<< "assignment operator" << std::endl;120 suite.err() << "assignment operator" << std::endl; 127 121 // GSL will catch the error in this test there for the GSL error 128 122 // handling must be disabled until after the exception is … … 138 132 } 139 133 if (!exception_happens) { 140 *message<< "Vector assignment operator did not throw expected exception"134 suite.err() << "Vector assignment operator did not throw expected exception" 141 135 << std::endl; 142 ok=false;136 suite.add(false); 143 137 } 144 138 gsl_set_error_handler(err_handler); … … 148 142 // a view is changed. 149 143 { 150 *message<< "assignment operator on view" << std::endl;144 suite.err() << "assignment operator on view" << std::endl; 151 145 vec(3)=vec(4)=vec(5)=13; 152 146 utility::VectorView vec_view(vec,3,3,1); … … 154 148 vec_view=vec2; 155 149 if (vec(3)!=vec_view(0) || vec(4)!=vec_view(1) || vec(5)!=vec_view(2)){ 156 *message<< " failed\n";157 ok=false;150 suite.err() << " failed\n"; 151 suite.add(false); 158 152 } 159 153 } … … 161 155 // checking clone functionality 162 156 { 163 *message<< "clone functionality" << std::endl;157 suite.err() << "clone functionality" << std::endl; 164 158 bool this_ok=true; 165 *message<< "\tcloning normal vector" << std::endl;159 suite.err() << "\tcloning normal vector" << std::endl; 166 160 utility::Vector vec2(3,123.0); 167 161 vec2 = vec; … … 174 168 if (vec.gsl_vector_p()==vec2.gsl_vector_p()) 175 169 this_ok=false; 176 *message<< "\tcloning vector view" << std::endl;170 suite.err() << "\tcloning vector view" << std::endl; 177 171 utility::VectorView* vec_view=new utility::VectorView(vec,3,3,1); 178 172 utility::VectorView vec_view2(*vec_view); … … 185 179 if ((*vec_view)(i)!=vec_view2(i)) 186 180 this_ok=false; 187 *message<< "\tcloned vector view independence" << std::endl;181 suite.err() << "\tcloned vector view independence" << std::endl; 188 182 delete vec_view; 189 183 if (vec(3)!=vec_view2(0) || vec(4)!=vec_view2(1) || vec(5)!=vec_view2(2)) … … 191 185 192 186 if (!this_ok) { 193 *message<< "FAIL: clone test" << std::endl;194 ok=false;187 suite.err() << "FAIL: clone test" << std::endl; 188 suite.add(false); 195 189 } 196 190 } … … 198 192 // checking that reading vectors from properly formatted files works 199 193 try { 200 *message<< "stream" << std::endl;194 suite.err() << "stream" << std::endl; 201 195 std::string data1("data/vector1.data"); 202 196 std::string data2("data/vector2.data"); … … 212 206 std::ifstream data_stream4(data4.c_str()); 213 207 utility::Vector vec1(data_stream1); 214 ok &=(vec1.size()==9);208 suite.add(vec1.size()==9); 215 209 vec1=utility::Vector(data_stream2); 216 ok &=(vec1.size()==9);210 suite.add(vec1.size()==9); 217 211 utility::Vector vec2(data_stream3); 218 ok &=(vec2.size()==12);212 suite.add(vec2.size()==12); 219 213 vec2=utility::Vector(data_stream4); 220 ok &=(vec2.size()==12);214 suite.add(vec2.size()==12); 221 215 } catch (utility::IO_error& err) { 222 *message<< err.what() << std::endl;223 ok=false;216 suite.err() << err.what() << std::endl; 217 suite.add(false); 224 218 } 225 219 … … 227 221 // vector stream output operator produces. 228 222 { 229 *message<< "checking that output stream is valid as an input stream"223 suite.err() << "checking that output stream is valid as an input stream" 230 224 << std::endl; 231 225 std::stringstream s; 232 226 s << vec; 233 227 utility::Vector vec2(s); 234 ok &= (vec==vec2);228 suite.add(suite.equal_range(vec.begin(), vec.end(), vec2.begin())); 235 229 } 236 230 237 231 // Checking that badly formatted files are not accepted, or at least 238 232 // throws an exception for the programmer to catch. 239 *message<< "checking that bad stream are rejected" << std::endl;233 suite.err() << "checking that bad stream are rejected" << std::endl; 240 234 bool this_ok=false; 241 235 // Checking that unexpected characters in a stream gives error. … … 246 240 utility::Vector dummy(data_stream5); // this will give an exception 247 241 } catch (utility::IO_error& err) { 248 *message<< err.what() << std::endl;242 suite.err() << err.what() << std::endl; 249 243 this_ok=true; // good, exception thrown, test passed 250 244 } … … 255 249 utility::Vector dummy(data_stream); // this will give an exception 256 250 } catch (utility::IO_error& err) { 257 *message<< err.what() << std::endl;251 suite.err() << err.what() << std::endl; 258 252 this_ok=true; // good, exceoption thrown, test passed 259 253 } 260 ok &= this_ok;254 suite.add(this_ok); 261 255 262 256 this_ok=false; … … 267 261 vec=utility::Vector(data_stream); // this will give an exception 268 262 } catch (utility::IO_error& err) { 269 *message<< err.what() << std::endl;263 suite.err() << err.what() << std::endl; 270 264 this_ok=true; // good, exceoption thrown, test passed 271 265 } 272 ok &= this_ok;266 suite.add(this_ok); 273 267 274 268 … … 283 277 utility::sort_index(dummy,vec3); 284 278 if(dummy.size()!=vec3.size()) { 285 ok=false;286 *message<< "Vector of sorted indices has incorrect size" << std::endl;279 suite.add(false); 280 suite.err() << "Vector of sorted indices has incorrect size" << std::endl; 287 281 } 288 282 if(dummy[0]!=11 || dummy[dummy.size()-1]!=8) { 289 ok=false;290 *message<< "Vector of sorted indices incorrect" << std::endl;283 suite.add(false); 284 suite.err() << "Vector of sorted indices incorrect" << std::endl; 291 285 } 292 286 size_t k=3; … … 294 288 utility::sort_smallest_index(dummy,k,vec3); 295 289 if(dummy.size()!=k) { 296 ok=false;297 *message<< "Vector of sorted smallest indices has incorrect size" << std::endl;290 suite.add(false); 291 suite.err() << "Vector of sorted smallest indices has incorrect size" << std::endl; 298 292 } 299 293 if(dummy[0]!=11 || dummy[dummy.size()-1]!=9) { 300 ok=false;301 *message<< "Vector of sorted smallest indices incorrect" << std::endl;294 suite.add(false); 295 suite.err() << "Vector of sorted smallest indices incorrect" << std::endl; 302 296 } 303 297 … … 305 299 utility::sort_largest_index(dummy,k,vec3); 306 300 if(dummy.size()!=k) { 307 ok=false;308 *message<< "Vector of sorted largest indices has incorrect size" << std::endl;301 suite.add(false); 302 suite.err() << "Vector of sorted largest indices has incorrect size" << std::endl; 309 303 } 310 304 if(dummy[0]!=8 || dummy[dummy.size()-1]!=5) { 311 ok=false;312 *message<< "Vector of sorted largest indices incorrect" << std::endl;305 suite.add(false); 306 suite.err() << "Vector of sorted largest indices incorrect" << std::endl; 313 307 } 314 308 } … … 319 313 vec = vv; 320 314 if (vec.size()!=10){ 321 *message<< "indirect self-assignment failed - size should be 10\n";322 ok = false;315 suite.err() << "indirect self-assignment failed - size should be 10\n"; 316 suite.add(false); 323 317 } 324 318 if (vec(0)!=2.3){ 325 *message<< "indirect self-assignment failed - vec(0) should be 2.3\n";326 ok = false;319 suite.err() << "indirect self-assignment failed - vec(0) should be 2.3\n"; 320 suite.add(false); 327 321 } 328 322 utility::VectorView vv2(vec, 0, 5); 329 323 vec = vv2; 330 324 if (vec.size()!=5){ 331 *message<< "indirect self-assignment failed - size should be 5\n";332 ok = false;325 suite.err() << "indirect self-assignment failed - size should be 5\n"; 326 suite.add(false); 333 327 } 334 328 if (vec(0)!=2.3){ 335 *message<< "indirect self-assignment failed - vec(0) should be 2.3\n";336 ok = false;329 suite.err() << "indirect self-assignment failed - vec(0) should be 2.3\n"; 330 suite.add(false); 337 331 } 338 332 } … … 345 339 } 346 340 347 if (!ok) 348 *message << "vector test failed" << std::endl; 349 350 if (message!=&std::cerr) 351 delete message; 352 353 return (ok ? 0 : -1); 341 return suite.return_value(); 354 342 } -
trunk/test/view_test.cc
r1137 r1248 22 22 */ 23 23 24 #include "Suite.h" 25 24 26 #include "yat/utility/Matrix.h" 25 27 #include "yat/utility/VectorBase.h" … … 32 34 #include <string> 33 35 34 int main( const int argc,constchar* argv[])36 int main(int argc, char* argv[]) 35 37 { 36 38 using namespace theplu::yat::utility; 37 std::ostream* message; 38 if (argc>1 && argv[1]==std::string("-v")) 39 message = &std::cerr; 40 else { 41 message = new std::ofstream("/dev/null"); 42 if (argc>1) 43 std::cout << "vector_test -v : for printing extra " << "information\n"; 44 } 45 *message << "testing vector" << std::endl; 46 bool ok = true; 39 theplu::yat::test::Suite suite(argc, argv); 40 suite.err() << "testing vector" << std::endl; 47 41 48 42 Matrix data1; … … 59 53 VectorView bajs(data2, 0, false); 60 54 if (a(0)!=data1(0,0)){ 61 *message<< "Matrix::column_const_view failed\n";62 ok =false;55 suite.err() << "Matrix::column_const_view failed\n"; 56 suite.add(false); 63 57 } 64 58 if (b(0)!=data2(0,0)){ 65 *message<< "Matrix::column_view failed\n";66 ok =false;59 suite.err() << "Matrix::column_view failed\n"; 60 suite.add(false); 67 61 } 68 62 69 63 data1.column_const_view(0); 70 64 if (b.size()!=3){ 71 ok =false;72 *message<< "ERROR: expected size to be 3 - found " << b.size() << std::endl;65 suite.add(false); 66 suite.err() << "ERROR: expected size to be 3 - found " << b.size() << std::endl; 73 67 } 74 68 if ( !(b(0)==1 && b(1)==(1) && b(2)==1) ) 75 ok = false;69 suite.add(false); 76 70 77 71 if (a.begin()!=data1.begin_column(0)){ 78 ok=false;79 *message<< "VectorConstView::begin should equal "72 suite.add(false); 73 suite.err() << "VectorConstView::begin should equal " 80 74 << "Matrix::begin_column(size_t)\n"; 81 75 } 82 76 if (a.end()!=data1.end_column(0)) { 83 ok=false;84 *message<< "VectorConstView::end should equal "77 suite.add(false); 78 suite.err() << "VectorConstView::end should equal " 85 79 << "Matrix::end_column(size_t)\n"; 86 80 } 87 81 if (b.begin()!=data2.begin_column(0)){ 88 ok=false;89 *message<< "VectorView::begin "82 suite.add(false); 83 suite.err() << "VectorView::begin " 90 84 << b.begin().base() << " should equal\n" 91 85 << "Matrix::begin_column(size_t) " … … 93 87 } 94 88 if (b.end()!=data2.end_column(0)){ 95 ok=false;96 *message<< "VectorView::end should equal "89 suite.add(false); 90 suite.err() << "VectorView::end should equal " 97 91 << "Matrix::end_column(size_t)\n"; 98 92 } … … 100 94 VectorView d=data2.row_view(0); 101 95 if (c.begin()!=data1.begin_row(0)) { 102 ok=false;103 *message<< "VectorConstView::begin should equal "96 suite.add(false); 97 suite.err() << "VectorConstView::begin should equal " 104 98 << "Matrix::begin_row(size_t)\n"; 105 99 } 106 100 if (c.end()!=data1.end_row(0)){ 107 ok=false;108 *message<< "VectorConstView::end should equal "101 suite.add(false); 102 suite.err() << "VectorConstView::end should equal " 109 103 << "Matrix::end_row(size_t)\n"; 110 104 } 111 105 if (d.begin()!=data2.begin_row(0)){ 112 ok=false;113 *message<< "VectorView::begin should equal "106 suite.add(false); 107 suite.err() << "VectorView::begin should equal " 114 108 << "Matrix::begin_row(size_t)\n"; 115 109 } 116 110 if (d.end()!=data2.end_row(0)){ 117 ok=false;118 *message<< "VectorView::end should equal "111 suite.add(false); 112 suite.err() << "VectorView::end should equal " 119 113 << "Matrix::end_row(size_t)\n"; 120 114 } … … 129 123 delete vv; 130 124 if (vcv.size()!=10) 131 ok = false;125 suite.add(false); 132 126 if (vcv(0)!=1.2) 133 ok = false;127 suite.add(false); 134 128 } 135 129 136 130 137 if (ok) 138 *message << "test is ok" << std::endl; 139 else 140 *message << "view test failed" << std::endl; 141 142 if (message!=&std::cerr) 143 delete message; 144 145 return (ok ? 0 : -1); 131 return suite.return_value(); 146 132 } 147 133
Note: See TracChangeset
for help on using the changeset viewer.