regression_matlib_dynamic.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // Copyright (c) 2001-2011 Hartmut Kaiser
  2. // Copyright (c) 2009 Carl Barron
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #include <boost/detail/lightweight_test.hpp>
  7. #include <boost/spirit/include/lex_lexertl.hpp>
  8. #include <iostream>
  9. #include <algorithm>
  10. #include "matlib.h"
  11. void test_matrix(std::vector<std::vector<double> > const& x)
  12. {
  13. BOOST_TEST(x.size() == 3);
  14. BOOST_TEST(x[0].size() == 2 && x[0][0] == 1 && x[0][1] == 2);
  15. BOOST_TEST(x[1].size() == 1 && x[1][0] == 3);
  16. BOOST_TEST(x[2].size() == 3 && x[2][0] == 4 && x[2][1] == 5 && x[2][2] == 6);
  17. }
  18. int main ()
  19. {
  20. std::string input("[[1,2][3][4,5,6]]");
  21. std::vector<std::vector<double> > results;
  22. typedef std::string::iterator iter;
  23. typedef boost::spirit::lex::lexertl::actor_lexer<
  24. boost::spirit::lex::lexertl::token<iter>
  25. > lexer_type;
  26. typedef matlib_tokens<lexer_type> matlib_type;
  27. matlib_type matrix(results);
  28. iter first = input.begin();
  29. try {
  30. BOOST_TEST(boost::spirit::lex::tokenize(first, input.end(), matrix));
  31. test_matrix(results);
  32. }
  33. catch (std::runtime_error const& e) {
  34. std::cerr << "caught exception: " << e.what() << std::endl;
  35. BOOST_TEST(false);
  36. }
  37. return boost::report_errors();
  38. }