def test_filter_books(self): slash_book = slash_to_book(["1993", "Steve", "McConnell", "Code Complete"]) csv_book = csv_to_book(["Clean Code", "Martin", "Robert", "2008"]) self.assertEquals(filter_books([slash_book, csv_book], "20"), [csv_book]) self.assertEquals(filter_books([slash_book, csv_book], "ode"), [slash_book, csv_book]) self.assertEquals(filter_books([slash_book, csv_book], None), [slash_book, csv_book])
def test_sort_books(self): slash_book = slash_to_book(["1993", "Steve", "McConnell", "Code Complete"]) csv_book = csv_to_book(["Clean Code", "Martin", "Robert", "2008"]) kent_book_1 = pipe_to_book(["Kent", "Beck", "Test-Driven Development", "2002"]) kent_book_2 = pipe_to_book(["Kent", "Beck", "Implementation Patterns", "2007"]) books = [slash_book, kent_book_1, kent_book_2, csv_book] random.shuffle(books) self.assertEquals(sort_books(books), [kent_book_2, kent_book_1, csv_book, slash_book]) self.assertEquals(sort_books(books, True), [slash_book, kent_book_1, kent_book_2,csv_book]) self.assertEquals(sort_books(books, True, True), [csv_book, kent_book_2, kent_book_1, slash_book])
def test_book_repr(self): slash_book = slash_to_book(["2002", "Martin", "Fowler", "Patterns of Enterprise Application Architecture"]) self.assertEquals(str(slash_book), "Fowler, Martin, Patterns of Enterprise Application Architecture, 2002")
def test_slash_conversion(self): slash_book = slash_to_book(["1993", "Steve", "McConnell", "Code Complete"]) self._assert_book_conversion(slash_book, ["Steve", "McConnell", "Code Complete", "1993"])