Hi,
Can anyone help with this scenario:
Using only NUnit Assert.AreEqual method, write tests for the BankAccount class that cover the following cases:
.The Deposit & Withdraw methods will not accept negative numbers.
.BankAccount cannot overstep its overdraft limit.
.The Deposit & Withdraw methods will deposit or withdraw the correct amount, respectively.
.The Withdraw & Deposit methods return the correct results.
Each of the test case methods should be the Tester class & have the Test attribute.
TIA
Can anyone help with this scenario:
Using only NUnit Assert.AreEqual method, write tests for the BankAccount class that cover the following cases:
.The Deposit & Withdraw methods will not accept negative numbers.
.BankAccount cannot overstep its overdraft limit.
.The Deposit & Withdraw methods will deposit or withdraw the correct amount, respectively.
.The Withdraw & Deposit methods return the correct results.
C#:
public class BankAccount
{
public double Balance { get; private set; }
public double OverdraftLimit { get; private set; }
public BankAccount(double overdraftLimit)
{
this.OverdraftLimit = overdraftLimit > 0 ? overdraftLimit : 0;
}
public bool Deposit(double amount)
{
if(amount >=0)
{
this.Balance += amount;
return true;
}
return false;
}
public bool Withdraw(double amount)
{
if(this.Balance - amount >= -this.OverdraftLimit && amount >= 0)
{
this.Balance -= amount;
return true;
}
return false;
}
}
Each of the test case methods should be the Tester class & have the Test attribute.
C#:
using System;
using NUnit.Framework;
[TestFixture]
public class Tester
{
private double epsilon = 1e-6;
[Test]
public void BankAccountCannotHaveNegativeOverdraftLimit()
{
BankAccount account = new BankAccount(-20);
Assert.AreEqual(0, account.OverdraftLimit, epsilon);
}
}
TIA