Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Created April 23, 2019 08:09
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/fb4b635eabbb656e4d3ee0921f95fb0c to your computer and use it in GitHub Desktop.
Save jasongorman/fb4b635eabbb656e4d3ee0921f95fb0c to your computer and use it in GitHub Desktop.
[TestFixture]
public class TransferTests
{
[Test]
public void AmountTransferredFromPayerToPayee()
{
// initialise accounts
var payerBalance = InitAccount();
var payeeBalance = InitAccount();
// credit payer with funds to allow transfer
Credit(ref payerBalance, 100);
// transfer 50
Transfer(ref payerBalance, ref payeeBalance, 50);
Assert.That(payerBalance, Is.EqualTo(50));
Assert.That(payeeBalance, Is.EqualTo(50));
}
private double InitAccount()
{
double balance = 0;
return balance;
}
private void Transfer(ref double payerBalance, ref double payeeBalance, double amount)
{
Debit(ref payerBalance, amount);
Credit(ref payeeBalance, amount);
}
private void Credit(ref double payerBalance, double amount)
{
payerBalance += amount;
}
private void Debit(ref double payerBalance, double amount)
{
payerBalance -= amount;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment