1+ import pytest
12from ..exercises .exercise_68 import Vector3D
2- from ..exercises .exercise_69 import Calculator
3+ from ..exercises .exercise_69 import TaxCalculator
34from ..exercises .exercise_70 import Circle , Shape , Square
45from ..exercises .exercise_71 import Author , Book , Genre
56from ..exercises .exercise_72 import BookShelf
67from ..exercises .exercise_73 import Library
7- from ..exercises .exercise_74 import Account , Card
8- from ..exercises .exercise_75 import Customer
8+ from ..exercises .exercise_74 import Account , Card , Customer
9+ from ..exercises .exercise_75 import BankCustomer
910from ..exercises .exercise_76 import Box
11+ from ..exercises .exercise_77 import create_content , Blogger , Vlogger
1012
11- # from ..exercises.exercise_77 import
1213# from ..exercises.exercise_78 import
1314
1415
@@ -28,10 +29,14 @@ def test_e68():
2829
2930
3031def test_e69 ():
31- assert Calculator .add (0 , 0 ) == 0
32- assert Calculator .add (1 , 2 ) == 3
33- assert Calculator .subtract (0 , 0 ) == 0
34- assert Calculator .subtract (1 , 2 ) == - 1
32+ tax_calculator = TaxCalculator ()
33+ assert tax_calculator .calculate_tax (0 ) == 0
34+ assert tax_calculator .calculate_tax (10_000 ) == 0
35+ assert tax_calculator .calculate_tax (10_001 ) == 1000.1
36+ assert tax_calculator .calculate_tax (50_000 ) == 5000
37+ assert tax_calculator .calculate_tax (50_001 ) == 10_000.2
38+ assert tax_calculator .calculate_tax (100_000 ) == 20_000
39+ assert tax_calculator .calculate_tax (150_000 ) == 45_000
3540
3641
3742def test_e70 ():
@@ -59,20 +64,23 @@ def test_e72():
5964 book = Book ("The Book" , author , 2024 , Genre .Fiction )
6065
6166 shelf = BookShelf ()
62- shelf .add_book (book )
6367 assert shelf .get_books () == []
64- assert shelf .get_books_by_genre ( Genre . Fiction ) == []
68+ shelf .add_book ( book )
6569 assert shelf .get_books () == [book ]
70+ assert shelf .get_books_by_genre (Genre .History ) == []
71+ assert shelf .get_books_by_genre (Genre .NonFiction ) == []
6672 assert shelf .get_books_by_genre (Genre .Fiction ) == [book ]
6773
6874 shelf .remove_book (book )
6975 assert shelf .get_books () == []
7076 assert shelf .get_books_by_genre (Genre .Fiction ) == []
71- shelf .add_book (Book ("Biography Book" , author , 2024 , Genre .Biography ))
72- shelf .add_book (Book ("History Book" , author , 2024 , Genre .History ))
77+ book2 = Book ("Biography Book" , author , 2024 , Genre .Biography )
78+ book3 = Book ("History Book" , author , 2024 , Genre .History )
79+ shelf .add_book (book2 )
80+ shelf .add_book (book3 )
7381 assert shelf .get_books_by_genre (Genre .Fiction ) == []
74- assert shelf .get_books_by_genre (Genre .Biography ) == [book ]
75- assert shelf .get_books_by_genre (Genre .History ) == [book ]
82+ assert shelf .get_books_by_genre (Genre .Biography ) == [book2 ]
83+ assert shelf .get_books_by_genre (Genre .History ) == [book3 ]
7684
7785
7886def test_e73 ():
@@ -93,7 +101,8 @@ def test_e73():
93101 assert library .get_books () == []
94102 library .add_shelf (shelfA )
95103 library .add_shelf (shelfB )
96- assert library .get_books () == shelf_A_books + shelf_B_books
104+ assert set (library .get_books ()) == set (shelf_A_books + shelf_B_books )
105+
97106 assert library .is_book_in_library (shelf_A_books [0 ]) is True
98107 assert (
99108 library .is_book_in_library (
@@ -102,25 +111,48 @@ def test_e73():
102111 is False
103112 )
104113 library .remove_shelf (shelfA )
105- assert library .get_books () == shelf_B_books
114+ assert set ( library .get_books ()) == set ( shelf_B_books )
106115
107116
108117def test_e74 ():
109- # TODO
110- card = Card ("1234" , "User A" , "2024-12-31" , "1234" )
118+ customer = Customer ("John" , "Doe" )
119+ card = Card (
120+ card_number = "1234" ,
121+ customer = customer ,
122+ expiry_date = "2024-12-31" ,
123+ pin = "1234" ,
124+ )
111125 assert isinstance (card , Card )
112- account = Account ("1234" , "User A" , 1000 , [card ])
126+ account = Account ("1234" , customer , 1000 , [card ])
113127 assert isinstance (account , Account )
128+ assert account .account_number == "1234"
114129
115130
116- # TODO
117131def test_e75 ():
118- customer = Customer ("John" , "Doe" )
119- assert isinstance (customer , Customer )
120- assert customer .add_account (Account ("1234" , "User A" , 1000 , [])) is None
121- assert customer .add_card (Card ("1234" , "User A" , "2024-12-31" , "1234" )) is None
132+ customer = BankCustomer ("John" , "Doe" )
133+ card1 = Card ("1234" , customer , "2024-12-31" , "1234" )
134+ card2 = Card ("5678" , customer , "2024-12-31" , "5678" )
135+ account1 = Account ("acc-1234" , customer , 1000 , [card1 ])
136+ account2 = Account ("acc-5678" , customer , 2000 , [card2 ])
137+
138+ assert customer .get_total_balance () == 0.0
139+ customer .add_account (account1 )
122140 assert customer .get_total_balance () == 1000
123- assert customer .withdraw (1234 , 500 , 1234 , 1234 ) is None
141+ customer .add_account (account2 )
142+ assert customer .get_total_balance () == 3000
143+ assert customer .get_card ("1234" ) == card1
144+ assert customer .get_card ("5678" ) == card2
145+ assert customer .get_account ("acc-1234" ) == account1
146+ assert customer .get_account ("acc-5678" ) == account2
147+
148+ assert customer .deposit ("acc-1234" , 500 ) is None
149+ assert customer .get_account ("acc-1234" ).balance == 1500
150+ assert customer .get_total_balance () == 3500
151+
152+ with pytest .raises (ValueError ):
153+ customer .withdraw ("acc-1234" , 1_000_000 , "1234" , "1234" )
154+ with pytest .raises (ValueError ):
155+ customer .withdraw ("acc-1234" , 1_000 , "1234" , "WRONG_PIN" )
124156
125157
126158def test_e76 ():
@@ -137,3 +169,8 @@ def test_e76():
137169 box3 .add ("Hello" )
138170 assert isinstance (box3 .get (), str )
139171 assert box3 .get () == "Hello"
172+
173+
174+ def test_e77 ():
175+ assert create_content (Blogger ()) == "Blogger is creating content"
176+ assert create_content (Vlogger ()) == "Vlogger is creating content"
0 commit comments