mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-05 22:31:11 +08:00
Improved simple test
This commit is contained in:
parent
3bbcea165f
commit
2e4666f9b4
@ -7,6 +7,8 @@ module YouPlot
|
||||
# plotting functions.
|
||||
module Backends
|
||||
module UnicodePlotBackend
|
||||
class Error < StandardError; end
|
||||
|
||||
module_function
|
||||
|
||||
def barplot(data, params, fmt = nil, count: false)
|
||||
@ -193,14 +195,14 @@ module YouPlot
|
||||
warn " Headers: \e[35m#{data.headers.inspect}\e[0m"
|
||||
warn " The first item is: \e[35m\"#{series[0][0]}\"\e[0m"
|
||||
warn " The last item is : \e[35m\"#{series[0][-1]}\"\e[0m"
|
||||
exit 1 if YouPlot.run_as_executable?
|
||||
YouPlot.run_as_executable ? exit(1) : raise(Error)
|
||||
end
|
||||
if fmt == 'xyxy' && series.size.odd?
|
||||
warn 'YouPlot: In the xyxy format, the number of series must be even.'
|
||||
warn ''
|
||||
warn " Number of series: \e[35m#{series.size}\e[0m"
|
||||
warn " Headers: \e[35m#{data.headers.inspect}\e[0m"
|
||||
exit 1 if YouPlot.run_as_executable?
|
||||
YouPlot.run_as_executable ? exit(1) : raise(Error)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
6
test/fixtures/simple-boxplot.txt
vendored
Normal file
6
test/fixtures/simple-boxplot.txt
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
┌ ┐
|
||||
╷ ┌──────────┬──────────┐ ╷
|
||||
1 ├───────┤ │ ├────────┤
|
||||
╵ └──────────┴──────────┘ ╵
|
||||
└ ┘
|
||||
-50 0 50
|
9
test/fixtures/simple-histogram.txt
vendored
Normal file
9
test/fixtures/simple-histogram.txt
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
┌ ┐
|
||||
[-60.0, -40.0) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1
|
||||
[-40.0, -20.0) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2
|
||||
[-20.0, 0.0) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2
|
||||
[ 0.0, 20.0) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 1
|
||||
[ 20.0, 40.0) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2
|
||||
[ 40.0, 60.0) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 2
|
||||
└ ┘
|
||||
Frequency
|
18
test/fixtures/simple-lineplot.txt
vendored
Normal file
18
test/fixtures/simple-lineplot.txt
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
┌────────────────────────────────────────┐
|
||||
50 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸│
|
||||
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡄⠀⠀⠀⠀⠀⠀⠀⡸│
|
||||
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⢇⠀⠀⠀⠀⠀⠀⠀⡇│
|
||||
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢠⢇⠀⠀⠀⠀⠀⠀⠀⡎⢸⠀⠀⠀⠀⠀⠀⢠⠃│
|
||||
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡄⠀⠀⠀⠀⠀⠀⠀⡜⢸⠀⠀⠀⠀⠀⠀⢠⠃⠈⡆⠀⠀⠀⠀⠀⢸⠀│
|
||||
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡸⠸⡀⠀⠀⠀⠀⠀⢠⠃⠀⡇⠀⠀⠀⠀⠀⢸⠀⠀⢇⠀⠀⠀⠀⠀⡎⠀│
|
||||
│⠀⠀⠀⡠⠳⡀⠀⠀⠀⠀⠀⢠⠃⠀⢣⠀⠀⠀⠀⠀⡜⠀⠀⢱⠀⠀⠀⠀⠀⡇⠀⠀⢸⠀⠀⠀⠀⠀⡇⠀│
|
||||
│⠤⢤⠼⠤⠤⠵⡤⠤⠤⠤⢤⠧⠤⠤⠼⡤⠤⠤⠤⢤⠧⠤⠤⠬⡦⠤⠤⠤⢴⠥⠤⠤⠬⡦⠤⠤⠤⢼⠤⠤│
|
||||
│⡠⠃⠀⠀⠀⠀⠱⡀⠀⠀⡜⠀⠀⠀⠀⢱⠀⠀⠀⡸⠀⠀⠀⠀⢣⠀⠀⠀⡸⠀⠀⠀⠀⡇⠀⠀⠀⡜⠀⠀│
|
||||
│⠁⠀⠀⠀⠀⠀⠀⠱⡀⡰⠁⠀⠀⠀⠀⠀⡇⠀⢀⠇⠀⠀⠀⠀⠸⡀⠀⠀⡇⠀⠀⠀⠀⢸⠀⠀⠀⡇⠀⠀│
|
||||
│⠀⠀⠀⠀⠀⠀⠀⠀⠱⠃⠀⠀⠀⠀⠀⠀⠸⡀⡸⠀⠀⠀⠀⠀⠀⢇⠀⢸⠀⠀⠀⠀⠀⠘⡄⠀⢰⠁⠀⠀│
|
||||
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢇⠇⠀⠀⠀⠀⠀⠀⢸⠀⡎⠀⠀⠀⠀⠀⠀⡇⠀⢸⠀⠀⠀│
|
||||
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠀⠀⠀⠀⠀⠀⠀⠀⣇⠇⠀⠀⠀⠀⠀⠀⢸⠀⡇⠀⠀⠀│
|
||||
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⠀⠀⠀⠀⠀⠀⠀⠘⣄⠇⠀⠀⠀│
|
||||
-50 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣿⠀⠀⠀⠀│
|
||||
└────────────────────────────────────────┘
|
||||
1 10
|
@ -104,27 +104,26 @@ class YouPlotIRISTest < Test::Unit::TestCase
|
||||
assert_equal fixture('iris-boxplot.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
test :c do
|
||||
omit
|
||||
YouPlot::Command.new(['count', '-H', '-d,']).run
|
||||
assert_equal fixture('iris-count.txt'), @stderr_file.read
|
||||
end
|
||||
# test :c do
|
||||
# YouPlot::Command.new(['count', '-H', '-d,']).run
|
||||
# assert_equal fixture('iris-count.txt'), @stderr_file.read
|
||||
# end
|
||||
|
||||
test :count do
|
||||
omit
|
||||
YouPlot::Command.new(['c', '-H', '-d,']).run
|
||||
assert_equal fixture('iris-count.txt'), @stderr_file.read
|
||||
end
|
||||
# test :count do
|
||||
# YouPlot::Command.new(['c', '-H', '-d,']).run
|
||||
# assert_equal fixture('iris-count.txt'), @stderr_file.read
|
||||
# end
|
||||
|
||||
test :plot_output_stdout do
|
||||
YouPlot::Command.new(['bar', '-o', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
||||
assert_equal '', @stderr_file.read
|
||||
assert_equal fixture('iris-barplot.txt'), @stdout_file.read
|
||||
end
|
||||
|
||||
test :data_output_stdout do
|
||||
YouPlot::Command.new(['bar', '-O', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
||||
assert_equal fixture('iris-barplot.txt'), @stderr_file.read
|
||||
assert_equal File.read(File.expand_path('../fixtures/iris.csv', __dir__)), @stdout_file.read
|
||||
assert_equal fixture('iris.csv'), @stdout_file.read
|
||||
end
|
||||
|
||||
%i[colors color colours colour].each do |cmd_name|
|
||||
|
@ -40,70 +40,77 @@ class YouPlotSimpleTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
# test :barplot do
|
||||
# YouPlot::Command.new(['barplot', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
||||
# assert_equal fixture('iris-barplot.txt'), @stderr_file.read
|
||||
# end
|
||||
test :barplot do
|
||||
assert_raise(ArgumentError) do
|
||||
YouPlot::Command.new(['barplot']).run
|
||||
end
|
||||
end
|
||||
|
||||
# test :hist do
|
||||
# YouPlot::Command.new(['hist', '-H', '-d,', '-t', 'IRIS-HISTOGRAM']).run
|
||||
# assert_equal fixture('iris-histogram.txt'), @stderr_file.read
|
||||
# end
|
||||
test :hist do
|
||||
YouPlot::Command.new(['hist']).run
|
||||
assert_equal fixture('simple-histogram.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
# test :histogram do
|
||||
# YouPlot::Command.new(['histogram', '-H', '-d,', '-t', 'IRIS-HISTOGRAM']).run
|
||||
# assert_equal fixture('iris-histogram.txt'), @stderr_file.read
|
||||
# end
|
||||
test :histogram do
|
||||
YouPlot::Command.new(['histogram']).run
|
||||
assert_equal fixture('simple-histogram.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
# test :line do
|
||||
# YouPlot::Command.new(['line', '-H', '-d,', '-t', 'IRIS-LINEPLOT']).run
|
||||
# assert_equal fixture('iris-lineplot.txt'), @stderr_file.read
|
||||
# end
|
||||
test :line do
|
||||
YouPlot::Command.new(['line']).run
|
||||
assert_equal fixture('simple-lineplot.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
# test :lineplot do
|
||||
# YouPlot::Command.new(['lineplot', '-H', '-d,', '-t', 'IRIS-LINEPLOT']).run
|
||||
# assert_equal fixture('iris-lineplot.txt'), @stderr_file.read
|
||||
# end
|
||||
test :lineplot do
|
||||
YouPlot::Command.new(['lineplot']).run
|
||||
assert_equal fixture('simple-lineplot.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
# test :lines do
|
||||
# YouPlot::Command.new(['lines', '-H', '-d,', '-t', 'IRIS-LINEPLOTS']).run
|
||||
# assert_equal fixture('iris-lineplots.txt'), @stderr_file.read
|
||||
# end
|
||||
test :lines do
|
||||
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do
|
||||
YouPlot::Command.new(['lines']).run
|
||||
end
|
||||
end
|
||||
|
||||
# test :lineplots do
|
||||
# YouPlot::Command.new(['lineplots', '-H', '-d,', '-t', 'IRIS-LINEPLOTS']).run
|
||||
# assert_equal fixture('iris-lineplots.txt'), @stderr_file.read
|
||||
# end
|
||||
test :lineplots do
|
||||
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do
|
||||
YouPlot::Command.new(['lineplots']).run
|
||||
end
|
||||
end
|
||||
|
||||
# test :s do
|
||||
# YouPlot::Command.new(['s', '-H', '-d,', '-t', 'IRIS-SCATTER']).run
|
||||
# assert_equal fixture('iris-scatter.txt'), @stderr_file.read
|
||||
# end
|
||||
test :s do
|
||||
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do
|
||||
YouPlot::Command.new(['s']).run
|
||||
end
|
||||
end
|
||||
|
||||
# test :scatter do
|
||||
# YouPlot::Command.new(['scatter', '-H', '-d,', '-t', 'IRIS-SCATTER']).run
|
||||
# assert_equal fixture('iris-scatter.txt'), @stderr_file.read
|
||||
# end
|
||||
test :scatter do
|
||||
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do
|
||||
YouPlot::Command.new(['scatter']).run
|
||||
end
|
||||
end
|
||||
|
||||
# test :d do
|
||||
# YouPlot::Command.new(['d', '-H', '-d,', '-t', 'IRIS-DENSITY']).run
|
||||
# assert_equal fixture('iris-density.txt'), @stderr_file.read
|
||||
# end
|
||||
test :d do
|
||||
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do
|
||||
YouPlot::Command.new(['d']).run
|
||||
end
|
||||
end
|
||||
|
||||
# test :density do
|
||||
# YouPlot::Command.new(['density', '-H', '-d,', '-t', 'IRIS-DENSITY']).run
|
||||
# assert_equal fixture('iris-density.txt'), @stderr_file.read
|
||||
# end
|
||||
test :density do
|
||||
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do
|
||||
YouPlot::Command.new(['density']).run
|
||||
end
|
||||
end
|
||||
|
||||
# test :box do
|
||||
# YouPlot::Command.new(['box', '-H', '-d,', '-t', 'IRIS-BOXPLOT']).run
|
||||
# assert_equal fixture('iris-boxplot.txt'), @stderr_file.read
|
||||
# end
|
||||
test :box do
|
||||
YouPlot::Command.new(['box']).run
|
||||
assert_equal fixture('simple-boxplot.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
# test :boxplot do
|
||||
# YouPlot::Command.new(['boxplot', '-H', '-d,', '-t', 'IRIS-BOXPLOT']).run
|
||||
# assert_equal fixture('iris-boxplot.txt'), @stderr_file.read
|
||||
# end
|
||||
test :boxplot do
|
||||
YouPlot::Command.new(['boxplot']).run
|
||||
assert_equal fixture('simple-boxplot.txt'), @stderr_file.read
|
||||
end
|
||||
|
||||
# test :c do
|
||||
# omit
|
||||
@ -117,36 +124,15 @@ class YouPlotSimpleTest < Test::Unit::TestCase
|
||||
# assert_equal fixture('iris-count.txt'), @stderr_file.read
|
||||
# end
|
||||
|
||||
# test :plot_output_stdout do
|
||||
# YouPlot::Command.new(['bar', '-o', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
||||
# assert_equal '', @stderr_file.read
|
||||
# end
|
||||
test :plot_output_stdout do
|
||||
YouPlot::Command.new(['line', '-o']).run
|
||||
assert_equal '', @stderr_file.read
|
||||
assert_equal fixture('simple-lineplot.txt'), @stdout_file.read
|
||||
end
|
||||
|
||||
# test :data_output_stdout do
|
||||
# YouPlot::Command.new(['bar', '-O', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
||||
# assert_equal fixture('iris-barplot.txt'), @stderr_file.read
|
||||
# assert_equal File.read(File.expand_path('../fixtures/iris.csv', __dir__)), @stdout_file.read
|
||||
# end
|
||||
|
||||
# %i[colors color colours colour].each do |cmd_name|
|
||||
# test cmd_name do
|
||||
# YouPlot::Command.new([cmd_name.to_s]).run
|
||||
# assert_equal fixture('colors.txt'), @stderr_file.read
|
||||
# assert_equal '', @stdout_file.read
|
||||
# end
|
||||
# end
|
||||
|
||||
# test :colors_output_stdout do
|
||||
# YouPlot::Command.new(['colors', '-o']).run
|
||||
# assert_equal '', @stderr_file.read
|
||||
# assert_equal fixture('colors.txt'), @stdout_file.read
|
||||
# end
|
||||
|
||||
# test :unrecognized_command do
|
||||
# assert_raise(YouPlot::Command::Parser::Error) do
|
||||
# YouPlot::Command.new(['abracadabra', '--hadley', '--wickham']).run
|
||||
# end
|
||||
# assert_equal '', @stderr_file.read
|
||||
# assert_equal '', @stdout_file.read
|
||||
# end
|
||||
test :data_output_stdout do
|
||||
YouPlot::Command.new(['box', '-O']).run
|
||||
assert_equal fixture('simple-boxplot.txt'), @stderr_file.read
|
||||
assert_equal fixture('simple.tsv'), @stdout_file.read
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user