Created
February 6, 2020 11:28
-
-
Save jasongorman/745b2dc36bd2b34b0d535fee0bf24565 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const assert = require('assert'); | |
function Warehouse(catalogue) { | |
this.catalogue = catalogue; | |
this.getCd = function (artist, title) { | |
return this.catalogue.find((cd) => cd.artist == artist && cd.title == title); | |
}; | |
this.buyCd = function (artist, title, catalogue) { | |
const cd = this.getCd(artist, title, catalogue); | |
cd.buy(); | |
return this.catalogue; | |
}; | |
} | |
function CD(artist, title, stock) { | |
this.artist = artist; | |
this.title = title; | |
this.stock = stock; | |
this.getStock = function () { | |
return this.stock; | |
}; | |
this.buy = function () { | |
this.stock -= 1; | |
}; | |
this.matches = function (artist, title) { | |
return this.artist == artist && this.title == title; | |
}; | |
} | |
describe('CD Warehouse', () => { | |
it('reduces stock count by 1 of bought CD', () => { | |
const cd = new CD('Peter Gabriel', 'So', 1); | |
let catalogue = [ | |
cd | |
]; | |
const warehouse = new Warehouse(catalogue); | |
warehouse.buyCd('Peter Gabriel', 'So'); | |
assert.equal(cd.getStock(), 0); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment