Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Created April 23, 2019 08:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongorman/7e82cd95419ed3977d029e6ad3ec0be3 to your computer and use it in GitHub Desktop.
Save jasongorman/7e82cd95419ed3977d029e6ad3ec0be3 to your computer and use it in GitHub Desktop.
[TestFixture]
public class TransferTests
{
[Test]
public void AmountTransferredFromPayerToPayee()
{
var transfer = new FundsTransfer();
// initialise accounts
var payerBalance = transfer.InitAccount();
var payeeBalance = transfer.InitAccount();
// credit payer with funds to allow transfer
transfer.Credit(ref payerBalance, 100);
// transfer 50
transfer.Transfer(ref payerBalance, ref payeeBalance, 50);
Assert.That(payerBalance, Is.EqualTo(50));
Assert.That(payeeBalance, Is.EqualTo(50));
}
}
public class FundsTransfer
{
public double InitAccount()
{
double balance = 0;
return balance;
}
public void Transfer(ref double payerBalance, ref double payeeBalance, double amount)
{
Debit(ref payerBalance, amount);
Credit(ref payeeBalance, amount);
}
public void Credit(ref double balance, double amount)
{
balance += amount;
}
public void Debit(ref double balance, double amount)
{
balance -= amount;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment