[Test]
public void testMultiplication()
{
var five=new Dollar(5);
Assert.AreEqual(new Dollar(10), five.times(2));
Assert.AreEqual(new Dollar(15), five.times(3));
}
lớp DollarLỗi kiểm tra NUnit? Dự kiến <MyType> Nhưng là <MyType>
public class Dollar
{
private int amount;
public Dollar(int amount)
{
this.amount = amount;
}
public Dollar times(int multiplier)
{
return new Dollar(amount * multiplier);
}
public bool equals(Object theObject)
{
Dollar dollar = (Dollar) theObject;
return amount == dollar.amount;
}
}
On line Assert.AreEqual (Dollar mới (10), five.times (2)); thử nghiệm thất bại với lỗi:
dự kiến: TDDbooks.Dollar
Nhưng là: TDDbooks.Dollar
sang một bên: tại sao bạn không thực hiện quá tải toán tử? –
Dường như nó có thể là một vấn đề phiên bản lắp ráp; có thể bạn có hai phiên bản của assembly lắp đặt 'TDDbooks.Dollar' được tải không? –