Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
describe('Unit | Caclcule du prix du panier', () => {
let basket: Basket
beforeEach(() => basket = new Basket())
it('Pour un panier vide', () => {
expect(basket.price).to.be.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.be.equal(32)
})
})
describe('Emprunter n fois le même livre', () => {
it('Appliquer aucune remise pour uniquement un livre', () => {
addNTimesTheSameBook(1)
expect(basket.price).to.be.equal(8)
})
it('Appliquer 5% de remise pour 2 livres identiques', () => {
addNTimesTheSameBook(2)
expect(basket.price).to.be.equal(15.2)
})
it('Appliquer 25% de remise pour 3 livres identiques', () => {
addNTimesTheSameBook(3)
expect(basket.price).to.be.equal(18)
})
it('Appliquer 25% de remise pour plus de 3 livres identiques', () => {
addNTimesTheSameBook(4)
expect(basket.price).to.be.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
You can’t perform that action at this time.