Skip to content

Commit

Permalink
Raghavendra's changes
Browse files Browse the repository at this point in the history
added logic and test cases for
1. A customer can transfer between their accounts
2. Change Maxi-Savings accounts to have an interest rate of 5% assuming
no withdrawals in the past 10 days otherwise 0.1%
  • Loading branch information
raagztv committed Dec 17, 2014
1 parent 792c4e0 commit 019aaa5
Show file tree
Hide file tree
Showing 15 changed files with 408 additions and 140 deletions.
4 changes: 4 additions & 0 deletions AbcBank.Test/AbcBank.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AccountTest.cs" />
<Compile Include="BankTest.cs" />
<Compile Include="CustomerTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand All @@ -58,6 +59,9 @@
<Name>AbcBank</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Expand Down
67 changes: 67 additions & 0 deletions AbcBank.Test/AccountTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AbcBank.Test
{
[TestFixture]
public class AccountTest
{
public void Test_Deposit()
{
SavingsAccount svgAccount = new SavingsAccount();
svgAccount.Deposit(100);
Assert.AreEqual(1, svgAccount.transactions.Count);
}

[Test]
[ExpectedException]
public void Test_DepositNegativeAmount()
{
SavingsAccount svgAccount = new SavingsAccount();
svgAccount.Deposit(-100);
Assert.AreEqual(1, svgAccount.transactions.Count);
}

[Test]
public void Test_Withdraw()
{
SavingsAccount svgAccount = new SavingsAccount();
svgAccount.Deposit(100);

svgAccount.Withdraw(100);
Assert.AreEqual(2, svgAccount.transactions.Count);
}

[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "amount to withdraw is more than your current balance")]
public void Test_WithdrawMoreThanBalance()
{
SavingsAccount svgAccount = new SavingsAccount();
svgAccount.Withdraw(100);
Assert.AreEqual(1, svgAccount.transactions.Count);
}

[Test]
[ExpectedException(typeof(ArgumentException), ExpectedMessage = "amount must be greater than zero")]
public void Test_WithdrawNegativeAmount()
{
SavingsAccount svgAccount = new SavingsAccount();
svgAccount.Withdraw(-100);
Assert.AreEqual(1, svgAccount.transactions.Count);
}

[Test]
public void Test_SumTransactions()
{
SavingsAccount acc1 = new SavingsAccount();
acc1.Deposit(100);
acc1.Deposit(200);

Assert.AreEqual(300, acc1.SumTransactions());
}
}
}
72 changes: 52 additions & 20 deletions AbcBank.Test/BankTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,84 @@ public class BankTest
private static readonly double DOUBLE_DELTA = 1e-15;

[Test]
public void customerSummary()
public void Test_CustomerSummary()
{
Bank bank = new Bank();
Customer john = new Customer("John");
john.openAccount(new Account(Account.CHECKING));
bank.addCustomer(john);
john.OpenAccount(new CheckingAccount());
bank.AddCustomer(john);

Assert.AreEqual("Customer Summary\n - John (1 account)", bank.customerSummary());
Assert.AreEqual("Customer Summary\n - John (1 account)", bank.CustomerSummary());
}

[Test]
public void checkingAccount()
public void Test_CustomerSummary_ZeroAccounts()
{
Bank bank = new Bank();
Account checkingAccount = new Account(Account.CHECKING);
Customer bill = new Customer("Bill").openAccount(checkingAccount);
bank.addCustomer(bill);
Customer john = new Customer("John");

Assert.AreEqual("Customer Summary\n - No accounts found", bank.CustomerSummary());
}

checkingAccount.deposit(100.0);
[Test]
public void Test_GetFirstCustomerName()
{
Bank bank = new Bank();
Customer john = new Customer("John");
bank.AddCustomer(john);

Assert.AreEqual(0.1, bank.totalInterestPaid(), DOUBLE_DELTA);
Assert.AreEqual("John", bank.GetFirstCustomerName());
}

[Test]
public void Test_GetFirstCustomerName_Exception()
{
Bank bank = new Bank();
Assert.AreEqual("Error", bank.GetFirstCustomerName());
}

[Test]
public void savings_account()
public void Test_InterestPaid_CheckingAccount()
{
Bank bank = new Bank();
Account checkingAccount = new Account(Account.SAVINGS);
bank.addCustomer(new Customer("Bill").openAccount(checkingAccount));
Account checkingAccount = new CheckingAccount();
Customer bill = new Customer("Bill").OpenAccount(checkingAccount);
bank.AddCustomer(bill);

checkingAccount.deposit(1500.0);
checkingAccount.Deposit(100.0);

Assert.AreEqual(2.0, bank.totalInterestPaid(), DOUBLE_DELTA);
Assert.AreEqual(0.1, bank.TotalInterestPaid(), DOUBLE_DELTA);
}

[Test]
public void maxi_savings_account()
public void Test_InterestPaid_SavingsAccount()
{
Bank bank = new Bank();
Account checkingAccount = new Account(Account.MAXI_SAVINGS);
bank.addCustomer(new Customer("Bill").openAccount(checkingAccount));
Account checkingAccount = new SavingsAccount();
bank.AddCustomer(new Customer("Bill").OpenAccount(checkingAccount));

checkingAccount.deposit(3000.0);
checkingAccount.Deposit(1500.0);

Assert.AreEqual(170.0, bank.totalInterestPaid(), DOUBLE_DELTA);
Assert.AreEqual(2.0, bank.TotalInterestPaid(), DOUBLE_DELTA);
}

