Skip to content

Commit

Permalink
<Imran/Devesh>: Rafactored code
Browse files Browse the repository at this point in the history
  • Loading branch information
unknown committed Apr 4, 2011
1 parent a9cce74 commit 0e82db8
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Src/AnujBank/AnujBank/ClientAccounts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public bool SharesAccountWith(ClientAccounts clientAccounts)
}


public double CumulativeBalance()
public double NetBalance()
{
return accounts.Sum(x => x.Balance);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

namespace TestAnujBank
{
public class InterestRateConfigurationManager
public class InterestRates
{

private double positiveInterestRate;
private double negativeInterestRate;
TextReader Reader { get; set; }

public InterestRateConfigurationManager()
public InterestRates()
{

}
public InterestRateConfigurationManager(TextReader reader)
public InterestRates(TextReader reader)
{
Reader = reader;
}
Expand Down
9 changes: 3 additions & 6 deletions Src/AnujBank/AnujBank/Structure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,17 @@ public bool SharesASourceAccountWith(Structure newStructure)

public double NetBalance()
{
return sourceClientAccounts.CumulativeBalance();
return sourceClientAccounts.NetBalance();
}

public double NetInterest(InterestRateConfigurationManager interestRateConfigurationManager)
{
double cumulativeBalance = sourceClientAccounts.CumulativeBalance();
double cumulativeBalance = NetBalance();
if(cumulativeBalance > 0)
{
return interestRateConfigurationManager.PositiveInterestRate()*cumulativeBalance/36500;
}
else
{
return interestRateConfigurationManager.NegativeInterestRate()*cumulativeBalance/36500;
}
return interestRateConfigurationManager.NegativeInterestRate()*cumulativeBalance/36500;
}
}
}
4 changes: 2 additions & 2 deletions Src/AnujBank/TestAnujBank/TestClientAccounts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void ShouldBeAbleToFindTwoClientAccountsShareACommonAccount()
}

[Test]
public void ShouldCalculateCumulativeBalance()
public void ShouldCalculateNetBalance()
{
var account1 = new Account(new AccountId(12341234), new ClientId("ABC123"));
var account2 = new Account(new AccountId(12341235), new ClientId("ABC123"));
Expand All @@ -55,7 +55,7 @@ public void ShouldCalculateCumulativeBalance()
clientAccounts.Add(account1);
clientAccounts.Add(account2);

Assert.AreEqual(500.0, clientAccounts.CumulativeBalance());
Assert.AreEqual(500.0, clientAccounts.NetBalance());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
namespace TestAnujBank
{
[TestFixture]
public class TestInterestRateConfigurationManager
public class TestInterestRates
{
[Test]
public void ShouldLoadInterestRates()
{
StringReader reader = new StringReader("PositiveInterestRate=2.0\nNegativeInterestRate=3.0");
var configurationManager = new InterestRateConfigurationManager(reader);
var configurationManager = new InterestRates(reader);
Assert.AreEqual(0.0d, configurationManager.PositiveInterestRate());
Assert.AreEqual(0.0d, configurationManager.NegativeInterestRate());
configurationManager.Configure();
Expand Down

0 comments on commit 0e82db8

Please sign in to comment.