io.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // This file is part of Eigen, a lightweight C++ template library
  2. // for linear algebra.
  3. //
  4. // Copyright (C) 2019 Joel Holdsworth <joel.holdsworth@vcatechnology.com>
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla
  7. // Public License v. 2.0. If a copy of the MPL was not distributed
  8. // with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
  9. #include <sstream>
  10. #include "main.h"
  11. template<typename Scalar>
  12. struct check_ostream_impl
  13. {
  14. static void run()
  15. {
  16. const Array<Scalar,1,1> array(123);
  17. std::ostringstream ss;
  18. ss << array;
  19. VERIFY(ss.str() == "123");
  20. check_ostream_impl< std::complex<Scalar> >::run();
  21. };
  22. };
  23. template<>
  24. struct check_ostream_impl<bool>
  25. {
  26. static void run()
  27. {
  28. const Array<bool,1,2> array(1, 0);
  29. std::ostringstream ss;
  30. ss << array;
  31. VERIFY(ss.str() == "1 0");
  32. };
  33. };
  34. template<typename Scalar>
  35. struct check_ostream_impl< std::complex<Scalar> >
  36. {
  37. static void run()
  38. {
  39. const Array<std::complex<Scalar>,1,1> array(std::complex<Scalar>(12, 34));
  40. std::ostringstream ss;
  41. ss << array;
  42. VERIFY(ss.str() == "(12,34)");
  43. };
  44. };
  45. template<typename Scalar>
  46. static void check_ostream()
  47. {
  48. check_ostream_impl<Scalar>::run();
  49. }
  50. EIGEN_DECLARE_TEST(rand)
  51. {
  52. CALL_SUBTEST(check_ostream<bool>());
  53. CALL_SUBTEST(check_ostream<float>());
  54. CALL_SUBTEST(check_ostream<double>());
  55. CALL_SUBTEST(check_ostream<Eigen::numext::int8_t>());
  56. CALL_SUBTEST(check_ostream<Eigen::numext::uint8_t>());
  57. CALL_SUBTEST(check_ostream<Eigen::numext::int16_t>());
  58. CALL_SUBTEST(check_ostream<Eigen::numext::uint16_t>());
  59. CALL_SUBTEST(check_ostream<Eigen::numext::int32_t>());
  60. CALL_SUBTEST(check_ostream<Eigen::numext::uint32_t>());
  61. CALL_SUBTEST(check_ostream<Eigen::numext::int64_t>());
  62. CALL_SUBTEST(check_ostream<Eigen::numext::uint64_t>());
  63. }