我正在为我的可可类编写单元测试用例。下面是测试用例。我无法弄清楚为什么这个测试用例会失败,即使断言消息中的expect
anddiff
是相同的。我怀疑这可能与 double 或 NSTimeInterval 的计算方式有关
NSTimeInterval day = 60*60*24;
NSDate * current = [NSDate date];
NSDate * daysAgo = [NSDate dateWithTimeInterval:-6*day sinceDate:current];
NSTimeInterval diff = [current timeIntervalSinceDate:daysAgo];
NSTimeInterval expect = 6 * day;
STAssertEquals(expect, diff, @"Failed expecting: %ld, getting %ld", expect, diff);