From fe117be2b597a7fd95c35ea79f65278c21fe8ed2 Mon Sep 17 00:00:00 2001 From: June Kim Date: Sun, 10 May 2026 07:46:04 -0700 Subject: [PATCH 1/2] Format bar labels as integers when appropriate Fixes #44 When bar chart values have no fractional part (e.g., 3.0, 12.0), display them as integers (3, 12) instead of floats. This makes bar charts cleaner and more readable for integer data. The logic preserves fractional values when they exist (3.5 stays 3.5), only removing the `.0` suffix when the value is a whole number. This completes the integer formatting work started in da6351c, which fixed the count command. Now both `uplot bar` and `uplot count` display integer values cleanly. Implementation uses normalize_numeric_value helper that: - Returns non-finite values (NaN, Infinity) unchanged to prevent crashes - Converts floats to integers when num == num.to_i - Forces integer conversion for count mode --- lib/youplot/backends/unicode_plot.rb | 15 +++++--- test/fixtures/iris-barplot.txt | 56 ++++++++++++++-------------- 2 files changed, 37 insertions(+), 34 deletions(-) diff --git a/lib/youplot/backends/unicode_plot.rb b/lib/youplot/backends/unicode_plot.rb index 971deba..f600bc7 100644 --- a/lib/youplot/backends/unicode_plot.rb +++ b/lib/youplot/backends/unicode_plot.rb @@ -35,6 +35,13 @@ class Error < StandardError; end module_function + def normalize_numeric_value(value, force_integer = false) + num = value.to_f + return num unless num.finite? + return num.to_i if force_integer + num == num.to_i ? num.to_i : num + end + def barplot(data, params, fmt = nil, count: false, reverse: false) headers = data.headers series = data.series @@ -47,7 +54,7 @@ def barplot(data, params, fmt = nil, count: false, reverse: false) # If there is only one series.use the line number for label. params.title ||= headers[0] if headers labels = Array.new(series[0].size) { |i| (i + 1).to_s } - values = series[0].map(&:to_f) + values = series[0].map { |v| normalize_numeric_value(v, count) } else # If there are 2 or more series... if fmt == 'yx' @@ -61,11 +68,7 @@ def barplot(data, params, fmt = nil, count: false, reverse: false) end params.title ||= headers[y_col] if headers labels = series[x_col] - values = if count - series[y_col].map(&:to_i) - else - series[y_col].map(&:to_f) - end + values = series[y_col].map { |v| normalize_numeric_value(v, count) } end ::UnicodePlot.barplot(labels, values, **params.to_hc) end diff --git a/test/fixtures/iris-barplot.txt b/test/fixtures/iris-barplot.txt index 7f38cb8..0d6bfe4 100644 --- a/test/fixtures/iris-barplot.txt +++ b/test/fixtures/iris-barplot.txt @@ -1,7 +1,7 @@ IRIS-BARPLOT ┌ ┐ 5.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.5 - 4.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 4.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 4.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.2 4.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.1 5.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.6 @@ -12,9 +12,9 @@ 4.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.1 5.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.7 4.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.4 - 4.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 - 4.3 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 - 5.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 4.0 + 4.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 4.3 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 5.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 4 5.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 4.4 5.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.9 5.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.5 @@ -25,7 +25,7 @@ 4.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.6 5.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.3 4.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.4 - 5.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 5.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 5.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.4 5.2 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.5 5.2 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.4 @@ -38,14 +38,14 @@ 5.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.2 5.5 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.5 4.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.1 - 4.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 4.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 5.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.4 5.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.5 4.5 ┤■■■■■■■■■■■■■■■■■■ 2.3 4.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.2 5.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.5 5.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.8 - 4.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 4.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 5.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.8 4.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.2 5.3 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.7 @@ -60,13 +60,13 @@ 4.9 ┤■■■■■■■■■■■■■■■■■■■ 2.4 6.6 ┤■■■■■■■■■■■■■■■■■■■■■■■ 2.9 5.2 ┤■■■■■■■■■■■■■■■■■■■■■ 2.7 - 5.0 ┤■■■■■■■■■■■■■■■■ 2.0 - 5.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 5.0 ┤■■■■■■■■■■■■■■■■ 2 + 5.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 6.0 ┤■■■■■■■■■■■■■■■■■■ 2.2 6.1 ┤■■■■■■■■■■■■■■■■■■■■■■■ 2.9 5.6 ┤■■■■■■■■■■■■■■■■■■■■■■■ 2.9 6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.1 - 5.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 5.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 5.8 ┤■■■■■■■■■■■■■■■■■■■■■ 2.7 6.2 ┤■■■■■■■■■■■■■■■■■■ 2.2 5.6 ┤■■■■■■■■■■■■■■■■■■■■ 2.5 @@ -75,48 +75,48 @@ 6.3 ┤■■■■■■■■■■■■■■■■■■■■ 2.5 6.1 ┤■■■■■■■■■■■■■■■■■■■■■■ 2.8 6.4 ┤■■■■■■■■■■■■■■■■■■■■■■■ 2.9 - 6.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 6.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 6.8 ┤■■■■■■■■■■■■■■■■■■■■■■ 2.8 - 6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 6.0 ┤■■■■■■■■■■■■■■■■■■■■■■■ 2.9 5.7 ┤■■■■■■■■■■■■■■■■■■■■■ 2.6 5.5 ┤■■■■■■■■■■■■■■■■■■■ 2.4 5.5 ┤■■■■■■■■■■■■■■■■■■■ 2.4 5.8 ┤■■■■■■■■■■■■■■■■■■■■■ 2.7 6.0 ┤■■■■■■■■■■■■■■■■■■■■■ 2.7 - 5.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 5.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 6.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.4 6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.1 6.3 ┤■■■■■■■■■■■■■■■■■■ 2.3 - 5.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 5.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 5.5 ┤■■■■■■■■■■■■■■■■■■■■ 2.5 5.5 ┤■■■■■■■■■■■■■■■■■■■■■ 2.6 - 6.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 6.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 5.8 ┤■■■■■■■■■■■■■■■■■■■■■ 2.6 5.0 ┤■■■■■■■■■■■■■■■■■■ 2.3 5.6 ┤■■■■■■■■■■■■■■■■■■■■■ 2.7 - 5.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 5.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 5.7 ┤■■■■■■■■■■■■■■■■■■■■■■■ 2.9 6.2 ┤■■■■■■■■■■■■■■■■■■■■■■■ 2.9 5.1 ┤■■■■■■■■■■■■■■■■■■■■ 2.5 5.7 ┤■■■■■■■■■■■■■■■■■■■■■■ 2.8 6.3 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.3 5.8 ┤■■■■■■■■■■■■■■■■■■■■■ 2.7 - 7.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 7.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 6.3 ┤■■■■■■■■■■■■■■■■■■■■■■■ 2.9 - 6.5 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 - 7.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 6.5 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 7.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 4.9 ┤■■■■■■■■■■■■■■■■■■■■ 2.5 7.3 ┤■■■■■■■■■■■■■■■■■■■■■■■ 2.9 6.7 ┤■■■■■■■■■■■■■■■■■■■■ 2.5 7.2 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.6 6.5 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.2 6.4 ┤■■■■■■■■■■■■■■■■■■■■■ 2.7 - 6.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 6.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 5.7 ┤■■■■■■■■■■■■■■■■■■■■ 2.5 5.8 ┤■■■■■■■■■■■■■■■■■■■■■■ 2.8 6.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.2 - 6.5 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 6.5 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 7.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.8 7.7 ┤■■■■■■■■■■■■■■■■■■■■■ 2.6 6.0 ┤■■■■■■■■■■■■■■■■■■ 2.2 @@ -127,27 +127,27 @@ 6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.3 7.2 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.2 6.2 ┤■■■■■■■■■■■■■■■■■■■■■■ 2.8 - 6.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 6.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 6.4 ┤■■■■■■■■■■■■■■■■■■■■■■ 2.8 - 7.2 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 7.2 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 7.4 ┤■■■■■■■■■■■■■■■■■■■■■■ 2.8 7.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.8 6.4 ┤■■■■■■■■■■■■■■■■■■■■■■ 2.8 6.3 ┤■■■■■■■■■■■■■■■■■■■■■■ 2.8 6.1 ┤■■■■■■■■■■■■■■■■■■■■■ 2.6 - 7.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 7.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 6.3 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.4 6.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.1 - 6.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 6.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 6.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.1 6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.1 6.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.1 5.8 ┤■■■■■■■■■■■■■■■■■■■■■ 2.7 6.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.2 6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.3 - 6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 6.3 ┤■■■■■■■■■■■■■■■■■■■■ 2.5 - 6.5 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 6.5 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 6.2 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.4 - 5.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 5.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 └ ┘ From 08f029af3169482f30bb1e3692d6540ef825d3bf Mon Sep 17 00:00:00 2001 From: June Kim Date: Tue, 12 May 2026 22:47:13 -0700 Subject: [PATCH 2/2] Check all values before integer formatting (#44) Per-value integer detection created visual inconsistency (3 next to 3.5 in the same column). The issue asks for all-or-nothing: if every value is an integer, drop the decimal points; otherwise keep them. --- lib/youplot/backends/unicode_plot.rb | 19 +++++----- test/fixtures/integer-barplot.txt | 5 +++ test/fixtures/integer.tsv | 3 ++ test/fixtures/iris-barplot.txt | 56 ++++++++++++++-------------- test/youplot/integer_test.rb | 43 +++++++++++++++++++++ 5 files changed, 89 insertions(+), 37 deletions(-) create mode 100644 test/fixtures/integer-barplot.txt create mode 100644 test/fixtures/integer.tsv create mode 100644 test/youplot/integer_test.rb diff --git a/lib/youplot/backends/unicode_plot.rb b/lib/youplot/backends/unicode_plot.rb index f600bc7..28d8d2e 100644 --- a/lib/youplot/backends/unicode_plot.rb +++ b/lib/youplot/backends/unicode_plot.rb @@ -35,13 +35,6 @@ class Error < StandardError; end module_function - def normalize_numeric_value(value, force_integer = false) - num = value.to_f - return num unless num.finite? - return num.to_i if force_integer - num == num.to_i ? num.to_i : num - end - def barplot(data, params, fmt = nil, count: false, reverse: false) headers = data.headers series = data.series @@ -54,7 +47,7 @@ def barplot(data, params, fmt = nil, count: false, reverse: false) # If there is only one series.use the line number for label. params.title ||= headers[0] if headers labels = Array.new(series[0].size) { |i| (i + 1).to_s } - values = series[0].map { |v| normalize_numeric_value(v, count) } + values = series[0].map(&:to_f) else # If there are 2 or more series... if fmt == 'yx' @@ -68,7 +61,15 @@ def barplot(data, params, fmt = nil, count: false, reverse: false) end params.title ||= headers[y_col] if headers labels = series[x_col] - values = series[y_col].map { |v| normalize_numeric_value(v, count) } + values = if count + series[y_col].map(&:to_i) + else + series[y_col].map(&:to_f) + end + end + # If all values are integers, display without decimal points (#44) + if values.all? { |v| v.finite? && v == v.to_i } + values = values.map(&:to_i) end ::UnicodePlot.barplot(labels, values, **params.to_hc) end diff --git a/test/fixtures/integer-barplot.txt b/test/fixtures/integer-barplot.txt new file mode 100644 index 0000000..23ce4ff --- /dev/null +++ b/test/fixtures/integer-barplot.txt @@ -0,0 +1,5 @@ + ┌ ┐ + a ┤■■■■■■■■■ 3 + b ┤■■■■■■■■■■■■■■■■■■■■■ 7 + c ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 12 + └ ┘ diff --git a/test/fixtures/integer.tsv b/test/fixtures/integer.tsv new file mode 100644 index 0000000..12c7a37 --- /dev/null +++ b/test/fixtures/integer.tsv @@ -0,0 +1,3 @@ +a 3 +b 7 +c 12 diff --git a/test/fixtures/iris-barplot.txt b/test/fixtures/iris-barplot.txt index 0d6bfe4..7f38cb8 100644 --- a/test/fixtures/iris-barplot.txt +++ b/test/fixtures/iris-barplot.txt @@ -1,7 +1,7 @@ IRIS-BARPLOT ┌ ┐ 5.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.5 - 4.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 4.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 4.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.2 4.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.1 5.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.6 @@ -12,9 +12,9 @@ 4.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.1 5.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.7 4.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.4 - 4.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 - 4.3 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 - 5.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 4 + 4.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 4.3 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 5.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 4.0 5.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 4.4 5.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.9 5.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.5 @@ -25,7 +25,7 @@ 4.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.6 5.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.3 4.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.4 - 5.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 5.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 5.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.4 5.2 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.5 5.2 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.4 @@ -38,14 +38,14 @@ 5.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.2 5.5 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.5 4.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.1 - 4.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 4.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 5.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.4 5.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.5 4.5 ┤■■■■■■■■■■■■■■■■■■ 2.3 4.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.2 5.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.5 5.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.8 - 4.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 4.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 5.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.8 4.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.2 5.3 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.7 @@ -60,13 +60,13 @@ 4.9 ┤■■■■■■■■■■■■■■■■■■■ 2.4 6.6 ┤■■■■■■■■■■■■■■■■■■■■■■■ 2.9 5.2 ┤■■■■■■■■■■■■■■■■■■■■■ 2.7 - 5.0 ┤■■■■■■■■■■■■■■■■ 2 - 5.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 5.0 ┤■■■■■■■■■■■■■■■■ 2.0 + 5.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 6.0 ┤■■■■■■■■■■■■■■■■■■ 2.2 6.1 ┤■■■■■■■■■■■■■■■■■■■■■■■ 2.9 5.6 ┤■■■■■■■■■■■■■■■■■■■■■■■ 2.9 6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.1 - 5.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 5.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 5.8 ┤■■■■■■■■■■■■■■■■■■■■■ 2.7 6.2 ┤■■■■■■■■■■■■■■■■■■ 2.2 5.6 ┤■■■■■■■■■■■■■■■■■■■■ 2.5 @@ -75,48 +75,48 @@ 6.3 ┤■■■■■■■■■■■■■■■■■■■■ 2.5 6.1 ┤■■■■■■■■■■■■■■■■■■■■■■ 2.8 6.4 ┤■■■■■■■■■■■■■■■■■■■■■■■ 2.9 - 6.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 6.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 6.8 ┤■■■■■■■■■■■■■■■■■■■■■■ 2.8 - 6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 6.0 ┤■■■■■■■■■■■■■■■■■■■■■■■ 2.9 5.7 ┤■■■■■■■■■■■■■■■■■■■■■ 2.6 5.5 ┤■■■■■■■■■■■■■■■■■■■ 2.4 5.5 ┤■■■■■■■■■■■■■■■■■■■ 2.4 5.8 ┤■■■■■■■■■■■■■■■■■■■■■ 2.7 6.0 ┤■■■■■■■■■■■■■■■■■■■■■ 2.7 - 5.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 5.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 6.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.4 6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.1 6.3 ┤■■■■■■■■■■■■■■■■■■ 2.3 - 5.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 5.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 5.5 ┤■■■■■■■■■■■■■■■■■■■■ 2.5 5.5 ┤■■■■■■■■■■■■■■■■■■■■■ 2.6 - 6.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 6.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 5.8 ┤■■■■■■■■■■■■■■■■■■■■■ 2.6 5.0 ┤■■■■■■■■■■■■■■■■■■ 2.3 5.6 ┤■■■■■■■■■■■■■■■■■■■■■ 2.7 - 5.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 5.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 5.7 ┤■■■■■■■■■■■■■■■■■■■■■■■ 2.9 6.2 ┤■■■■■■■■■■■■■■■■■■■■■■■ 2.9 5.1 ┤■■■■■■■■■■■■■■■■■■■■ 2.5 5.7 ┤■■■■■■■■■■■■■■■■■■■■■■ 2.8 6.3 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.3 5.8 ┤■■■■■■■■■■■■■■■■■■■■■ 2.7 - 7.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 7.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 6.3 ┤■■■■■■■■■■■■■■■■■■■■■■■ 2.9 - 6.5 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 - 7.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 6.5 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 + 7.6 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 4.9 ┤■■■■■■■■■■■■■■■■■■■■ 2.5 7.3 ┤■■■■■■■■■■■■■■■■■■■■■■■ 2.9 6.7 ┤■■■■■■■■■■■■■■■■■■■■ 2.5 7.2 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.6 6.5 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.2 6.4 ┤■■■■■■■■■■■■■■■■■■■■■ 2.7 - 6.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 6.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 5.7 ┤■■■■■■■■■■■■■■■■■■■■ 2.5 5.8 ┤■■■■■■■■■■■■■■■■■■■■■■ 2.8 6.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.2 - 6.5 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 6.5 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 7.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.8 7.7 ┤■■■■■■■■■■■■■■■■■■■■■ 2.6 6.0 ┤■■■■■■■■■■■■■■■■■■ 2.2 @@ -127,27 +127,27 @@ 6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.3 7.2 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.2 6.2 ┤■■■■■■■■■■■■■■■■■■■■■■ 2.8 - 6.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 6.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 6.4 ┤■■■■■■■■■■■■■■■■■■■■■■ 2.8 - 7.2 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 7.2 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 7.4 ┤■■■■■■■■■■■■■■■■■■■■■■ 2.8 7.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.8 6.4 ┤■■■■■■■■■■■■■■■■■■■■■■ 2.8 6.3 ┤■■■■■■■■■■■■■■■■■■■■■■ 2.8 6.1 ┤■■■■■■■■■■■■■■■■■■■■■ 2.6 - 7.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 7.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 6.3 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.4 6.4 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.1 - 6.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 6.0 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 6.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.1 6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.1 6.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.1 5.8 ┤■■■■■■■■■■■■■■■■■■■■■ 2.7 6.8 ┤■■■■■■■■■■■■■■■■■■■■■■■■■ 3.2 6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.3 - 6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 6.7 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 6.3 ┤■■■■■■■■■■■■■■■■■■■■ 2.5 - 6.5 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 6.5 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 6.2 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.4 - 5.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3 + 5.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 └ ┘ diff --git a/test/youplot/integer_test.rb b/test/youplot/integer_test.rb new file mode 100644 index 0000000..ef02d2b --- /dev/null +++ b/test/youplot/integer_test.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +require 'tempfile' +require_relative '../test_helper' + +class YouPlotIntegerTest < Test::Unit::TestCase + class << self + def startup + @stdin = $stdin.dup + @stdout = $stdout.dup + @stderr = $stderr.dup + end + + def shutdown + $stdin = @stdin + $stdout = @stdout + $stderr = @stderr + end + end + + def setup + @stderr_file = Tempfile.new + @stdout_file = Tempfile.new + $stderr = @stderr_file + $stdout = @stdout_file + end + + def teardown + @stderr_file.close + @stdout_file.close + end + + def fixture(fname) + File.read(File.expand_path("../fixtures/#{fname}", __dir__)) + end + + # Issue #44: When all values are integers, display without decimal points + test :barplot_integer_values do + $stdin = File.open(File.expand_path('../fixtures/integer.tsv', __dir__), 'r') + YouPlot::Command.new(['bar']).run + assert_equal fixture('integer-barplot.txt'), @stderr_file.read + end +end