Changeset 2273


Ignore:
Timestamp:
Jun 15, 2010, 4:11:47 AM (11 years ago)
Author:
Peter
Message:

adding a test for load function (T=string) and fixed a bug in same function.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/utility_test.cc

    r2248 r2273  
    4848void test_get_map(test::Suite&);
    4949void test_load(test::Suite&);
     50void test_load2(test::Suite&);
    5051void test_inverse(test::Suite&);
    5152
     
    172173  test_ptr_compare(suite);
    173174  test_load(suite);
     175  test_load2(suite);
    174176
    175177  return suite.return_value();
     
    220222void test_less_nan(test::Suite& suite)
    221223{
     224  suite.out() << "test less_nan\n";
    222225  bool prior_ok=suite.ok();
    223226  utility::less_nan<double> f;
     
    265268    suite.add(false);
    266269  }
     270}
     271
     272
     273void test_load2(test::Suite& suite)
     274{
     275  suite.out() << "test load<double>(matrix)\n";
     276  std::string str("1.69 3.14\n1.23 1.22\n");
     277  std::istringstream iss(str);
     278  std::vector<std::vector<double> > double_m;
     279  utility::load(iss, double_m);
     280  suite.add(double_m.size()==2);
     281
     282  suite.out() << "test load<std::string>(matrix)\n";
     283  suite.out() << str;
     284  std::istringstream iss2(str);
     285  std::vector<std::vector<std::string> > str_m;
     286  utility::load(iss2, str_m);
     287  std::cout << str_m.size() << std::endl;
     288  for (size_t i=0; i<str_m.size(); ++i)
     289    for (size_t j=0; j<str_m[i].size(); ++j)
     290      suite.out() << str_m[i][j] << "\n";
     291  suite.add(str_m.size()==2);
    267292}
    268293
  • trunk/yat/utility/utility.h

    r2270 r2273  
    288288      if (line.empty() && ignore_empty)
    289289        continue;
    290       matrix.resize(matrix.size()+1);
    291       std::vector<double>& v=matrix.back();
     290      matrix.push_back(std::vector<T>());
     291      std::vector<T>& v=matrix.back();
    292292      v.reserve(nof_columns);
    293293      std::stringstream ss(line);
    294294      load(ss, v, sep);
    295       // add NaN for final separator
     295      // add NaN for final separator (or empty string if T=std::string)
     296      detail::VectorPusher<T> pusher;
    296297      if(sep!='\0' && !line.empty() && line[line.size()-1]==sep)
    297         v.push_back(std::numeric_limits<T>::quiet_NaN());
     298        pusher("", v);
    298299     
    299300      if (rectangle && nof_columns && v.size()!=nof_columns) {
     
    324325      if(!ok)
    325326        break;
    326      
    327327      pusher(element, vec);
    328328    }
Note: See TracChangeset for help on using the changeset viewer.