Ignore:
Timestamp:
Sep 27, 2007, 9:10:33 AM (16 years ago)
Author:
Markus Ringnér
Message:

Refs #251. Fixed so the unweighted distances are at the forward-iterator level. To test this I added a distance calculation between a list and a vector in vector_distance_test (also fixed its indentation)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/vector_distance_test.cc

    r898 r900  
    1212#include <fstream>
    1313#include <iostream>
     14#include <list>
     15#include <string>
     16#include <vector>
    1417
    1518
     
    4649  *error << "testing vector_distance" << std::endl;
    4750  bool ok = true;
    48 
     51 
    4952  utility::vector a(3,1);
    5053  a(1) = 2;
    5154  utility::vector b(3,0);
    5255  b(2) = 1;
    53 
     56 
    5457  double tolerance=1e-4;
    55 
     58 
    5659  double dist=statistics::vector_distance(a.begin(),a.end(),b.begin(),
    5760                                          statistics::euclidean_vector_distance_tag());
    5861  if(fabs(dist-2.23607)>tolerance) {
    59     *error << "Error in unweighted Euclidean vector_distance: " << std::endl;
     62    *error << "Error in unweighted Euclidean vector_distance " << std::endl;
    6063    ok=false;
    6164  }
    62 
     65 
    6366  dist=statistics::vector_distance(a.begin(),a.end(),b.begin(),
    64                                           statistics::pearson_vector_distance_tag());
     67                                   statistics::pearson_vector_distance_tag()); 
    6568  if(fabs(dist-1.5)>tolerance) {
    66     *error << "Error in unweighted Pearson vector_distance: " << std::endl;
     69    *error << "Error in unweighted Pearson vector_distance " << std::endl;
    6770    ok=false;
    6871  }
    69 
     72 
    7073 
    7174  // Testing weighted versions
     
    8487 
    8588  if(fabs(dist-2)>tolerance) {
    86     *error << "Error in weighted Euclidean vector_distance: " << std::endl;
     89    *error << "Error in weighted Euclidean vector_distance " << std::endl;
    8790    ok=false;
    8891  }
    89 
     92 
    9093  dist=statistics::vector_distance(aw.begin(),aw.end(),bw.begin(),
    91                                           statistics::pearson_vector_distance_tag());
     94                                   statistics::pearson_vector_distance_tag());
    9295 
    9396  if(fabs(dist-2)>tolerance) {
    94     *error << "Error in weighted Pearson vector_distance: " << std::endl;
     97    *error << "Error in weighted Pearson vector_distance " << std::endl;
    9598    ok=false;
    9699  }
    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(dist-2.23607)>tolerance) {
    107     *error << "Error in vector_distance for std::vector: " << std::endl;
    108     ok=false;
    109   }
    110 
    111 
     100 
     101 
    112102  // Test with pointer to a vector_distance
    113103  statistics::vector_distance_lookup_weighted_ptr test_ptr=
     
    118108    ok=false;
    119109  }
    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(dist-2.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(dist-2.23607)>tolerance) {
     130    *error << "Error in vector_distance for std::list " << std::endl;
     131    ok=false;
     132  }
     133 
    121134  if(!ok) {
    122135    *error << "vector_distance_test failed" << std::endl;
Note: See TracChangeset for help on using the changeset viewer.