小编Jul*_*esW的帖子

Boost 测试用例混合数据集和模板

我使用 boost.test 进行单元测试(目前使用 boost 1.71.0)。我有一个模板类,我想用数据集进行测试。

我只能找到测试不同模板参数(使用BOOST_AUTO_TEST_CASE_TEMPLATE)或数据集(使用BOOST_DATA_TEST_CASE)的方法。但我找不到混合模板和数据集的方法。

这是我所取得的成就的 MWE,并评论了我正在尝试做的事情。

test.cpp

#define BOOST_TEST_MODULE data_template
#include <boost/mpl/list.hpp>
#include <boost/test/data/test_case.hpp>
#include <boost/test/unit_test.hpp>
#include <vector>
#include <list>
#include <numeric> // std::accumulate

template <typename C>
struct Testee{
    C container;
    typename C::value_type f(){
        // just a dummy function to be tested
        return std::accumulate(container.begin(),container.end(),0);
    }
};

typedef boost::mpl::list<std::vector<double>, std::list<double>, std::vector<size_t>> container_types;

template <class T> void test_containers(size_t size)
{
    Testee<T> t;
    t.container = T(size,1);

    BOOST_CHECK_EQUAL(t.f(), size);
}

// test on all container types but …
Run Code Online (Sandbox Code Playgroud)

c++ boost boost-test

5
推荐指数
0
解决办法
314
查看次数

标签 统计

boost ×1

boost-test ×1

c++ ×1