Created
April 23, 2019 08:09
-
-
Save jasongorman/fb4b635eabbb656e4d3ee0921f95fb0c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[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