Changeset 900 for trunk/test/vector_distance_test.cc
 Timestamp:
 Sep 27, 2007, 9:10:33 AM (16 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

trunk/test/vector_distance_test.cc
r898 r900 12 12 #include <fstream> 13 13 #include <iostream> 14 #include <list> 15 #include <string> 16 #include <vector> 14 17 15 18 … … 46 49 *error << "testing vector_distance" << std::endl; 47 50 bool ok = true; 48 51 49 52 utility::vector a(3,1); 50 53 a(1) = 2; 51 54 utility::vector b(3,0); 52 55 b(2) = 1; 53 56 54 57 double tolerance=1e4; 55 58 56 59 double dist=statistics::vector_distance(a.begin(),a.end(),b.begin(), 57 60 statistics::euclidean_vector_distance_tag()); 58 61 if(fabs(dist2.23607)>tolerance) { 59 *error << "Error in unweighted Euclidean vector_distance :" << std::endl;62 *error << "Error in unweighted Euclidean vector_distance " << std::endl; 60 63 ok=false; 61 64 } 62 65 63 66 dist=statistics::vector_distance(a.begin(),a.end(),b.begin(), 64 67 statistics::pearson_vector_distance_tag()); 65 68 if(fabs(dist1.5)>tolerance) { 66 *error << "Error in unweighted Pearson vector_distance :" << std::endl;69 *error << "Error in unweighted Pearson vector_distance " << std::endl; 67 70 ok=false; 68 71 } 69 72 70 73 71 74 // Testing weighted versions … … 84 87 85 88 if(fabs(dist2)>tolerance) { 86 *error << "Error in weighted Euclidean vector_distance :" << std::endl;89 *error << "Error in weighted Euclidean vector_distance " << std::endl; 87 90 ok=false; 88 91 } 89 92 90 93 dist=statistics::vector_distance(aw.begin(),aw.end(),bw.begin(), 91 94 statistics::pearson_vector_distance_tag()); 92 95 93 96 if(fabs(dist2)>tolerance) { 94 *error << "Error in weighted Pearson vector_distance :" << std::endl;97 *error << "Error in weighted Pearson vector_distance " << std::endl; 95 98 ok=false; 96 99 } 97 98 99 // Test with std::vectors 100 std::vector<double> sa(3,1); 101 sa[1] = 2; 102 std::vector<double> sb(3,0); 103 sb[2] = 1; 104 105 dist=statistics::vector_distance(sa.begin(),sa.end(),sb.begin(), 106 statistics::euclidean_vector_distance_tag()); if(fabs(dist2.23607)>tolerance) { 107 *error << "Error in vector_distance for std::vector: " << std::endl; 108 ok=false; 109 } 110 111 100 101 112 102 // Test with pointer to a vector_distance 113 103 statistics::vector_distance_lookup_weighted_ptr test_ptr= … … 118 108 ok=false; 119 109 } 120 110 111 // Test with std::vectors 112 std::vector<double> sa(3,1); 113 sa[1] = 2; 114 std::vector<double> sb(3,0); 115 sb[2] = 1; 116 117 dist=statistics::vector_distance(sa.begin(),sa.end(),sb.begin(), 118 statistics::euclidean_vector_distance_tag()); 119 if(fabs(dist2.23607)>tolerance) { 120 *error << "Error in vector_distance for std::vector " << std::endl; 121 ok=false; 122 } 123 124 // Test for a std::list and a std::vector 125 std::list<double> la; 126 std::copy(sa.begin(),sa.end(),std::back_inserter<std::list<double> >(la)); 127 dist=statistics::vector_distance(la.begin(),la.end(),sb.begin(), 128 statistics::euclidean_vector_distance_tag()); 129 if(fabs(dist2.23607)>tolerance) { 130 *error << "Error in vector_distance for std::list " << std::endl; 131 ok=false; 132 } 133 121 134 if(!ok) { 122 135 *error << "vector_distance_test failed" << std::endl;
Note: See TracChangeset
for help on using the changeset viewer.