Skip to content

Commit

Permalink
excellalabs#25 - Fix inconsistency between exercises 1 and 6
Browse files Browse the repository at this point in the history
  • Loading branch information
Douglas Matoso committed Oct 2, 2017
1 parent 62da8d1 commit 18f0324
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 21 deletions.
10 changes: 3 additions & 7 deletions exercises/bad_practices/solution/solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
increaseBalance: function(amount){
balance += amount;
},
getBalance: function(){
getBalance: function(){
return balance;
},
canAfford: function(amount){
Expand All @@ -27,10 +27,6 @@ module.exports = {
balance -= amount;
},
isValidAmount: function(amount){
if(!amount){
return false;
} else {
return true;
}
return amount !== null && amount !== undefined;
}
};
};
12 changes: 6 additions & 6 deletions exercises/decompose_balancemanager/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
Expand All @@ -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');
});
Expand All @@ -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;
module.exports = exercise;
4 changes: 2 additions & 2 deletions exercises/decompose_balancemanager/problem.md
Original file line number Diff line number Diff line change
@@ -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.
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.
11 changes: 9 additions & 2 deletions exercises/decompose_balancemanager/solution/solution.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
increaseBalance: function(amount){
balance += amount;
},
getBalance: function(){
getBalance: function(){
return balance;
},
canAfford: function(amount){
Expand All @@ -15,5 +15,12 @@ module.exports = {
throw new Error('Insufficient balance');
}
balance -= amount;
},
isValidAmount: function(amount){
if(amount === null){
return false;
} else {
return true;
}
}
};
};
7 changes: 5 additions & 2 deletions exercises/verify_vendingmachine/solution/balanceManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
increaseBalance: function(amount){
balance += amount;
},
getBalance: function(){
getBalance: function(){
return balance;
},
canAfford: function(amount){
Expand All @@ -15,5 +15,8 @@ module.exports = {
throw new Error('Insufficient balance');
}
balance -= amount;
},
isValidAmount: function(amount){
return amount !== null && amount !== undefined;
}
};
};
10 changes: 8 additions & 2 deletions src/expected/balanceManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ 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){
if(!this.canAfford(amount)){
throw new Error('Insufficient balance');
}
balance -= amount;
},
isValidAmount: function(amount){
return amount !== null && amount !== undefined;
}
};
};

0 comments on commit 18f0324

Please sign in to comment.