|
344 | 344 | @test pyfmt(".1e", 0.0006) == "6.0e-04" |
345 | 345 | end |
346 | 346 |
|
| 347 | +# This testset is currently non-compliant to Python's format_spec |
| 348 | +# Trailing insignificant zeros should be removed, however it is not done in |
| 349 | +# the current implementation. |
| 350 | +# FIXME: Make g/G compliant with Python's behavior |
| 351 | +@testset "Format general (g/G)" begin |
| 352 | + # Default precision (6 significant digits) |
| 353 | + @test pyfmt("g", 123.456789) == "123.457" |
| 354 | + @test pyfmt("g", 1.234567e-5) == "1.23457e-05" |
| 355 | + |
| 356 | + # Switch between fixed and scientific depending on precision |
| 357 | + # and exponent -> Issue #91 (Format.jl) |
| 358 | + @test pyfmt(".3g", 0.0012345) == "0.00123" |
| 359 | + @test pyfmt(".3g", 1234567.0) == "1.23e+06" |
| 360 | + @test pyfmt(".2g", 0.000012345) == "1.2e-05" |
| 361 | + @test pyfmt(".2g", 1e-4) == "0.00010" |
| 362 | + @test pyfmt("g", 1e5) == "100000" |
| 363 | + @test pyfmt("g", 1e6) == "1.00000e+06" |
| 364 | + |
| 365 | + # Trailing zero and decimal point trimming |
| 366 | + @test pyfmt(".6g", 1200.0) == "1200.00" |
| 367 | + @test pyfmt(".4g", 12.0) == "12.00" |
| 368 | + |
| 369 | + # Alternate form '#' keeps trailing zeros and decimal point |
| 370 | + @test pyfmt("#.4g", 12.0) == "12.00" |
| 371 | + @test pyfmt("#.3g", 1.0e-5) == "1.00e-05" |
| 372 | + |
| 373 | + # Width, alignment, and zero-padding |
| 374 | + @test pyfmt(">8.3g", 13.89) == " 13.9" |
| 375 | + @test pyfmt("⋆<8.3g", 13.89) == "13.9⋆⋆⋆⋆" |
| 376 | + @test pyfmt("⋆^8.3g", 13.89) == "⋆⋆13.9⋆⋆" |
| 377 | + @test pyfmt("010.3g", 13.89) == "00000013.9" |
| 378 | + @test pyfmt("010.3g", -13.89) == "-0000013.9" |
| 379 | + @test pyfmt("+010.3g", 13.89) == "+0000013.9" |
| 380 | + |
| 381 | + # Rounding across powers of ten |
| 382 | + @test_broken pyfmt(".3g", 9.999) == "10.0" |
| 383 | + @test pyfmt(".3g", 9.999e9) == "1.00e+10" |
| 384 | + @test pyfmt(".3g", -9.999e-5) == "-1.00e-04" |
| 385 | + @test pyfmt(".3g", -9.999e-6) == "-1.00e-05" |
| 386 | + |
| 387 | + # 'G' behaves like 'g' but uses 'E' |
| 388 | + @test pyfmt(".3G", 1234567.0) == "1.23E+06" |
| 389 | + @test pyfmt(".3G", 0.000012345) == "1.23E-05" |
| 390 | + @test pyfmt("G", 12.0) == "12.0000" |
| 391 | + @test pyfmt("#.4G", 12.0) == "12.00" |
| 392 | + @test pyfmt("G", 1e6) == "1.00000E+06" |
| 393 | + |
| 394 | + # Zeros, from regression of (04baaf3) |
| 395 | + @test pyfmt("g", 0.0) == "0.00000" |
| 396 | + @test pyfmt("g", -0.0) == "-0.00000" |
| 397 | +end |
| 398 | + |
347 | 399 | @testset "Format percentage (%)" begin |
348 | 400 | @test pyfmt("8.2%", 0.123456) == " 12.35%" |
349 | 401 | @test pyfmt("<8.2%", 0.123456) == "12.35% " |
|
0 commit comments