Skip to content

Commit c98fa84

Browse files
committed
added test for check_vector_index
1 parent 59335f6 commit c98fa84

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#include <stan/math/prim.hpp>
2+
#include <gtest/gtest.h>
3+
#include <limits>
4+
5+
TEST(ErrorHandlingMatrix, checkVectorIndexColumnVector) {
6+
Eigen::Matrix<double, Eigen::Dynamic, 1> y;
7+
size_t i;
8+
double nan = std::numeric_limits<double>::quiet_NaN();
9+
10+
i = 2;
11+
y.resize(3);
12+
y << nan, nan, nan;
13+
EXPECT_NO_THROW(
14+
stan::math::check_vector_index("checkVectorIndexMatrix", "i", y, i));
15+
i = 3;
16+
EXPECT_NO_THROW(
17+
stan::math::check_vector_index("checkVectorIndexMatrix", "i", y, i));
18+
19+
y.resize(2);
20+
y << nan, nan;
21+
EXPECT_THROW(
22+
stan::math::check_vector_index("checkVectorIndexMatrix", "i", y, i),
23+
std::out_of_range);
24+
25+
i = 0;
26+
EXPECT_THROW(
27+
stan::math::check_vector_index("checkVectorIndexMatrix", "i", y, i),
28+
std::out_of_range);
29+
}
30+
31+
TEST(ErrorHandlingMatrix, checkVectorIndexRowVector) {
32+
Eigen::Matrix<double, 1, Eigen::Dynamic> y;
33+
size_t i;
34+
double nan = std::numeric_limits<double>::quiet_NaN();
35+
36+
i = 2;
37+
y.resize(3);
38+
y << nan, nan, nan;
39+
EXPECT_NO_THROW(
40+
stan::math::check_vector_index("checkVectorIndexMatrix", "i", y, i));
41+
i = 3;
42+
EXPECT_NO_THROW(
43+
stan::math::check_vector_index("checkVectorIndexMatrix", "i", y, i));
44+
45+
y.resize(2);
46+
y << nan, nan;
47+
EXPECT_THROW(
48+
stan::math::check_vector_index("checkVectorIndexMatrix", "i", y, i),
49+
std::out_of_range);
50+
51+
i = 0;
52+
EXPECT_THROW(
53+
stan::math::check_vector_index("checkVectorIndexMatrix", "i", y, i),
54+
std::out_of_range);
55+
}

0 commit comments

Comments
 (0)