@@ -144,7 +144,7 @@ def test_fractional(test_input: float | str, expected: str) -> None:
144144 "test_args, expected" ,
145145 [
146146 ([1000 ], "1.00 x 10³" ),
147- ([- 1000 ], "1.00 x 10⁻ ³" ),
147+ ([- 1000 ], "- 1.00 x 10³" ),
148148 ([5.5 ], "5.50 x 10⁰" ),
149149 ([5781651000 ], "5.78 x 10⁹" ),
150150 (["1000" ], "1.00 x 10³" ),
@@ -156,6 +156,10 @@ def test_fractional(test_input: float | str, expected: str) -> None:
156156 ([float (0.3 ), 1 ], "3.0 x 10⁻¹" ),
157157 ([1000 , 0 ], "1 x 10³" ),
158158 ([float (0.3 ), 0 ], "3 x 10⁻¹" ),
159+ ([float (1e20 )], "1.00 x 10²⁰" ),
160+ ([float (2e-20 )], "2.00 x 10⁻²⁰" ),
161+ ([float (- 3e20 )], "-3.00 x 10²⁰" ),
162+ ([float (- 4e-20 )], "-4.00 x 10⁻²⁰" ),
159163 ],
160164)
161165def test_scientific (test_args : list [typing .Any ], expected : str ) -> None :
@@ -177,3 +181,40 @@ def test_scientific(test_args: list[typing.Any], expected: str) -> None:
177181)
178182def test_clamp (test_args : list [typing .Any ], expected : str ) -> None :
179183 assert humanize .clamp (* test_args ) == expected
184+
185+
186+ @pytest .mark .parametrize (
187+ "test_args, expected" ,
188+ [
189+ ([1 , "Hz" ], "1.00 Hz" ),
190+ ([1.0 , "W" ], "1.00 W" ),
191+ ([3 , "C" ], "3.00 C" ),
192+ ([3 , "W" , 5 ], "3.0000 W" ),
193+ ([1.23456 ], "1.23" ),
194+ ([12.3456 ], "12.3" ),
195+ ([123.456 ], "123" ),
196+ ([1234.56 ], "1.23 k" ),
197+ ([12345 , "" , 6 ], "12.3450 k" ),
198+ ([200_000 ], "200 k" ),
199+ ([1e25 , "m" ], "10.0 Ym" ),
200+ ([1e26 , "m" ], "100 Ym" ),
201+ ([1e27 , "A" ], "1.00 x 10²⁷A" ),
202+ ([1.234e28 , "A" ], "1.23 x 10²⁸A" ),
203+ ([- 1500 , "V" ], "-1.50 kV" ),
204+ ([0.12 ], "120 m" ),
205+ ([0.012 ], "12.0 m" ),
206+ ([0.0012 ], "1.20 m" ),
207+ ([0.00012 ], "120 μ" ),
208+ ([1e-23 ], "10.0 y" ),
209+ ([1e-24 ], "1.00 y" ),
210+ ([1e-25 ], "1.00 x 10⁻²⁵" ),
211+ ([1e-26 ], "1.00 x 10⁻²⁶" ),
212+ ([1 , "°" ], "1.00°" ),
213+ ([0.1 , "°" ], "100m°" ),
214+ ([100 ], "100" ),
215+ ([0.1 ], "100 m" ),
216+ ],
217+ ids = str ,
218+ )
219+ def test_metric (test_args : list [typing .Any ], expected : str ) -> None :
220+ assert humanize .metric (* test_args ) == expected
0 commit comments