Beispiel #1
0
    def setUp(self):
        self.transition = [[0, 2, 3], [3, 0, 4], [3, 4, 0]]
        self.books = [
            Book(0, 1, 5),
            Book(1, 0, 3),
            Book(2, 1, 10),
            Book(3, 1, 2),
            Book(4, 2, 8),
        ]
        self.readers = [
            Reader({
                0: 3,
                1: 2
            }, 0, 10),
            Reader({
                1: 1,
                2: 10,
                3: 3
            }, 0, 10),
            Reader({
                0: 1,
                1: 1,
                2: 1,
                3: 1,
                4: 1
            }, 1, 10),
            Reader({
                2: 5,
                4: 5
            }, 2, 10),
        ]

        self.state = State(self.transition, self.books, self.readers)
 def setUp(self):
     self.book_data = {0: 5, 1: 2, 3: 3}
     self.reader = Reader(books=self.book_data, location=1, max_weeks=6)
     self.books = [
         Book(0, 3, 1),
         Book(1, 5, 0),
         Book(2, 4, 1),
         Book(3, 2, 1)
     ]
Beispiel #3
0
 def setUp(self):
     self.book_data = {0: 5, 1: 2, 3: 3}
     self.reader = Reader(books=self.book_data, location=1, max_weeks=6)
     self.books = [
         Book(0, 1, 3),
         Book(1, 0, 5),
         Book(2, 1, 4),
         Book(3, 1, 2)
     ]
Beispiel #4
0
    def setUp(self):

        self.room_1 = Room("Bongo", 3, 20)
        self.room_2 = Room("Studio 24", 5, 30)

        self.guest_1 = Guest("Pierre", 50, "Gotta Go")
        self.guest_2 = Guest("Alexander", 40, "On My Radio")
        self.guest_3 = Guest("Pepe", 30, "Divorce a I'ltalienne")
        self.guest_4 = Guest("Edi", 5, "Gotta Go")

        self.book = Book("For taxation purposes")
        self.hiden_book = Book("Real income")
def test_exercise():
    book = Book("J.R.R. Tolkein", "Lord of the Rings", "1000")

    assert book.get_author() == "J.R.R. Tolkein"
    assert book.get_name() == "Lord of the Rings"
    assert book.get_pages() == "1000"
    assert str(book) == "J.R.R. Tolkein, Lord of the Rings, 1000 pages"
    def test_addBookWithSameTitle_RaiseException(self):

        title = "Python to ML"

        book1 = Book(title, self.abstract, self.summary,
                     self.num_pages, self.isbn, self.author,
                     self.category, self.edition, self.price)

        book2 = Book(title, self.abstract, self.summary,
                     self.num_pages, self.isbn, self.author,
                     self.category, self.edition, self.price)

        collection = CollectionBooks()
        collection.add(book1)

        self.assertRaises(Exception, collection.add, book2)
Beispiel #7
0
 def check_for_books(self):
     '''check the current hand for any possible books'''
     #a dictionary of books
     possible_books = dict()
     #while the player still has cards
     while len(self.hand) > 0:
         #remove one from the top
         card = self.hand.pop()
         try:
             #check if the card's value already has a book
             #in the dict
             book = possible_books[card.value]
             #if that worked, we can add the card
             book.add(card)
         except KeyError:
             #if the dict didn't have a matching index
             #create a new book
             new_book = Book()
             #add the card to it
             new_book.add(card)
             #set the new book to the card's value in the dict
             possible_books[card.value] = new_book
     #create a list of the completed books
     complete_books = filter(lambda book: book.is_complete(),\
     list(possible_books.values()))
     #add any new books to the player's books
     self.books.extend(complete_books)
     #create a lit of the incomplete books
     incomplete_books = filter(lambda book: not book.is_complete(), \
     list(possible_books.values()))
     #add each of the book's cards back to the player's hand
     for book in incomplete_books:
         self.hand.extend(book.cards)
     #sort the player's hand smallest to largest
     self.hand.sort(key=lambda card: card.value)
Beispiel #8
0
    def setUp(self) -> None:
        self.price = 20.00
        self.title = "Python to ML"
        self.book1 = Book(self.title, "*" * 500,
                          "introduction to python to ML", 50,
                          "978–85–33302-27–3", "Guilherme Silveira",
                          "Data Science", 11, self.price)

        self.collection = CollectionBooks()
        self.collection.add(self.book1)
