/* * $Rev: 5247 $ * Author: Jesse Perla (c) 2010 * Use, modification and distribution are subject to the * Boost Software License, Version 1.0. (See accompanying file * LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) */ #define BOOST_TEST_MODULE test_tie #include #include #include //For the ublas::tie #include #include #include #include //For << BOOST_AUTO_TEST_CASE( test_vector_tie) { double x; double y; ublas::vector v(2); v(0) = 1.1; v(1) = 2.1; ublas::tie(x, y) = v; BOOST_REQUIRE_CLOSE(x, v(0), .1); BOOST_REQUIRE_CLOSE(y, v(1), .1); } BOOST_AUTO_TEST_CASE( test_vector_tie_different_types) { double x; int y; ublas::vector v(2); v(0) = 1; v(1) = 2; ublas::tie(x, y) = v; BOOST_REQUIRE_CLOSE(x, (double)v(0), .1); BOOST_REQUIRE_EQUAL(y, v(1)); } ublas::vector f() { ublas::vector v(2); v(0) = 1.1; v(1) = 2.1; return v; } BOOST_AUTO_TEST_CASE( test_vector_tie_func) { double x; double y; ublas::tie(x, y) = f(); BOOST_REQUIRE_CLOSE(x, f()[0], .1); BOOST_REQUIRE_CLOSE(y, f()[1], .1); } BOOST_AUTO_TEST_CASE( test_vector_tie_matrix) { double x; double y; ublas::matrix mat(2,2); mat(0,0) = 1; mat(0,1) = 2; mat(1,0) = 3; mat(1,1) = 4; ublas::tie(x, y) = row(mat, 0); BOOST_REQUIRE_CLOSE(x, mat(0,0), .1); BOOST_REQUIRE_CLOSE(y, mat(0,1), .1); }