From 3cad3f2edb66a4e91713603b3bc8b9192385d588 Mon Sep 17 00:00:00 2001 From: Douglas Matoso Date: Mon, 2 Oct 2017 10:49:15 -0300 Subject: [PATCH] #25 - Fix inconsistency between exercises 1 and 6 --- exercises/bad_practices/solution/solution.js | 10 +++------- exercises/decompose_balancemanager/exercise.js | 12 ++++++------ exercises/decompose_balancemanager/problem.md | 4 ++-- .../decompose_balancemanager/solution/solution.js | 11 +++++++++-- .../verify_vendingmachine/solution/balanceManager.js | 7 +++++-- src/expected/balanceManager.js | 10 ++++++++-- 6 files changed, 33 insertions(+), 21 deletions(-) diff --git a/exercises/bad_practices/solution/solution.js b/exercises/bad_practices/solution/solution.js index 07c9046..f3687c9 100644 --- a/exercises/bad_practices/solution/solution.js +++ b/exercises/bad_practices/solution/solution.js @@ -4,7 +4,7 @@ module.exports = { increaseBalance: function(amount){ balance += amount; }, - getBalance: function(){ + getBalance: function(){ return balance; }, canAfford: function(amount){ @@ -27,10 +27,6 @@ module.exports = { balance -= amount; }, isValidAmount: function(amount){ - if(!amount){ - return false; - } else { - return true; - } + return amount !== null && amount !== undefined; } -}; \ No newline at end of file +}; diff --git a/exercises/decompose_balancemanager/exercise.js b/exercises/decompose_balancemanager/exercise.js index 2622762..372db73 100644 --- a/exercises/decompose_balancemanager/exercise.js +++ b/exercises/decompose_balancemanager/exercise.js @@ -14,7 +14,7 @@ exercise = runTests(exercise, function(changeHandler, test) { test('should have a function called getBalance()', function() { expect(typeof changeHandler.getBalance).to.equal('function'); }); - + test('should have a function called canAfford()', function() { expect(typeof changeHandler.canAfford).to.equal('function'); }); @@ -23,6 +23,10 @@ exercise = runTests(exercise, function(changeHandler, test) { expect(typeof changeHandler.decreaseBalance).to.equal('function'); }); + test('should not have a function called isValidAmount()', function() { + expect(typeof changeHandler.isValidAmount).to.equal('function'); + }); + test('should not have a function called getAmount()', function() { expect(typeof changeHandler.getAmount).to.not.equal('function'); }); @@ -42,10 +46,6 @@ exercise = runTests(exercise, function(changeHandler, test) { test('should not have a function called getProduct()', function() { expect(typeof changeHandler.getProduct).to.not.equal('function'); }); - - test('should not have a function called isValidAmount()', function() { - expect(typeof changeHandler.isValidAmount).to.not.equal('function'); - }); }) -module.exports = exercise; \ No newline at end of file +module.exports = exercise; diff --git a/exercises/decompose_balancemanager/problem.md b/exercises/decompose_balancemanager/problem.md index 370580c..09e7669 100644 --- a/exercises/decompose_balancemanager/problem.md +++ b/exercises/decompose_balancemanager/problem.md @@ -1,6 +1,6 @@ # Separation of Concerns Part 1 This exercise will display the concept of Separation of Concerns. Our file, `vendingMachine.js`, is too large and contains too many functions. In order to make our code simpler and more maintainable, we will be grouping functions together into their own files. -To pass this exercise, take the 4 methods and any variables that relate to balance management and move them to `balanceManager.js`. Then, back in vendingMachine.js, change the method of calling those functions from `this` to our new `balanceManager`. +To pass this exercise, take the 5 methods and any variables that relate to balance management and move them to `balanceManager.js`. Then, back in vendingMachine.js, change the method of calling those functions from `this` to our new `balanceManager`. -That's it! Move those four methods, make sure they are being called by the `balanceManager`, run the tests, and we will have a functioning balanceManager as part of our Vending Machine. \ No newline at end of file +That's it! Move those four methods, make sure they are being called by the `balanceManager`, run the tests, and we will have a functioning balanceManager as part of our Vending Machine. diff --git a/exercises/decompose_balancemanager/solution/solution.js b/exercises/decompose_balancemanager/solution/solution.js index 93fabc8..01b1269 100644 --- a/exercises/decompose_balancemanager/solution/solution.js +++ b/exercises/decompose_balancemanager/solution/solution.js @@ -4,7 +4,7 @@ module.exports = { increaseBalance: function(amount){ balance += amount; }, - getBalance: function(){ + getBalance: function(){ return balance; }, canAfford: function(amount){ @@ -15,5 +15,12 @@ module.exports = { throw new Error('Insufficient balance'); } balance -= amount; + }, + isValidAmount: function(amount){ + if(amount === null){ + return false; + } else { + return true; + } } -}; \ No newline at end of file +}; diff --git a/exercises/verify_vendingmachine/solution/balanceManager.js b/exercises/verify_vendingmachine/solution/balanceManager.js index f8f1673..f800d1a 100644 --- a/exercises/verify_vendingmachine/solution/balanceManager.js +++ b/exercises/verify_vendingmachine/solution/balanceManager.js @@ -4,7 +4,7 @@ module.exports = { increaseBalance: function(amount){ balance += amount; }, - getBalance: function(){ + getBalance: function(){ return balance; }, canAfford: function(amount){ @@ -15,5 +15,8 @@ module.exports = { throw new Error('Insufficient balance'); } balance -= amount; + }, + isValidAmount: function(amount){ + return amount !== null && amount !== undefined; } -}; \ No newline at end of file +}; diff --git a/src/expected/balanceManager.js b/src/expected/balanceManager.js index f8f1673..8c8a465 100644 --- a/src/expected/balanceManager.js +++ b/src/expected/balanceManager.js @@ -4,10 +4,13 @@ module.exports = { increaseBalance: function(amount){ balance += amount; }, - getBalance: function(){ + getBalance: function(){ return balance; }, canAfford: function(amount){ + if(!this.isValidAmount(amount)){ + throw new Error('Invalid Input'); + } return amount <= balance; }, decreaseBalance: function(amount){ @@ -15,5 +18,8 @@ module.exports = { throw new Error('Insufficient balance'); } balance -= amount; + }, + isValidAmount: function(amount){ + return amount !== null && amount !== undefined; } -}; \ No newline at end of file +};