Changeset 879 for trunk/test


Ignore:
Timestamp:
Sep 21, 2007, 4:10:07 PM (16 years ago)
Author:
Markus Ringnér
Message:

Added support to utility::vector for gsl-functions that finds indices to the k largest/smallest elements in a vector

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/vector_test.cc

    r877 r879  
    242242  } catch (utility::IO_error& err) {
    243243    *message << err.what() << std::endl;
    244     this_ok=true; // good, exceoption thrown, test passed
     244    this_ok=true; // good, exception thrown, test passed
    245245  }
    246246  try {
     
    267267  ok &= this_ok;
    268268
    269   std::string data3("data/vector3.data");
    270   std::ifstream data_stream3(data3.c_str());
    271   utility::vector vec3(data_stream3);
    272   std::vector<size_t> dummy;
    273   utility::sort_index(dummy,vec3);
    274   for(size_t i=0;i<dummy.size();i++) {
    275     *message << "dummy: " << dummy[i] << std::endl;
     269
     270  // Test sort algorithms
     271  {
     272    std::string data3("data/vector3.data");
     273    std::ifstream data_stream3(data3.c_str());
     274    utility::vector vec3(data_stream3);
     275    std::vector<size_t> dummy;
     276    dummy.push_back(100); // To make sure it works starting with a non-empty vector
     277
     278    utility::sort_index(dummy,vec3);
     279    if(dummy.size()!=vec3.size()) {
     280      ok=false;
     281      *message << "Vector of sorted indices has incorrect size" << std::endl;
     282    }
     283    if(dummy[0]!=11 || dummy[dummy.size()-1]!=8) {
     284      ok=false;
     285      *message << "Vector of sorted indices incorrect" << std::endl;
     286    }
     287    size_t k=3;
     288
     289    utility::sort_smallest_index(dummy,k,vec3);
     290    if(dummy.size()!=k) {
     291      ok=false;
     292      *message << "Vector of sorted smallest indices has incorrect size" << std::endl;
     293    }
     294    if(dummy[0]!=11 || dummy[dummy.size()-1]!=9) {
     295      ok=false;
     296      *message << "Vector of sorted smallest indices incorrect" << std::endl;
     297    }
     298
     299    k=4;
     300    utility::sort_largest_index(dummy,k,vec3);
     301    if(dummy.size()!=k) {
     302      ok=false;
     303      *message << "Vector of sorted largest indices has incorrect size" << std::endl;
     304    }
     305    if(dummy[0]!=8 || dummy[dummy.size()-1]!=5) {
     306      ok=false;
     307      *message << "Vector of sorted largest indices incorrect" << std::endl;
     308    }
    276309  }
    277310
Note: See TracChangeset for help on using the changeset viewer.