Look s like you have confused two different things.
(看起来您已经混淆了两种不同的事物。)
Quoted example refers to situation where actual tests has been written using some library like: CTest, Google Test, Boost.Test. (引用的示例是指使用某些库(例如CTest,Google Test,Boost.Test)编写实际测试的情况。)
Using this tools you have to write separate code which tests production code (you can read about TDD - Test driven development). (使用此工具,您必须编写测试生产代码的单独代码(您可以阅读有关TDD-测试驱动的开发)。)
You have included a list of text files which are feed to standard input using for test cases on sites like: SPOJ, Hackerrank and so on.
(您已经包括了文本文件列表,这些文件可作为标准输入的提要,用于诸如SPOJ,Hackerrank等站点上的测试用例。)
On this sites different programing languages can be used. (在此站点上可以使用不同的编程语言。)
To verify correctness of provided solution standard input and output is used. (为了验证所提供解决方案的正确性,使用了标准输入和输出。)
This is a quick simple way to verify correctness of programs created in almost any language, but this solution is not very usable in real life software development. (这是一种验证几乎所有语言创建的程序正确性的快速简便方法,但是该解决方案在现实生活中的软件开发中不是很有用。)
AFAIK there is no tool which can help you to do it quickly.
(AFAIK没有工具可以帮助您快速完成。)
By refactoring your code you can take advantage of one of the tools and at the same time use those files.
(通过重构代码,您可以利用其中一种工具,同时使用这些文件。)
int problemSolver(std::istream& in, std::ostream& out)
{
}
#ifndef TESTING_MODE
int main()
{
return problemSolver(std::cin, std::cout);
}
#else
TEST(ProblemSolverTest, input1)
{
std::istringstream in{ load_file("Test_input_1.txt") };
std::ostringstream out;
ASSERT_EQ(problemSolver(in, out), 0);
auto result = out.str();
ASSERT_EQ(result, load_file("Test_output_1.txt"));
}
...
#endif // TESTING_MODE
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…