66
77
88def test_btc_name ():
9- assert BTC . _name == "Bitcoin"
9+ assert BTC ( 0 ). name == "Bitcoin"
1010
1111
12- def test_btc_symbol ():
13- assert BTC ._symbol == "BTC"
12+ def test_btc_code ():
13+ assert BTC (0 ).code == "BTC"
14+
15+
16+ def test_btc_new_instance ():
17+ assert BTC ("1.5" ) == BTC (1.5 )
18+ assert BTC ("1" ) == BTC (1 )
19+ assert BTC ("1.5" ) == BTC (Decimal ("1.5" ))
1420
1521
1622def test_btc_precision ():
@@ -27,7 +33,7 @@ def test_btc_str():
2733
2834
2935def test_btc_repr ():
30- assert repr (BTC ("1.5" )) == "BTC(1.50000000 BTC )"
36+ assert repr (BTC ("1.5" )) == "BTC(1.50000000)"
3137
3238
3339def test_btc_hash ():
@@ -62,7 +68,8 @@ def test_btc_addition_with_float():
6268
6369
6470def test_btc_addition_with_str ():
65- assert BTC ("0.5" ) + "0.5" == BTC ("1.0" )
71+ with pytest .raises (TypeError ):
72+ assert BTC ("0.5" ) + "0.5"
6673
6774
6875def test_btc_reverse_addition_with_int ():
@@ -85,8 +92,9 @@ def test_btc_subtraction_with_float():
8592 assert BTC ("1.5" ) - 0.5 == BTC ("1.0" )
8693
8794
88- def test_btc_subtraction_with_str ():
89- assert BTC ("1.5" ) - "0.5" == BTC ("1.0" )
95+ def test_btc_subtraction_with_str_raises ():
96+ with pytest .raises (TypeError ):
97+ BTC ("1.5" ) - "0.5"
9098
9199
92100def test_btc_reverse_subtraction_with_int ():
@@ -105,8 +113,9 @@ def test_btc_multiplication_with_float():
105113 assert BTC ("1" ) * 2.0 == BTC ("2" )
106114
107115
108- def test_btc_multiplication_with_str ():
109- assert BTC ("1" ) * "2" == BTC ("2" )
116+ def test_btc_multiplication_with_str_raises ():
117+ with pytest .raises (TypeError ):
118+ assert BTC ("1" ) * "2"
110119
111120
112121def test_btc_reverse_multiplication_with_int ():
@@ -130,8 +139,9 @@ def test_btc_division_with_float():
130139 assert BTC ("2" ) / 2.0 == BTC ("1" )
131140
132141
133- def test_btc_division_with_str ():
134- assert BTC ("2" ) / "2" == BTC ("1" )
142+ def test_btc_division_with_str_raises ():
143+ with pytest .raises (TypeError ):
144+ assert BTC ("2" ) / "2"
135145
136146
137147def test_btc_reverse_division_with_int ():
@@ -159,8 +169,7 @@ def test_btc_equality_with_float():
159169
160170
161171def test_btc_equality_with_str ():
162- assert BTC ("1.5" ) == "1.5"
163- assert (BTC ("1.5" ) == "2.5" ) is False
172+ assert (BTC ("1.5" ) == "1.5" ) is False
164173
165174
166175def test_btc_equality_with_same_class ():
@@ -193,9 +202,9 @@ def test_btc_less_than_with_float():
193202 assert not BTC ("1" ) < 1.0
194203
195204
196- def test_btc_less_than_with_str ():
197- assert BTC ( "1" ) < "2"
198- assert not BTC ("1" ) < "1 "
205+ def test_btc_less_than_with_str_raises ():
206+ with pytest . raises ( TypeError ):
207+ assert BTC ("1" ) < "2 "
199208
200209
201210def test_btc_less_than_with_same_class ():
@@ -224,9 +233,9 @@ def test_btc_greater_than_with_float():
224233 assert not BTC ("1" ) > 1.0
225234
226235
227- def test_btc_greater_than_with_str ():
228- assert BTC ( "2" ) > "1"
229- assert not BTC ("1 " ) > "1"
236+ def test_btc_greater_than_with_str_raises ():
237+ with pytest . raises ( TypeError ):
238+ assert BTC ("2 " ) > "1"
230239
231240
232241def test_btc_greater_than_with_same_class ():
@@ -244,7 +253,6 @@ def test_btc_comparison_with_zero():
244253 assert BTC ("0" ) == 0
245254 assert BTC ("0" ) == Decimal ("0" )
246255 assert BTC ("0" ) == 0.0
247- assert BTC ("0" ) == "0"
248256 assert BTC ("0" ) == BTC ("0" )
249257 assert BTC ("1" ) > 0
250258 assert BTC ("-1" ) < 0
@@ -306,7 +314,6 @@ def test_btc_comparison_with_negative():
306314 assert BTC ("-1" ) == - 1
307315 assert BTC ("-1.5" ) == Decimal ("-1.5" )
308316 assert BTC ("-1.5" ) == - 1.5
309- assert BTC ("-1.5" ) == "-1.5"
310317 assert BTC ("-1.5" ) == BTC ("-1.5" )
311318 assert BTC ("-1" ) < 0
312319 assert BTC ("-1" ) < BTC ("0" )
0 commit comments