簡體   English   中英

升級中的單元測試

[英]unit test in boost

我的單元測試有以下代碼:

BOOST_AUTO_TEST_CASE (test_adapter) {
  boost::random::mt19937 gen;
  boost::normal_distribution<> nd1(10.0,31.0);
  unsigned int imax = 1000;
  std::vector<double> x, x_p;
  for (unsigned int k = 0 ; k < 1000 ; k++) {
    std::vector<double>().swap(x);
    std::vector<double>().swap(x_p);
    for (unsigned int i = 0 ; i < imax ; i++) {
      x.push_back(nd1(gen));
      x_p.push_back(nd1(gen));
        }
   }
        log_rtns <double >lr;
        BOOST_CHECK(lr( x, x_p) == false );

}

這是我的log_rtns:

template<class T>
class log_rtns: public std::binary_function<T,T,bool> {
 public:
  inline bool operator()(T t, T t_p) {return (std::log(t/t_p));}
};

您正在創建log_rtns變量(此處為log_rtns lr; )而未指定模板參數T 所以你必須寫log_rtns<something> lr;

我猜你想要log_rtns<double> ,但不使用lr變量。

你也不能在兩個數組上調用BOOST_CHECK_CLOSE() 你必須做類似的事情

BOOST_CHECK_EQUAL(x.size(), x_p.size());
for (size_t i = 0; i < x.size(); ++i) {
    BOOST_CHECK_CLOSE(x[i], x_p[i], 0.00000000000);
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM