unit-testing/bank/bank-account-test.cs - The class BankAccountTest. | Lecture 14 - slide 22 : 35 Program 2 |
using System; using NUnit.Framework; [TestFixture] public class BankAccountTest{ BankAccount ba1, ba2, ba3; const double tol = 0.000001; [SetUp] public void Init(){ ba1 = new BankAccount("Peter"); ba2 = new BankAccount("Jens", 1000.0); ba3 = new BankAccount("Martin", 2000.0, 0.03); } [Test] public void InitTest(){ Assert.AreEqual(0.0, ba1.Balance, tol, "ba1 init"); Assert.AreEqual(1000.0, ba2.Balance, tol, "ba2 init balance"); Assert.AreEqual(2000.0, ba3.Balance, tol, "ba3 init balance"); Assert.AreEqual(0.0, ba1.InterestRate, tol, "ba1 interest rate"); Assert.AreEqual(0.0, ba2.InterestRate, tol, "ba2 interest rate"); Assert.AreEqual(0.03, ba3.InterestRate, tol, "ba3 interest rate"); } [Test] public void DepositTest(){ ba1.Deposit(100); ba2.Deposit(100); ba3.Deposit(100); Assert.AreEqual(100.0, ba1.Balance, tol, "ba1 deposit"); Assert.AreEqual(1100.0, ba2.Balance, tol, "ba2 deposit"); Assert.AreEqual(2100.0, ba3.Balance, tol, "ba3 deposit"); } [Test] public void WithdrawTest(){ ba1.Withdraw(100.0); ba2.Withdraw(100.0); ba3.Withdraw(100.0); Assert.AreEqual(-100.0, ba1.Balance, tol, "ba1 withdraw"); Assert.AreEqual(900.0, ba2.Balance, tol, "ba2 withdraw"); Assert.AreEqual(1900.0, ba3.Balance, tol, "ba3 withdraw"); } [Test] public void AddInterestsTest(){ ba1.AddInterests(); ba2.AddInterests(); ba3.AddInterests(); Assert.AreEqual(0.0, ba1.Balance, tol, "ba1 add interest"); Assert.AreEqual(1000.0, ba2.Balance, tol, "ba2 add interest"); Assert.AreEqual(2060.0, ba3.Balance, tol, "ba3 add interest"); } }