#include #include #include #include #include #include #include using VectorX = Eigen::VectorXd; using MapVectorX = Eigen::Map; struct ETS { int n; double *qlim_l; double *qlim_h; double *q_range2; }; // __RAND_Q_FUNCTION__ static bool reject_case(ETS *ets, MapVectorX q, int expected_joint) { std::srand(701); const int expected_next = std::rand(); std::srand(701); try { _rand_q(ets, q); } catch (const std::invalid_argument &error) { const std::string message(error.what()); const int observed_next = std::rand(); return observed_next == expected_next && message.find("joint") != std::string::npos && message.find(std::to_string(expected_joint)) != std::string::npos && message.find("finite") != std::string::npos; } return false; } int main() { ETS ets{}; ets.n = 4; double lower[4] = {-2.0, 0.5, -3.0, 6.0}; double upper[4] = {1.0, 0.5, 5.0, 9.0}; double half_range[4] = {1.5, 0.0, 4.0, 1.5}; double output[4] = {}; ets.qlim_l = lower; ets.qlim_h = upper; ets.q_range2 = half_range; MapVectorX q(output, 4); std::srand(313); _rand_q(&ets, q); if (!q.allFinite()) return 10; for (int joint = 0; joint < ets.n; ++joint) if (q(joint) < lower[joint] || q(joint) > upper[joint]) return 11; if (q(1) != 0.5) return 12; lower[2] = std::numeric_limits::infinity(); if (!reject_case(&ets, q, 2)) return 20; lower[2] = -3.0; upper[3] = -std::numeric_limits::infinity(); if (!reject_case(&ets, q, 3)) return 21; upper[3] = 9.0; upper[1] = std::numeric_limits::quiet_NaN(); if (!reject_case(&ets, q, 1)) return 22; std::cout << "native-guard-ok\n"; return 0; }