[Test]
public void Test_InterestPaid_MaxSavings_Account()
{
Bank bank = new Bank();
Account checkingAccount = new MaxSavingsAccount();
bank.AddCustomer(new Customer("Bill").OpenAccount(checkingAccount));

checkingAccount.Deposit(3000.0);

Assert.AreEqual(150.0, bank.TotalInterestPaid(), DOUBLE_DELTA);
}

[Test]
public void Test_InterestPaid_ZeroCustomers()
{
Bank bank = new Bank();
Assert.AreEqual(0.0, bank.TotalInterestPaid());
}
}
}
97 changes: 63 additions & 34 deletions AbcBank.Test/CustomerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,84 @@ public class CustomerTest
{

[Test] //Test customer statement generation
public void testApp()
{
public void Test_GetStatement()
{
Account checkingAccount = new CheckingAccount();
Account savingsAccount = new SavingsAccount();

Customer henry = new Customer("Henry").OpenAccount(checkingAccount).OpenAccount(savingsAccount);

checkingAccount.Deposit(100.0);
savingsAccount.Deposit(4000.0);
savingsAccount.Withdraw(200.0);

Assert.AreEqual("Statement for Henry\n\n deposit $100.00\nTotal $100.00\n\n deposit $4,000.00\n withdrawal $200.00\nTotal $3,800.00\n\nTotal In All Accounts $3,900.00", henry.GetStatement());
}

Account checkingAccount = new Account(Account.CHECKING);
Account savingsAccount = new Account(Account.SAVINGS);

Customer henry = new Customer("Henry").openAccount(checkingAccount).openAccount(savingsAccount);

checkingAccount.deposit(100.0);
savingsAccount.deposit(4000.0);
savingsAccount.withdraw(200.0);

Assert.AreEqual("Statement for Henry\n" +
"\n" +
"Checking Account\n" +
" deposit $100.00\n" +
"Total $100.00\n" +
"\n" +
"Savings Account\n" +
" deposit $4,000.00\n" +
" withdrawal $200.00\n" +
"Total $3,800.00\n" +
"\n" +
"Total In All Accounts $3,900.00", henry.getStatement());
[Test]
public void Test_GetStatement_ZeroAccounts()
{
Customer henry = new Customer("Henry");
Assert.AreEqual("Statement for Henry\n\nTotal In All Accounts $0.00", henry.GetStatement());
}

[Test]
public void testOneAccount()
public void Test_OneAccount()
{
Customer oscar = new Customer("Oscar").openAccount(new Account(Account.SAVINGS));
Assert.AreEqual(1, oscar.getNumberOfAccounts());
Customer oscar = new Customer("Oscar").OpenAccount(new SavingsAccount());
Assert.AreEqual(1, oscar.GetNumberOfAccounts());
}

[Test]
public void testTwoAccount()
public void Test_TwoAccount()
{
Customer oscar = new Customer("Oscar")
.openAccount(new Account(Account.SAVINGS));
oscar.openAccount(new Account(Account.CHECKING));
Assert.AreEqual(2, oscar.getNumberOfAccounts());
.OpenAccount(new SavingsAccount());
oscar.OpenAccount(new CheckingAccount());
Assert.AreEqual(2, oscar.GetNumberOfAccounts());
}


[Ignore]
public void testThreeAcounts()
public void TestThreeAcounts()
{
Customer oscar = new Customer("Oscar")
.openAccount(new Account(Account.SAVINGS));
oscar.openAccount(new Account(Account.CHECKING));
Assert.AreEqual(3, oscar.getNumberOfAccounts());
.OpenAccount(new SavingsAccount());
oscar.OpenAccount(new CheckingAccount());
Assert.AreEqual(3, oscar.GetNumberOfAccounts());
}

[Test]
public void Test_TransferFunds()
{
Customer customer = new Customer("Jim");
SavingsAccount svgsAccount = new SavingsAccount();
svgsAccount.Deposit(100);
customer.OpenAccount(svgsAccount);

CheckingAccount chkAccount = new CheckingAccount();
customer.OpenAccount(chkAccount);

customer.TransferFunds(svgsAccount, chkAccount, 100);

Assert.AreEqual(100, chkAccount.SumTransactions());
}

[Test]
[ExpectedException("System.Exception")]
public void Test_TransferFundsException()
{
Customer customer = new Customer("Jim");
SavingsAccount svgsAccount = new SavingsAccount();
customer.OpenAccount(svgsAccount);

CheckingAccount chkAccount = new CheckingAccount();
customer.OpenAccount(chkAccount);

customer.TransferFunds(svgsAccount, chkAccount, 100);

Assert.AreEqual(100, chkAccount.SumTransactions());
}
}

}
2 changes: 1 addition & 1 deletion AbcBank.Test/TransactionTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace AbcBank.Test
public class TransactionTest
{
[Test]
public void transaction()
public void Test_Transaction()
{
Transaction t = new Transaction(5);
Assert.AreEqual(true, t is Transaction);
Expand Down
5 changes: 5 additions & 0 deletions AbcBank/AbcBank.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,14 @@
<ItemGroup>
<Compile Include="Account.cs" />
<Compile Include="Bank.cs" />
<Compile Include="CheckingAccount.cs" />
<Compile Include="Constants.cs" />
<Compile Include="Customer.cs" />
<Compile Include="DateProvider.cs" />
<Compile Include="DoubleExtensions.cs" />
<Compile Include="MaxSavingsAccount.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="SavingsAccount.cs" />
<Compile Include="Transaction.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Expand Down
Loading

0 comments on commit 019aaa5

Please sign in to comment.