我有一个比较两个字符串值的QtTest:
// This definitely returns "5/6"
std::string actual_value = simple(actual);
// Sets a string to the expected value
std::string expected_value = "5/6";然后是QCOMPARE:
QCOMPARE(QString(actual_value.c_str()), QString(expected_value.c_str()));
/* I'm Aware this could just be the code below (but this doesnt print values to
console so i can check they are actually the same) */
QCOMPARE(actual_value, expected_value)然后我得到了错误:(我会发布这两个,所以很明显,这不仅仅是QString的问题,所以下面是使用QString来显示值的QCOMPARE )
FAIL! : TestFraction::testFraction() Compared values are not the same
Actual (QString(actual_value.c_str())): 5/6
Expected (QString(expected_value.c_str())): 5/6这是正常的QCOMPARE错误消息:
FAIL! : TestFraction::testFraction() Compared values are not the same很明显,这背后还有其他代码,但我现在不发了,因为我认为它并不是特别相关,但请询问是否有你想知道的东西,据我所知,这个测试应该通过,但可能有我不知道的关于比较字符串的东西(例如,除非使用模糊比较,否则比较doubles是如何失败的)
提前感谢
发布于 2013-04-03 16:13:37
您的实际字符串有一个新的行字符。因此,比较失败。
https://stackoverflow.com/questions/15768885
复制相似问题