@@ -200,4 +200,74 @@ def test_factory_methods():
200200 assert Hbar .from_gigabars (1 ).to_hbars () == 1_000_000_000
201201 assert Hbar .from_gigabars (0 ).to_hbars () == 0
202202 assert Hbar .from_gigabars (- 1 ).to_hbars () == - 1_000_000_000
203- assert Hbar .from_gigabars (1 ).to_tinybars () == 100_000_000_000_000_000
203+ assert Hbar .from_gigabars (1 ).to_tinybars () == 100_000_000_000_000_000
204+
205+
206+ # NEW TESTS: Coverage improvements for issue #1447
207+ # ---------------------------------------------------------------------------
208+
209+ def test_from_tinybars_rejects_non_int ():
210+ """from_tinybars() should reject non-integer input."""
211+ with pytest .raises (TypeError , match = "tinybars must be an int" ):
212+ Hbar .from_tinybars (1.5 )
213+
214+ with pytest .raises (TypeError , match = "tinybars must be an int" ):
215+ Hbar .from_tinybars ("1000" )
216+
217+ with pytest .raises (TypeError , match = "tinybars must be an int" ):
218+ Hbar .from_tinybars (Decimal ("1000" ))
219+
220+
221+
222+ @pytest .mark .parametrize ("other" , [1 , 1.0 , "1" , None ])
223+ def test_comparison_with_non_hbar_raises_type_error (other ):
224+ """Ordering comparisons with non-Hbar types should raise TypeError."""
225+ h = Hbar (1 )
226+
227+ with pytest .raises (TypeError ):
228+ _ = h < other
229+
230+ with pytest .raises (TypeError ):
231+ _ = h > other
232+
233+ with pytest .raises (TypeError ):
234+ _ = h <= other
235+
236+ with pytest .raises (TypeError ):
237+ _ = h >= other
238+
239+
240+
241+ def test_str_formatting_and_negatives ():
242+ """String representation should use fixed 8 decimal places."""
243+ assert str (Hbar (1 )) == "1.00000000 ℏ"
244+ assert str (Hbar (- 1 )) == "-1.00000000 ℏ"
245+
246+
247+ def test_repr_contains_class_name_and_value ():
248+ """repr() should include class name and value."""
249+ h = Hbar (2 )
250+ r = repr (h )
251+
252+ assert r .startswith ("Hbar(" )
253+ assert "2" in r
254+
255+
256+
257+ def test_hash_consistency_for_equal_values ():
258+ """Equal Hbar values must have identical hashes."""
259+ h1 = Hbar (1 )
260+ h2 = Hbar (1 )
261+
262+ assert h1 == h2
263+ assert hash (h1 ) == hash (h2 )
264+
265+ values = {h1 , h2 }
266+ assert len (values ) == 1
267+
268+ d = {h1 : "value1" }
269+ d [h2 ] = "value2"
270+ assert len (d ) == 1
271+ assert d [h1 ] == "value2"
272+
273+
0 commit comments