Last active
April 20, 2020 06:59
-
-
Save mickaelw/8d734d69a7b86ca3d7ec2aed401f507e 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
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