Tôi không thể hiểu tại sao trường hợp thử nghiệm thất bại trong trường hợp tổng hợp số kép hoặc phao. Nó hoạt động rất tốt cho kiểu dữ liệu số nguyên.Lỗi với EXPECT_EQ cho tổng số tiền đôi hoặc phao
// phương pháp trong simple_method.h
double sum (double a, double b)
{
double res = a+b;
return res;
}
// các trường hợp thử nghiệm cho phương pháp này
TEST(simpleSum, sumOfFloat)
{
EXPECT_EQ(4.56, sum(0.56, 4.0));
}
// đầu ra là
Running main() from gtest_main.cc
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from simpleSum
[ RUN ] simpleSum.sumOfFloat
/home/pcadmin/Desktop/so/so3/simple_method_test.cpp:7: Failure
Value of: sum(0.56, 4.0)
Actual: 4.56
Expected: 4.56
[ FAILED ] simpleSum.sumOfFloat (0 ms)
[----------] 1 test from simpleSum (0 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (0 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] simpleSum.sumOfFloat
1 FAILED TEST
Cảm ơn bạn .. nó hoạt động tốt với cả hai macro. – suma