我遇到了我的测试问题。它看起来很简单。你所要做的只是删除一个空间,但由于某种原因我总是收到一个错误。测试错误
@Override
public String format(String template) {
if(template.equals("%t")){
return String.format("%02 seconds", getSeconds());
}
else if(template.equals("%h:%M:%S")) {
return String.format("%02d:%02d:%02d", getHours(), getMinutes(), getSeconds());
}
else if(template.equals("%d days, %h hours, %m minutes, and %s seconds")){
return String.format("%d days,%2d hours,%2d minutes, and %2d seconds", getDays(), getHours(),
getMinutes(), getSeconds());
}
else return null;
}
@Test
public void testFormatExample1() {
assertEquals("3 days, 4 hours, 0 minutes, and 9 seconds",
fromDHMS(3, 4, 0, 9)
.format("%d days, %h hours, %m minutes, and %s seconds"));
}
这是我应该得到
3 days, 4 hours, 0 minutes, and 9 seconds
然而,这就是我不断收到
Expected :3 days, 4 hours, 0 minutes, and 9 seconds
Actual :3 days, 4 hours, 0 minutes, and 9 seconds
我用尽了一切在and 9 seconds
如果我去我的if语句的最后一种情况,我删除了之间的空格和%2d seconds
,它仍然不起作用。我为它之前的空间做了它,它工作。
有谁知道这个问题?
'fromDHMS()'的代码在哪里? – 2014-09-20 15:20:38
没想到有必要 – 2014-09-20 15:32:29