Last active
April 20, 2020 06:58
-
-
Save mickaelw/148c9a967e5f6d3b5feaf462a3a698f0 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 | Basket price calculation', () => { | |
let basket: Basket | |
beforeEach(() => basket = new Basket()) | |
it('For an empty basket', () => { | |
expect(basket.price).to.equal(0) | |
}) | |
describe('Borrowing n different books', () => { | |
it('Apply no discount', () => { | |
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('Borrowing n times the same book', () => { | |
it('Apply no discount for only one book', () => { | |
addNTimesTheSameBook(1) | |
expect(basket.price).to.equal(8) | |
}) | |
it('Apply 5% discount for two same books', () => { | |
addNTimesTheSameBook(2) | |
expect(basket.price).to.equal(15.2) | |
}) | |
it('Apply 25% discount for three same books', () => { | |
addNTimesTheSameBook(3) | |
expect(basket.price).to.equal(18) | |
}) | |
it('Apply 25% discount for more than three times', () => { | |
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