Skip to content

Instantly share code, notes, and snippets.

@mickaelw
Last active April 20, 2020 06:59
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 mickaelw/8d734d69a7b86ca3d7ec2aed401f507e to your computer and use it in GitHub Desktop.
Save mickaelw/8d734d69a7b86ca3d7ec2aed401f507e to your computer and use it in GitHub Desktop.
describe('Unit | Caclcule du prix du panier', () => {
let basket: Basket
beforeEach(() => basket = new Basket())
it('Pour un panier vide', () => {
expect(basket.price).to.equal(0)
})
describe('Emprunter n livres différents', () => {
it('Appliquer aucune remise', () => {
basket.add(new Book('1'))
basket.add(new Book('2'))
basket.add(new Book('3'))
basket.add(new Book('5'))
expect(basket.price).to.equal(32)
})
})
describe('Emprunter n fois le même livre', () => {
it('Appliquer aucune remise pour uniquement un livre', () => {
addNTimesTheSameBook(1)
expect(basket.price).to.equal(8)
})
it('Appliquer 5% de remise pour 2 livres identiques', () => {
addNTimesTheSameBook(2)
expect(basket.price).to.equal(15.2)
})
it('Appliquer 25% de remise pour 3 livres identiques', () => {
addNTimesTheSameBook(3)
expect(basket.price).to.equal(18)
})
it('Appliquer 25% de remise pour plus de 3 livres identiques', () => {
addNTimesTheSameBook(4)
expect(basket.price).to.equal(24)
})
function addNTimesTheSameBook(nTimes: number) {
const book = new Book('1')
for (let i = 1; i <= nTimes; i++)
basket.add(book)
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment