From c6cedf3c404e71dfb460468f04f7fa5f806f3b5d Mon Sep 17 00:00:00 2001 From: Darafei Praliaskouski Date: Fri, 8 May 2026 18:52:22 +0400 Subject: [PATCH] feat(output): show loss with two decimals --- test/cmdparse.py | 16 ++++++++++++++++ ui/gtk.c | 2 +- ui/mtr.c | 2 +- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/test/cmdparse.py b/test/cmdparse.py index 4f5d64c..f344eaf 100755 --- a/test/cmdparse.py +++ b/test/cmdparse.py @@ -81,6 +81,22 @@ class TestMtrCommandParse(unittest.TestCase): self.assertIn('port number specified (-P)', reply.stderr) self.assertIn('protocol is ICMP', reply.stderr) + def test_report_loss_uses_two_decimal_places(self): + 'Test report mode preserves fine-grained loss percentage precision.' + + reply = self.run_mtr( + '--report', + '--report-cycles', + '1', + '--no-dns', + '127.0.0.1', + ) + + self.assertEqual(reply.returncode, 0) + self.assertEqual(reply.stderr, '') + self.assertIn('Loss%', reply.stdout) + self.assertIn('0.00%', reply.stdout) + def test_port_with_tcp_succeeds_flag(self): 'Test that specifying -P with -T (TCP) succeeds.' diff --git a/ui/gtk.c b/ui/gtk.c index a997a33..d1315fe 100644 --- a/ui/gtk.c +++ b/ui/gtk.c @@ -373,7 +373,7 @@ static void percent_formatter( gfloat f; gchar text[64]; gtk_tree_model_get(tree_model, iter, POINTER_TO_INT(data), &f, -1); - snprintf(text, sizeof(text), "%.1f%%", f); + snprintf(text, sizeof(text), "%.2f%%", f); g_object_set(cell, "text", text, NULL); } diff --git a/ui/mtr.c b/ui/mtr.c index f3be331..98977f6 100644 --- a/ui/mtr.c +++ b/ui/mtr.c @@ -69,7 +69,7 @@ char *myname; const struct fields data_fields[MAXFLD] = { /* key, Remark, Header, Format, Width, CallBackFunc */ {' ', ": Space between fields", " ", " ", 1, &net_drop}, - {'L', "L: Loss Ratio", "Loss%", " %4.1f%%", 6, &net_loss}, + {'L', "L: Loss Ratio", "Loss%", " %6.2f%%", 8, &net_loss}, {'D', "D: Dropped Packets", "Drop", " %4d", 5, &net_drop}, {'R', "R: Received Packets", "Rcv", " %5d", 6, &net_returned}, {'S', "S: Sent Packets", "Snt", " %5d", 6, &net_xmit}, -- 2.47.3