Skip to content

Commit

Permalink
add assertion comments to all Tap tests in .md for #34
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Oct 30, 2018
1 parent 98c3be9 commit afbf11a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/vending-machine.js
Expand Up @@ -63,7 +63,7 @@ function getCoinsAvail () {
*/
function sellProduct (totalPayable, coinsPaid, coinsAvail) {
const cashPaid = coinsPaid.reduce( function(sum, c) { return sum + c }, 0);
const change = calculateChange(totalPayable, cashPaid);
const change = calculateChange(totalPayable, cashPaid, coinsAvail);
// remove the coins we are about to return as change from the coinsAvail:
setCoinsAvail(reduceCoinSupply(coinsAvail, change));
return change;
Expand Down
29 changes: 18 additions & 11 deletions tap-advanced-testing.md
Expand Up @@ -370,7 +370,8 @@ const reduceCoinSupply = vendingMachine.reduceCoinSupply;
tap.test('reduceCoinSupply([200, 100, 50, 10, 1], [100, 50, 10]); returns [200, 1]', function (t) {
const result = reduceCoinSupply([200, 100, 50, 10, 1], [100, 50, 10]);
const expected = [200, 1];
t.deepEqual(result, expected);
t.deepEqual(result, expected,
'reduceCoinSupply reduces the coinsAvail by the coins given as change');
t.end();
});
```
Expand Down Expand Up @@ -447,7 +448,8 @@ tap.test('reduceCoinSupply remove more coins!', function (t) {
];

const result = reduceCoinSupply(COINS, remove);
t.deepEqual(result, expected);
t.deepEqual(result, expected,
'reduceCoinSupply removes coins from supply of coinsAvail');
t.end();
});
```
Expand Down Expand Up @@ -499,9 +501,11 @@ tap.test('Check Initial Supply of Coins in Vending Machine', function (t) {
2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1
];
t.deepEqual(vendingMachine.getCoinsAvail(), COINS);
t.deepEqual(vendingMachine.getCoinsAvail(), COINS,
'vendingMachine.getCoinsAvail() gets COINS available in Vending Machine');
vendingMachine.setCoinsAvail([1,2,3]);
t.deepEqual(vendingMachine.getCoinsAvail(), [1,2,3]);
t.deepEqual(vendingMachine.getCoinsAvail(), [1,2,3],
'vendingMachine.setCoinsAvail allows us to set the COINS available');
t.end();
});
```
Expand All @@ -519,7 +523,7 @@ you will see the last one fail:

In `lib/vending-machine.js` file,
after the `reduceCoinSupply` function definition,
add the following variable declaration:
add the following variable declaration and pair of functions:

```js
// GOLBAL Coins Available Array. 10 of each type of coin.
Expand All @@ -534,7 +538,6 @@ let COINS = [
1, 1, 1, 1, 1, 1, 1, 1, 1, 1
];


/**
* setCoinsAvail a "setter" for the COINS Array
* @param {Array} coinsAvail the list of available coins
Expand All @@ -549,10 +552,11 @@ function setCoinsAvail (coinsAvail) {
function getCoinsAvail () {
return COINS;
}

```

We will _use_ the `COINS` array in the next step.
We will _use_ the `COINS` array
and both the "getter" and "setter"
in the next step.
For now, simply _export_ "getter" and "setter" so the test will pass:

```js
Expand Down Expand Up @@ -618,9 +622,12 @@ tap.test('sellProduct(215, [200, 100], COINS) returns [50, 20, 10, 5]', function
const coinsPaid = [200, 100];
const result = vendingMachine.sellProduct(215, coinsPaid, COINS);
const expected = [50, 20, 10, 5];
t.deepEqual(result, expected);
t.deepEqual(result, expected,
'sellProduct returns the correct coins as change');

// check that the supply of COINS Available in the vendingMachine was reduced:
t.deepEqual(vendingMachine.getCoinsAvail(), reduceCoinSupply(COINS, result));
t.deepEqual(vendingMachine.getCoinsAvail(), reduceCoinSupply(COINS, result),
'running the sellProduct function reduces the COINS the vending machine');
t.end();
});
```
Expand Down Expand Up @@ -653,7 +660,7 @@ If you run the tests:
node test/vending-machine.test.js
```

you will see the last one fail:
you will see the last one _fail_:

![sellProduct-test-fail](https://user-images.githubusercontent.com/194400/47678596-1bb44880-dbba-11e8-8927-892149a201bd.png)

Expand Down

0 comments on commit afbf11a

Please sign in to comment.