gpt4 book ai didi

c++ - 用于检查表打印的 Google 单元测试

转载 作者:行者123 更新时间:2023-11-28 02:04:33 24 4
gpt4 key购买 nike

是否可以使用 google unit test 来测试用 c++ 进行的表格打印?

可以用其他单元测试框架来完成吗?

到目前为止,在A quick introduction to the Google C++ Testing Framework我只看到值(value)观的考验。 This SO 的问题讨论了使用 google mock 来测试数组。

最佳答案

我想您可以使用正则表达式来检查格式。 C++11 有一个专门用于此的函数。下面是一个大纲示例,改编自 cplusplus.com ,但您可以开发更复杂的解决方案来非常准确地测试表格。

c++11

#include <string>
#include <regex>

std::string s = "|some|sort|of|table|row|"
std::regex r = "" // Matching regex
ASSERT_TRUE(std::regex_match(s, r))

此外,您可以拆分(使用 std::string::find()std::string::substr() 概述 here )使用诸如 ASSERT_EQ(parsed_value, exp_value)

之类的东西检查单个值的表

不太客观的评论:
我发现 google test 有几乎所有的工具。您提到的值(value)测试实际上非常通用。 (有点不可避免的)工作是处理可用测试的数据,这意味着推断您关心的数据和特征并将其呈现给 ASSERT_* 和 EXPECT_* 宏。

关于c++ - 用于检查表打印的 Google 单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38126530/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com