Skip to content

Commit ac9318a

Browse files
committed
Right-align values in table
1 parent 20ac032 commit ac9318a

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

lib/results_table_builder.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,8 @@ def build_rss_ratio_columns(row, base_rss, other_rsss)
150150
def format_ratio(ratio, pval)
151151
sym = significance_symbol(pval)
152152
formatted = "%.3f" % ratio
153-
sym.empty? ? formatted : "#{formatted} (#{sym})"
153+
suffix = sym.empty? ? "" : " (#{sym})"
154+
(formatted + suffix).ljust(formatted.length + 6)
154155
end
155156

156157
def format_p_value(pval)

lib/table_formatter.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,9 @@ def build_separator(col_widths)
7070
end
7171

7272
def format_row(row, col_widths)
73-
row.map.with_index { |cell, i| cell.ljust(col_widths[i]) }
74-
.join(COLUMN_SEPARATOR)
75-
.rstrip
73+
row.map.with_index { |cell, i|
74+
i == 0 ? cell.ljust(col_widths[i]) : cell.rjust(col_widths[i])
75+
}.join(COLUMN_SEPARATOR)
76+
.rstrip
7677
end
7778
end

test/table_formatter_test.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
assert_equal <<~TABLE, result
1818
----- --------- ----------
1919
bench time (ms) stddev (%)
20-
fib 100.5 2.3
21-
loop 50.2 1.1
20+
fib 100.5 2.3
21+
loop 50.2 1.1
2222
----- --------- ----------
2323
TABLE
2424
end
@@ -36,8 +36,8 @@
3636
assert_equal <<~TABLE, result
3737
------------ ---------
3838
bench time (ms)
39-
broken_bench N/A
40-
fib 100.5
39+
broken_bench N/A
40+
fib 100.5
4141
------------ ---------
4242
TABLE
4343
end

0 commit comments

Comments
 (0)