// Boost.Units library // Copyright 2012 Paul A. Bristow Adding comments and examples of new types. // // Distributed under 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) #ifdef _MSC_VER # pragma warning(disable :4512) // 'boost::tuples::tuple_manipulator' : assignment operator could not be generated #endif #define BOOST_TEST_MAIN #include #include #include #include #include #include #include #include // An uncertain type called measure. #include #include BOOST_AUTO_TEST_CASE(test_output_width) { using namespace boost::units; using namespace boost::units::si; //quantity ql = 2345.6 * meters; //std::cout << std::setw(20) << ql << std::endl; std::size_t w = 25; quantity > qm = measurement(45210.0, 1234.0) * meters; // Value is big enough to switch to km if engineering_prefix is chosen. std::ostringstream oss; // Default right justify. oss.fill('*'); // So can see the fill chars clearly. std::cout.fill('*'); std::cout << boost::units::no_prefix << std::setw(w) << qm << std::endl; oss << std::setw(w) << boost::units::no_prefix << qm << std::flush; BOOST_CHECK_EQUAL(oss.str().size(), w); BOOST_CHECK_EQUAL(oss.str(), "*********45210(+/-1234) m"); //std::cout << oss.str() <<"|" << oss.str().size() << std::endl; oss.str(""); std::cout << boost::units::engineering_prefix << std::setw(w) << qm << std::endl; oss << std::setw(w) << boost::units::engineering_prefix << qm << std::flush; BOOST_CHECK_EQUAL(oss.str().size(), w); BOOST_CHECK_EQUAL(oss.str(),"*******45.21(+/-1.234) km"); oss.str(""); std::cout << boost::units::binary_prefix << std::setw(w) << qm << std::endl; oss << std::setw(w) << boost::units::binary_prefix << qm << std::flush; BOOST_CHECK_EQUAL(oss.str().size(), w); BOOST_CHECK_EQUAL(oss.str(),"**44.1504(+/-1.20508) Kim"); oss.str(""); // Left justify. std::cout << std::left << boost::units::no_prefix << std::setw(w) << qm << std::endl; oss << std::left << boost::units::no_prefix<< std::setw(w) << qm << std::flush; BOOST_CHECK_EQUAL(oss.str().size(), w); BOOST_CHECK_EQUAL(oss.str(), "45210(+/-1234) m*********"); oss.str(""); std::cout << std::left << boost::units::engineering_prefix << std::setw(w) << qm << std::endl; oss << std::left << std::setw(w) << boost::units::engineering_prefix << qm << std::flush; BOOST_CHECK_EQUAL(oss.str().size(), w); BOOST_CHECK_EQUAL(oss.str(),"45.21(+/-1.234) km*******"); oss.str(""); std::cout << std::left << boost::units::binary_prefix << std::setw(w) << qm << std::endl; oss << std::left << std::setw(w) << boost::units::binary_prefix << qm << std::flush; BOOST_CHECK_EQUAL(oss.str().size(), w); BOOST_CHECK_EQUAL(oss.str(),"44.1504(+/-1.20508) Kim**"); oss.str(""); } //