Changeset 1491


Ignore:
Timestamp:
Sep 12, 2008, 12:41:30 AM (13 years ago)
Author:
Peter
Message:

refs #439

Location:
trunk
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/utility_test.cc

    r1487 r1491  
    2626#include "yat/utility/Matrix.h"
    2727#include "yat/utility/utility.h"
     28#include "yat/utility/Vector.h"
     29#include "yat/utility/VectorConstView.h"
     30#include "yat/utility/sort_index.h"
    2831#include "yat/utility/stl_utility.h"
    2932
     
    4548                           const std::multimap<Key, size_t>& m,
    4649                           test::Suite& suite);
     50
     51void test_sort_index(test::Suite& suite);
    4752
    4853int main(int argc, char* argv[])
     
    149154
    150155  test_inverse(suite);
     156  test_sort_index(suite);
    151157
    152158  return suite.return_value();
     
    214220 
    215221}
     222
     223void test_sort_index(test::Suite& suite)
     224{
     225  suite.err() << "testing sort_index" << std::endl;
     226  utility::Vector a(10);
     227  for (size_t i=0; i<a.size(); ++i)
     228    a(i) = std::pow(i-4.2,2);
     229  std::vector<size_t> vec;
     230  utility::sort_index(vec, a);
     231
     232  std::vector<size_t> vec2;
     233  utility::sort_index(a.begin(), a.end(), vec2);
     234  if (vec.size()==vec2.size()) {
     235    if (!suite.equal_range(vec.begin(), vec.end(), vec2.begin())) {
     236      suite.add(false);
     237    }
     238  }
     239  else {
     240    suite.add(false);
     241    suite.err() << "size mismatch: vec.size()=" << vec.size()
     242                << "vec2.size()=" << vec2.size() << "\n";
     243  }
     244  const utility::VectorConstView b(a, 0, 5, 2);
     245
     246  std::vector<size_t> vec3;
     247  utility::sort_index(vec3, b);
     248  std::vector<size_t> vec4;
     249  utility::sort_index(b.begin(), b.end(), vec4);
     250  if (vec3.size()!=vec4.size()) {
     251    suite.add(false);
     252    suite.err() << "size mismatch: vec3.size()=" << vec3.size()
     253                << " vec4.size()=" << vec4.size() << "\n";
     254  }
     255  else {
     256    if (!suite.equal_range(vec3.begin(), vec3.end(), vec4.begin())){
     257      suite.add(false);
     258    }
     259  }
     260}
  • trunk/yat/utility/Makefile.am

    r1487 r1491  
    3030  OptionFile.cc OptionInFile.cc OptionOutFile.cc \
    3131  OptionHelp.cc OptionSwitch.cc \
    32   PCA.cc stl_utility.cc SVD.cc TypeInfo.cc utility.cc Vector.cc \
     32  PCA.cc sort_index.cc stl_utility.cc SVD.cc TypeInfo.cc utility.cc Vector.cc \
    3333  VectorBase.cc VectorConstView.cc VectorMutable.cc VectorView.cc \
    3434  version.cc WeNNI.cc
     
    4444  Option.h OptionArg.h OptionFile.h OptionInFile.h OptionOutFile.h \
    4545  OptionHelp.h OptionSwitch.h \
    46   PCA.h SmartPtr.h Range.h stl_utility.h StrideIterator.h \
     46  PCA.h SmartPtr.h sort_index.h Range.h stl_utility.h StrideIterator.h \
    4747  SVD.h TypeInfo.h utility.h Vector.h \
    4848  VectorBase.h VectorConstView.h VectorMutable.h VectorView.h \
Note: See TracChangeset for help on using the changeset viewer.