Skip to content

Instantly share code, notes, and snippets.

@FagnerMartinsBrack
Created November 22, 2018 10:01
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/bfc4cbf4cb9822ef2c9a386030911271 to your computer and use it in GitHub Desktop.
Save FagnerMartinsBrack/bfc4cbf4cb9822ef2c9a386030911271 to your computer and use it in GitHub Desktop.
(Medium) - How TDD Can Prevent Over-Engineering
@@ -7,12 +7,7 @@
assert.strictEqual(actual, expected);
}
- const calculateInterestForGreaterThan2000 = (loanAmount, endOfRange, interestPerDollar, previousInterestPerDollar) => {
- const greaterThan2000 = {
- endOfRange: endOfRange,
- interestPerDollar: interestPerDollar,
- previousInterestPerDollar: previousInterestPerDollar
- };
+ const calculateInterestForGreaterThan2000 = (loanAmount, greaterThan2000) => {
const dollarsAboveThreshold = loanAmount.minus(greaterThan2000.endOfRange);
const interestToPay = greaterThan2000.interestPerDollar.minus(greaterThan2000.previousInterestPerDollar).multipliedBy(dollarsAboveThreshold);
return interestToPay;
@@ -43,8 +38,13 @@
if (loanAmount.greaterThan(END_OF_FIRST_RANGE) && loanAmount.lessThan(Money('$5001.00'))) {
let interestAmount = Money('$0.00');
+ const greaterThan2000 = {
+ endOfRange: END_OF_FIRST_RANGE,
+ interestPerDollar: CENTS_FOR_SECOND_RANGE,
+ previousInterestPerDollar: CENTS_FOR_FIRST_RANGE
+ };
interestAmount = interestAmount.plus(
- calculateInterestForGreaterThan2000(loanAmount, END_OF_FIRST_RANGE, CENTS_FOR_SECOND_RANGE, CENTS_FOR_FIRST_RANGE)
+ calculateInterestForGreaterThan2000(loanAmount, greaterThan2000)
);
return interestAmount;
@@ -53,8 +53,13 @@
if (loanAmount.greaterThan(END_OF_SECOND_RANGE) && loanAmount.lessThan(Money('$10001.00'))) {
let interestAmount = Money('$0.00');
+ const greaterThan2000 = {
+ endOfRange: END_OF_FIRST_RANGE,
+ interestPerDollar: CENTS_FOR_SECOND_RANGE,
+ previousInterestPerDollar: CENTS_FOR_FIRST_RANGE
+ };
interestAmount = interestAmount.plus(
- calculateInterestForGreaterThan2000(loanAmount, END_OF_FIRST_RANGE, CENTS_FOR_SECOND_RANGE, CENTS_FOR_FIRST_RANGE)
+ calculateInterestForGreaterThan2000(loanAmount, greaterThan2000)
);
interestAmount = interestAmount.plus(
calculateInterestForGreaterThan5000(loanAmount, END_OF_SECOND_RANGE, CENTS_FOR_THIRD_RANGE, CENTS_FOR_SECOND_RANGE)
@@ -66,8 +71,13 @@
if (loanAmount.greaterThan(END_OF_THIRD_RANGE)) {
let interestAmount = Money('$0.00');
+ const greaterThan2000 = {
+ endOfRange: END_OF_FIRST_RANGE,
+ interestPerDollar: CENTS_FOR_SECOND_RANGE,
+ previousInterestPerDollar: CENTS_FOR_FIRST_RANGE
+ };
interestAmount = interestAmount.plus(
- calculateInterestForGreaterThan2000(loanAmount, END_OF_FIRST_RANGE, CENTS_FOR_SECOND_RANGE, CENTS_FOR_FIRST_RANGE)
+ calculateInterestForGreaterThan2000(loanAmount, greaterThan2000)
);
interestAmount = interestAmount.plus(
calculateInterestForGreaterThan5000(loanAmount, END_OF_SECOND_RANGE, CENTS_FOR_THIRD_RANGE, CENTS_FOR_SECOND_RANGE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment