Test the _format_number method.
()
| 52 | |
| 53 | |
| 54 | def test_format_number(): |
| 55 | """Test the _format_number method.""" |
| 56 | logger = ScreenLogger() |
| 57 | |
| 58 | # Test integer formatting |
| 59 | assert len(logger._format_number(42)) == logger._default_cell_size |
| 60 | |
| 61 | # Test float formatting with precision |
| 62 | float_str = logger._format_number(3.14159) |
| 63 | assert len(float_str) == logger._default_cell_size |
| 64 | assert "3.14" in float_str # default precision is 4 |
| 65 | |
| 66 | # Test long integer truncation |
| 67 | long_int = 12345678901234 |
| 68 | formatted = logger._format_number(long_int) |
| 69 | assert len(formatted) == logger._default_cell_size |
| 70 | assert formatted == "1.234e+13" |
| 71 | |
| 72 | # Test long float truncation |
| 73 | long_float = 1234.5678901234 |
| 74 | formatted = logger._format_number(long_float) |
| 75 | assert len(formatted) == logger._default_cell_size |
| 76 | assert formatted == "1234.5678" |
| 77 | |
| 78 | # Test negative long float truncation |
| 79 | long_float = -1234.5678901234 |
| 80 | formatted = logger._format_number(long_float) |
| 81 | assert len(formatted) == logger._default_cell_size |
| 82 | assert formatted == "-1234.567" |
| 83 | |
| 84 | # Test scientific notation truncation |
| 85 | sci_float = 12345678901234.5678901234 |
| 86 | formatted = logger._format_number(sci_float) |
| 87 | assert len(formatted) == logger._default_cell_size |
| 88 | assert formatted == "1.234e+13" |
| 89 | |
| 90 | sci_float = 1.11111111e-5 |
| 91 | formatted = logger._format_number(sci_float) |
| 92 | assert formatted == "1.111e-05" |
| 93 | |
| 94 | sci_float_neg = -1.11111111e-5 |
| 95 | formatted = logger._format_number(sci_float_neg) |
| 96 | assert formatted == "-1.11e-05" |
| 97 | |
| 98 | sci_float = -12345678901234.5678901234 |
| 99 | formatted = logger._format_number(sci_float) |
| 100 | assert len(formatted) == logger._default_cell_size |
| 101 | assert formatted == "-1.23e+13" |
| 102 | |
| 103 | # Test long scientific notation truncation |
| 104 | sci_float = -12345678901234.534e132 |
| 105 | formatted = logger._format_number(sci_float) |
| 106 | assert len(formatted) == logger._default_cell_size |
| 107 | assert formatted == "-1.2e+145" |
| 108 | |
| 109 | |
| 110 | def test_format_bool(): |
nothing calls this directly
no test coverage detected