Skip to content

Instantly share code, notes, and snippets.

@FagnerMartinsBrack
Created November 22, 2018 10:45
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 FagnerMartinsBrack/95b1b2dce6a72e19b99425c5e64fba62 to your computer and use it in GitHub Desktop.
Save FagnerMartinsBrack/95b1b2dce6a72e19b99425c5e64fba62 to your computer and use it in GitHub Desktop.
(Medium) - How TDD Can Prevent Over-Engineering
const interestToPayFor = (loanAmount) => {
const greaterThan2000 = { endOfRange: Money('$2000.00'), interestPerDollar: Money('$0.09'), previousInterestPerDollar: Money('$0.00') };
const greaterThan5000 = { endOfRange: Money('$5000.00'), interestPerDollar: Money('$0.14'), previousInterestPerDollar: Money('$0.09') };
const greaterThan10000 = { endOfRange: Money('$10000.00'), interestPerDollar: Money('$0.21'), previousInterestPerDollar: Money('$0.14') };
// You can move this into a configuration file so that changes
// in the behavior doesn't require code changes
const ranges = [greaterThan2000, greaterThan5000, greaterThan10000];
let interestAmount = Money('$0.00');
for (range of ranges) {
if (loanAmount.greaterThan(range.endOfRange)) {
interestAmount = interestAmount.plus(calculateInterest(loanAmount, range));
}
}
return interestAmount;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment