Skip to content

English #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions eferro/README.md

This file was deleted.

57 changes: 0 additions & 57 deletions eferro/specs/foo_spec.py

This file was deleted.

55 changes: 55 additions & 0 deletions eferro/specs/harry_potter_kata_spec.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# -*- coding: utf-8 -*-

from expects import *
from hamcrest import *
from doublex import *

from collections import Counter

UNIT_PRICE = 8
BOOK1 = 'book1'
BOOK2 = 'book2'
BOOK3 = 'book3'

def books_price(books):
discounts = {
2: 0.95,
3: 0.90,
}
book_counter = Counter(books)
differents = len(book_counter.keys())
repeated = len(books)-differents

return differents * discounts.get(differents, 1) * UNIT_PRICE + repeated * UNIT_PRICE

with context('Harry Potter Kata'):

with describe('buying one by one'):
with it('the cost of the first is UNIT_PRICE'):
expect(books_price([BOOK1])).to(equal(UNIT_PRICE))
with it('the cost of the second is UNIT_PRICE'):
expect(books_price([BOOK2])).to(equal(UNIT_PRICE))

with describe('buying two'):
with it('the cost of two copys of the same book is twice the unit price'):
expect(books_price([BOOK1, BOOK1])).to(equal(16))
expect(books_price([BOOK2, BOOK2])).to(equal(16))

with it('the cost of two different books has a 5percent discount'):
expect(books_price([BOOK1, BOOK2])).to(equal(16*0.95))
expect(books_price([BOOK2, BOOK1])).to(equal(16*0.95))

with describe('buying three books'):
with it('the cost of three copies is 24'):
expect(books_price([BOOK1, BOOK1, BOOK1])).to(equal(24))

with describe('when two book are different'):
with it('the cost is 23.5 (two books with 5percent discount)'):
expect(books_price([BOOK1, BOOK1, BOOK2])).to(equal(16*0.95 + UNIT_PRICE))
with describe('when all are differents'):
with it('the cost is 21.6 (three books with 10percent discount)'):
expect(books_price([BOOK1, BOOK2, BOOK3])).to(equal(UNIT_PRICE * 3*0.90))

with describe('buing four books'):
with it('the cost of four copies is 32'):
expect(books_price([BOOK1, BOOK1, BOOK1, BOOK1])).to(equal(32))