Beispiel #9
0
    def test_input_parser(self):
        ip = InputParser()
        for line in self.input_str.split("\n"):
            ip.parse_line(line)

        st = ip.get_state()
        trans = [[0, 2, 3], [3, 0, 4], [3, 4, 0]]
        books = [
            Book(0, 5, 0),
            Book(1, 3, 0),
            Book(2, 10, 1),
            Book(3, 2, 2),
            Book(4, 8, 2),
        ]
        readers = [
            Reader({
                0: 10,
                1: 2
            }, 0, 32),
            Reader({
                1: 1,
                2: 10,
                3: 3
            }, 0, 32),
            Reader({
                0: 1,
                1: 1,
                2: 1,
                3: 1,
                4: 1
            }, 1, 32),
            Reader({
                2: 5,
                4: 5
            }, 2, 32),
        ]
        expected = State(trans, books, readers)
        self.assertEqual(trans, st._transition)
        self.assertEqual(books, st._books)
        self.assertEqual(readers, st._readers)
        self.assertEqual(0, st._score)
        self.assertEqual(expected, st)
    def test_searchBookByTitle_return_MatchedBooks(self):
        title1 = "Python to ML"
        title2 = "Python to DS"
        text_search = "Py"

        book1 = Book(title1, self.abstract, self.summary,
                     self.num_pages, self.isbn, self.author,
                     self.category, self.edition, self.price)

        book2 = Book(title2, self.abstract, self.summary,
                     self.num_pages, self.isbn, self.author,
                     self.category, self.edition, self.price)

        collection = CollectionBooks()
        collection.add(book1)
        collection.add(book2)

        results = collection.search(text_search)

        self.assertEqual(2, len(results))
Beispiel #11
0
def create_new_book():
    if request.method == 'GET':
        return render_template('new_book.html')
    else:
        book_name = request.form['book_name']
        user = User.get_by_email(session['email'])

        new_book = Book(user.email, book_name, user._id)
        new_book.save_to_mongo()

        return make_response(user_books(user._id))
    def test_searchBookWithTitleShorterThan2chars_raiseException(self):
        title = "Python to ML"
        text_search = "P"

        book = Book(title, self.abstract, self.summary,
                    self.num_pages, self.isbn, self.author,
                    self.category, self.edition, self.price)

        collection = CollectionBooks()
        collection.add(book)

        self.assertRaises(Exception, collection.search, text_search)
    def test_searchBookByTitle_return_BooksInfo(self):
        title = "Python to ML"
        text_search = "Py"

        book = Book(title, self.abstract, self.summary,
                    self.num_pages, self.isbn, self.author,
                    self.category, self.edition, self.price)

        collection = CollectionBooks()
        collection.add(book)

        results = collection.search(text_search)
        first_result = results[0]

        self.assertEqual(first_result.title, title)
def main():
    bookList = []
    while (True):
        bookTitle = input("Title: ")
        bookPages = int(input("Pages: "))
        bookPubYear = int(input("Publication year: "))
        if not bookTitle:
            break
        bookList.append(Book(bookTitle, bookPages, bookPubYear))
    whatToPrint = input("What information will be printed?")
    for book in bookList:
        if (whatToPrint == "everything"):
            print(book)
        elif (whatToPrint == "name"):
            print(book.name)
Beispiel #15
0
    def create_book(command, counter):
        Path.reset_path()

        Debug.logger.info(u"开始制作第 {} 本电子书".format(counter))
        Debug.logger.info(u"对记录 {} 进行分析".format(command))
        task_package = ReadListParser.get_task(command)  # 分析命令

        if not task_package.is_work_list_empty():
            worker_factory(task_package.work_list)  # 执行抓取程序
            Debug.logger.info(u"网页信息抓取完毕")

        if not task_package.is_book_list_empty():
            Debug.logger.info(u"开始从数据库中生成电子书")
            book = Book(task_package.book_list)
            book.create()
        return
Beispiel #16
0
 def new_book(self, book_name):
     book = Book(author=self.email, book_name=book_name, author_id=self._id)
     book.save_to_mongo()
Beispiel #17
0
from src.book import Book

b1 = Book('Java How to Program', 'Deitel & Deitel', '2007', 1)
b2 = Book('Patterns of Enterprise Application Architecture', 'Martin Fowler',
          '2002', 2)
b3 = Book('Head First Design Patterns', 'Elisabeth Freeman', '2004', 3)
b4 = Book('Internet & World Wide Web: How to Program', 'Deitel & Deitel',
          '2007', 4)
 def test_createBookWithFreePrice_return_Book(self):
     price = 0
     book1 = Book(self.title, self.abstract, self.summary, self.num_pages,
                  self.isbn, self.author, self.category, self.edition,
                  price)
     self.assertIsNotNone(book1)
Beispiel #19
0
import os
import sys

from src.book import Book


if __name__ == "__main__":
    url = sys.argv[1]
    book = Book(url)
    print(f"Scraping `{book.meta['title']}` by `{book.meta['author']}`...")
    book.store()
    print("Creating epub with pandoc...")
    os.system(f"cd {book.directory} && pandoc --toc -o {book.meta['title'].replace(' ', '_')}.epub metadata.txt content.html +RTS -Ksize -RTS")
    print(f"Finished. Find your book at `{book.directory}`.")
Beispiel #20
0
 def test_create(self):
     """
     Test creates, which is a util to parse
     """
     book = create_book(self.line.split(" ")[1:])
     self.assertEqual(Book(0, 0, 5), book)
Beispiel #21
0
 def setUp(self):
     self.book = Book(1, 3, 0)
     self.book2 = Book(0, 3, 1)
Beispiel #22
0
 def setUp(self):
     self.book = Book(1, 0, 3)
     self.book2 = Book(0, 1, 3)