|
| 1 | +#include <stan/math/prim.hpp> |
| 2 | +#include <gtest/gtest.h> |
| 3 | + |
| 4 | +TEST(MathPrim, basic_print) { |
| 5 | + int i = 1; |
| 6 | + double d = 1.0; |
| 7 | + Eigen::VectorXd v = Eigen::VectorXd::Ones(1); |
| 8 | + Eigen::RowVectorXd rv = Eigen::RowVectorXd::Ones(1); |
| 9 | + Eigen::MatrixXd m = Eigen::MatrixXd::Ones(1, 1); |
| 10 | + std::vector<double> a(1, 1); |
| 11 | + |
| 12 | + { |
| 13 | + std::stringstream s; |
| 14 | + stan::math::stan_print(&s, i); |
| 15 | + EXPECT_TRUE(s.str().find("1") != std::string::npos); |
| 16 | + } |
| 17 | + |
| 18 | + { |
| 19 | + std::stringstream s; |
| 20 | + stan::math::stan_print(&s, d); |
| 21 | + EXPECT_TRUE(s.str().find("1") != std::string::npos); |
| 22 | + } |
| 23 | + |
| 24 | + { |
| 25 | + std::stringstream s; |
| 26 | + stan::math::stan_print(&s, v); |
| 27 | + EXPECT_TRUE(s.str().find("[1]") != std::string::npos); |
| 28 | + } |
| 29 | + |
| 30 | + { |
| 31 | + std::stringstream s; |
| 32 | + stan::math::stan_print(&s, rv); |
| 33 | + EXPECT_TRUE(s.str().find("[1]") != std::string::npos); |
| 34 | + } |
| 35 | + |
| 36 | + { |
| 37 | + std::stringstream s; |
| 38 | + stan::math::stan_print(&s, m); |
| 39 | + EXPECT_TRUE(s.str().find("[[1]]") != std::string::npos); |
| 40 | + } |
| 41 | + |
| 42 | + { |
| 43 | + std::stringstream s; |
| 44 | + stan::math::stan_print(&s, a); |
| 45 | + EXPECT_TRUE(s.str().find("[1]") != std::string::npos); |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +TEST(MathPrim, basic_expressions) { |
| 50 | + Eigen::VectorXd v = Eigen::VectorXd::Ones(2); |
| 51 | + Eigen::RowVectorXd rv = Eigen::RowVectorXd::Ones(2); |
| 52 | + Eigen::MatrixXd m = Eigen::MatrixXd::Ones(2, 2); |
| 53 | + |
| 54 | + { |
| 55 | + std::stringstream s; |
| 56 | + stan::math::stan_print(&s, v * v.transpose()); |
| 57 | + EXPECT_TRUE(s.str().find("[[1,1],[1,1]]") != std::string::npos); |
| 58 | + } |
| 59 | + |
| 60 | + { |
| 61 | + std::stringstream s; |
| 62 | + stan::math::stan_print(&s, rv * m); |
| 63 | + EXPECT_TRUE(s.str().find("[2,2]") != std::string::npos); |
| 64 | + } |
| 65 | + |
| 66 | + { |
| 67 | + std::stringstream s; |
| 68 | + stan::math::stan_print(&s, m * m); |
| 69 | + EXPECT_TRUE(s.str().find("[[2,2],[2,2]]") != std::string::npos); |
| 70 | + } |
| 71 | +} |
0 commit comments