-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest_cases.py
More file actions
96 lines (83 loc) · 4.37 KB
/
Test_cases.py
File metadata and controls
96 lines (83 loc) · 4.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import unittest
from Library_management import Library_Management, Book
class TestLibrary(unittest.TestCase):
def test_add_books(self):
"""
Test that it can add books to the system with auto-generated ISBN.
"""
library = Library_Management()
# Add a book to the library
library.add_book("The Great Gatsby", "F. Scott Fitzgerald", 1925)
# Check if the book was added successfully
added_book = library.books_df.iloc[0]
self.assertEqual(added_book["Title"], "The Great Gatsby")
self.assertEqual(added_book["Author"], "F. Scott Fitzgerald")
self.assertEqual(added_book["Publication Year"], 1925)
library.add_book("To Kill a Mockingbird", "Harper Lee", 1960)
added_book = library.books_df.iloc[1]
self.assertEqual(added_book["Title"], "To Kill a Mockingbird")
self.assertEqual(added_book["Author"], "Harper Lee")
self.assertEqual(added_book["Publication Year"], 1960)
def test_borrow_book(self):
"""
Test that it can borrow a book from the library if it's available
"""
library = Library_Management()
library.add_book("The Great Gatsby", "F. Scott Fitzgerald", 1925)
library.add_book("To Kill a Mockingbird", "Harper Lee", 1960)
# Borrow the first book (ISBN should be 1)
library.borrow_book("The Great Gatsby",1)
def test_borrow_book_not_available(self):
"""
Test that attempting to borrow a book that is already borrowed raises an error.
"""
library = Library_Management()
library.add_book("The Great Gatsby", "F. Scott Fitzgerald", 1925)
library.borrow_book("The Great Gatsby", 1)
library.borrow_book("The Great Gatsby",1)
def test_borrow_book_not_present(self):
''' Test that attempts to borrow a book which is not available in the library'''
library = Library_Management()
library.add_book("The Twilight Saga", "Stephenie Meyer", 2005)
library.borrow_book("New Moon", 3)
def test_return_book(self):
'''Test that attempts to return the borrowed book'''
library = Library_Management()
library.add_book("The Great Gatsby", "F. Scott Fitzgerald", 1925)
library.add_book("The Twilight Saga", "Stephenie Meyer", 2005)
library.add_book("The Great Gatsby", "F. Scott Fitzgerald", 1925)
# Borrow the book
library.borrow_book("The Great Gatsby", 3)
library.return_book("The Great Gatsby", 3)
# Check if the book is marked as not borrowed
# book_status = library.books_df[library.books_df['ISBN'] == 3].iloc[0]['Is Borrowed']
# self.assertFalse(book_status, "The book was not marked as returned.")
def test_return_book_not_borrowed(self):
'''Test attempts to return a book which was not borrowed'''
library = Library_Management()
library.add_book("The Great Gatsby", "F. Scott Fitzgerald", 1925)
library.add_book("The Twilight Saga", "Stephenie Meyer", 2005)
library.add_book("The Great Gatsby", "F. Scott Fitzgerald", 1925)
# Borrow the book
library.borrow_book("The Twilight Saga", 2)
library.return_book("The Great Gatsby", 3)
def test_return_book_not_present(self):
'''Test attempts to return a book which is not even added in the library'''
library = Library_Management()
library.add_book("The Great Gatsby", "F. Scott Fitzgerald", 1925)
library.add_book("The Twilight Saga", "Stephenie Meyer", 2005)
library.add_book("The Great Gatsby", "F. Scott Fitzgerald", 1925)
library.return_book("New Moon", 4)
def test_view_available_books(self):
'''Test attempts to return all the books which are available in the library'''
library = Library_Management()
library.add_book("The Great Gatsby", "F. Scott Fitzgerald", 1925)
library.add_book("The Twilight Saga", "Stephenie Meyer", 2005)
library.add_book("To Kill a Mockingbird", "Harper Lee", 1960)
library.add_book("The Great Gatsby", "F. Scott Fitzgerald", 1925)
library.borrow_book("The Great Gatsby",4)
library.borrow_book("The Twilight Saga",2)
library.return_book("The Great Gatsby",4)
library.view_available_books()
if __name__ == '__main__':
unittest.main()