c++ - Passing two arrays as arguments in a gtest -
i need write unit test (gtest) passes 2 values arrays a[]
, b[]
respectively.
example:
a[] = {40, 45, 50 ,55, 60} b[] = {2, 3, 5, 8, 9, 11}
my test case pass these arrays (a[]
,b[]
) arguments function.
is there way can pass both arrays test case ?
expecting arrays static can pass them following example shows:
class arraytests : public unittest_someclass, public testing::withparaminterface<std::pair<int*, int*>> { }; test_p(arraytests, dosomething) { const auto pair = getparam(); const auto = pair.first; const auto b = pair.second; expect_eq(4, a[3]); expect_eq(6, b[4]); } int a[]{ 1,2,3,4 }; int b[]{ 2,3,4,5,6 }; instantiate_test_case_p(unittest_someclass, arraytests, testing::values(std::make_pair(a, b)));
you can pass different arrays test:
int a0[]{ 1,2,3,4 }; int b0[]{ 2,3,4,5,6 }; int a1[]{ 7,8,9,10 }; int b1[]{ 2,3,4,5,6 }; instantiate_test_case_p(unittest_someclass, arraytests, testing::values(std::make_pair(a0, b0), std::make_pair(a1, b1)));
i think easier use std::vector
here int arrays, cause got access number of elements. hth
Comments
Post a Comment