check_adaptation.hpp
Go to the documentation of this file.
1 #ifndef TEST__UNIT__CHECK_ADAPTATION_HPP
2 #define TEST__UNIT__CHECK_ADAPTATION_HPP
3 
5 #include <gtest/gtest.h>
6 #include <stdlib.h>
7 #include <stdio.h>
8 #include <string>
9 #include <vector>
10 #include <boost/algorithm/string.hpp>
11 
12 namespace stan {
13  namespace test {
14  namespace unit {
15 
16  double stod(const std::string& val) {
17  char tmp[val.length()];
18  strcpy(tmp,val.c_str());
19  return atof(tmp);
20  }
21 
22  void check_adaptation(const size_t& num_params,
23  const std::vector<double>& param_vals,
25  const double& err_margin) {
26  std::vector<std::string> param_strings = report.string_values();
27  size_t offset = 0;
28  for (size_t i = 0; i < param_strings.size(); i++) {
29  offset++;
30  if (param_strings[i].find("lements of inverse mass matrix:")
31  != std::string::npos) {
32  break;
33  }
34  }
35  std::vector<std::string> strs;
36  boost::split(strs, param_strings[offset], boost::is_any_of(", "),
37  boost::token_compress_on);
38  EXPECT_EQ(num_params, strs.size());
39  for (size_t i = 0; i < num_params; i++) {
40  ASSERT_NEAR(param_vals[i], test::unit::stod(strs[i]), err_margin);
41  }
42  }
43 
44  void check_adaptation(const size_t& num_rows, const size_t& num_cols,
45  const std::vector<double>& param_vals,
47  const double& err_margin) {
48  std::vector<std::string> param_strings = report.string_values();
49  size_t offset = 0;
50  for (size_t i = 0; i < param_strings.size(); i++) {
51  offset++;
52  if (param_strings[i].find("lements of inverse mass matrix:")
53  != std::string::npos) {
54  break;
55  }
56  }
57  for (size_t i = 0, ij = 0; i < num_rows; i++) {
58  std::vector<std::string> strs;
59  boost::split(strs, param_strings[offset+i], boost::is_any_of(", "),
60  boost::token_compress_on);
61  EXPECT_EQ(num_cols, strs.size());
62  for (size_t j = 0; j < num_cols; j++, ij++) {
63  ASSERT_NEAR(param_vals[ij], test::unit::stod(strs[j]), err_margin);
64  }
65  }
66  }
67 
68  void check_different(const size_t& num_params,
69  const std::vector<double>& param_vals,
71  const double& margin) {
72  std::vector<std::string> param_strings = report.string_values();
73  size_t offset = 0;
74  for (size_t i = 0; i < param_strings.size(); i++) {
75  offset++;
76  if (param_strings[i].find("lements of inverse mass matrix:")
77  != std::string::npos) {
78  break;
79  }
80  }
81  std::vector<std::string> strs;
82  boost::split(strs, param_strings[offset], boost::is_any_of(", "),
83  boost::token_compress_on);
84  EXPECT_EQ(num_params, strs.size());
85  for (size_t i = 0; i < num_params; i++) {
86  ASSERT_GT(fabs(param_vals[i]-test::unit::stod(strs[i])), margin);
87  }
88  }
89 
90  void check_different(const size_t& num_rows, const size_t& num_cols,
91  const std::vector<double>& param_vals,
93  const double& margin) {
94  std::vector<std::string> param_strings = report.string_values();
95  size_t offset = 0;
96  for (size_t i = 0; i < param_strings.size(); i++) {
97  offset++;
98  if (param_strings[i].find("lements of inverse mass matrix:")
99  != std::string::npos) {
100  break;
101  }
102  }
103  for (size_t i = 0, ij = 0; i < num_rows; i++) {
104  std::vector<std::string> strs;
105  boost::split(strs, param_strings[offset+i], boost::is_any_of(", "),
106  boost::token_compress_on);
107  EXPECT_EQ(num_cols, strs.size());
108  for (size_t j = 0; j < num_cols; j++, ij++) {
109  ASSERT_GT(fabs(param_vals[ij]-test::unit::stod(strs[j])), margin);
110  }
111  }
112  }
113 
114  }
115  }
116 }
117 
118 #endif
void split(double tt, double *fr)
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
double stod(const std::string &val)
Float_t tmp
Definition: plot.C:36
const double j
Definition: BetheBloch.cxx:29
void check_different(const size_t &num_params, const std::vector< double > &param_vals, stan::test::unit::instrumented_writer &report, const double &margin)
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
void check_adaptation(const size_t &num_params, const std::vector< double > &param_vals, stan::test::unit::instrumented_writer &report, const double &err_margin)