0
public Double Invert(Double? id)
{
return (Double)(id/id);
}
我已經這樣做了這個測試,但未能取悅任何人都可以用這個COS剛開始的單元測試幫助單位在ASP.NET測試控制器MVC 3
/* HINT: Remember that you are passing Invert an *integer* so
* the value of 1/input is calculated using integer arithmetic.
* */
//Arrange
var controller = new UrlParameterController();
int input = 7;
Double expected = 0.143d;
Double marginOfError = 0.001d;
//Act
var result = controller.Invert(input);
//Assert
Assert.AreEqual(expected, result, marginOfError);
/* NOTE This time we use a different Assert.AreEqual() method, which
* checks whether or not two Double values are within a specified
* distance of one another. This is a good way to deal with rounding
* errors from floating point arithmetic. Without the marginOfError
* parameter the assertion fails.
* */
我沒有看到問題,請更具體地與您的帖子。 –
這似乎更多地是關於浮點運算而不是單元測試。 'Assert'的結果是什麼? – DaveShaw
你爲什麼使用可爲空的Double?無論如何劃分爲零是不可能的,所以它只會導致一個神祕的錯誤。 –