예제 #1
0
def test_basket_countTotalPrice_buySomeBooks_ut():
    first_book = Book("Potter1", 8.0)
    second_book = Book("Potter2", 8.0)
    third_book = Book("Potter3", 8.0)
    fourth_book = Book("Potter4", 8.0)
    fifth_book = Book("Potter5", 8.0)

    basket = Basket()
    basket.addBook(first_book)
    basket.addBook(second_book)
    basket.addBook(third_book)
    basket.addBook(fourth_book)
    basket.addBook(fifth_book)

    basket.addBook(first_book)
    basket.addBook(second_book)
    basket.addBook(fourth_book)
    basket.addBook(fifth_book)

    basket.addBook(second_book)

    basket.sort_collection_of_books()

    total = 5 * 8.0 * 0.75 + 4 * 8.0 * 0.8 + 1 * 8.0 * 1

    assert total == basket.countTotalPrice()
예제 #2
0
def test_basket_addBook_addTwoBooks_TwoBooksInBasket_ut():
    first_book = Book("Potter1", 8.0)
    second_book = Book("Potter2", 8.0)

    basket = Basket()
    basket.addBook(first_book)
    basket.addBook(second_book)

    assert len(basket) == 2
예제 #3
0
def test_basket_sortCollectionOfBooks_TwoDifferentBooks_ut():
    first_book = Book("Potter1", 8.0)
    second_book = Book("Potter2", 8.0)

    basket = Basket()
    basket.addBook(first_book)
    basket.addBook(second_book)

    sorted_list = [{first_book, second_book}]

    assert sorted_list == basket.sort_collection_of_books()
예제 #4
0
def test_basket_countTotalPrice_buyTwoDifferentBooks_fivePercentOfDiscount_ut(
):
    first_book = Book("Potter1", 8.0)
    second_book = Book("Potter2", 8.0)

    basket = Basket()
    basket.addBook(first_book)
    basket.addBook(second_book)

    basket.sort_collection_of_books()

    assert basket.countTotalPrice() == 15.2
예제 #5
0
def test_basket_countTotalPrice_buyThreeDifferentBooks_tenPercentOfDiscountut(
):
    first_book = Book("Potter1", 8.0)
    second_book = Book("Potter2", 8.0)
    third_book = Book("Potter3", 8.0)

    basket = Basket()
    basket.addBook(first_book)
    basket.addBook(second_book)
    basket.addBook(third_book)

    basket.sort_collection_of_books()

    assert 24.0 * 0.9 == basket.countTotalPrice()
예제 #6
0
def test_basket_countTotalPrice_buyFiveDifferentBooks_25PercentOfDiscount_ut():
    first_book = Book("Potter1", 8.0)
    second_book = Book("Potter2", 8.0)
    third_book = Book("Potter3", 8.0)
    fourth_book = Book("Potter4", 8.0)
    fifth_book = Book("Potter5", 8.0)

    basket = Basket()
    basket.addBook(first_book)
    basket.addBook(second_book)
    basket.addBook(third_book)
    basket.addBook(fourth_book)
    basket.addBook(fifth_book)

    basket.sort_collection_of_books()

    assert 8.0 * 5 * 0.75 == basket.countTotalPrice()
예제 #7
0
def test_basket_countTotalPrice_oneBooks_ut():

    basket = Basket()
    fifth_book = Book("Potter5", 8.0)
    basket.addBook(fifth_book)

    basket.sort_collection_of_books()

    assert 8.0 == basket.countTotalPrice()
예제 #8
0
def test_basket_countTotalPrice_buyTwoThisSameBooks_noDiscount_ut():
    first_book = Book("Potter1", 8.0)

    basket = Basket()
    basket.addBook(first_book)
    basket.addBook(first_book)

    basket.sort_collection_of_books()

    assert basket.countTotalPrice() == 16.0
예제 #9
0
def test_basket_sortCollectionOfBooks_TwoThisSameBooks_ut():
    first_book = Book("Potter1", 8.0)

    basket = Basket()
    basket.addBook(first_book)
    basket.addBook(first_book)

    sorted_list = [{first_book}, {first_book}]

    assert sorted_list == basket.sort_collection_of_books()
예제 #10
0
def test_basket_countTotalPrice_SpecialCase_ut():
    first_book = Book("Potter1", 8.0)
    second_book = Book("Potter2", 8.0)
    third_book = Book("Potter3", 8.0)
    fourth_book = Book("Potter4", 8.0)
    fifth_book = Book("Potter5", 8.0)

    basket = Basket()
    basket.addBook(first_book)
    basket.addBook(second_book)
    basket.addBook(third_book)
    basket.addBook(fourth_book)
    basket.addBook(fifth_book)

    basket.addBook(first_book)
    basket.addBook(second_book)
    basket.addBook(third_book)

    basket.sort_collection_of_books()

    total = 4 * 8.0 * 0.8 + 4 * 8.0 * 0.8

    assert total == basket.countTotalPrice()
예제 #11
0
def test_book_canCreateBook_noSideEffects_ut():

    book = Book("Potter1", 8.0)
    assert book.title == "Potter1"
    assert book.price == 8.0
예제 #12
0
def test_basket_addBook_addOneBook_OneBookInBasket_ut():
    book = Book("Potter1", 8.0)
    basket = Basket()
    basket.addBook(book)

    assert len(basket) == 1