mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-07 23:51:12 +08:00
Improved simple test
This commit is contained in:
parent
3bbcea165f
commit
2e4666f9b4
@ -7,6 +7,8 @@ module YouPlot
|
|||||||
# plotting functions.
|
# plotting functions.
|
||||||
module Backends
|
module Backends
|
||||||
module UnicodePlotBackend
|
module UnicodePlotBackend
|
||||||
|
class Error < StandardError; end
|
||||||
|
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def barplot(data, params, fmt = nil, count: false)
|
def barplot(data, params, fmt = nil, count: false)
|
||||||
@ -193,14 +195,14 @@ module YouPlot
|
|||||||
warn " Headers: \e[35m#{data.headers.inspect}\e[0m"
|
warn " Headers: \e[35m#{data.headers.inspect}\e[0m"
|
||||||
warn " The first item is: \e[35m\"#{series[0][0]}\"\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"
|
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
|
end
|
||||||
if fmt == 'xyxy' && series.size.odd?
|
if fmt == 'xyxy' && series.size.odd?
|
||||||
warn 'YouPlot: In the xyxy format, the number of series must be even.'
|
warn 'YouPlot: In the xyxy format, the number of series must be even.'
|
||||||
warn ''
|
warn ''
|
||||||
warn " Number of series: \e[35m#{series.size}\e[0m"
|
warn " Number of series: \e[35m#{series.size}\e[0m"
|
||||||
warn " Headers: \e[35m#{data.headers.inspect}\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
|
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
|
assert_equal fixture('iris-boxplot.txt'), @stderr_file.read
|
||||||
end
|
end
|
||||||
|
|
||||||
test :c do
|
# test :c do
|
||||||
omit
|
# YouPlot::Command.new(['count', '-H', '-d,']).run
|
||||||
YouPlot::Command.new(['count', '-H', '-d,']).run
|
# assert_equal fixture('iris-count.txt'), @stderr_file.read
|
||||||
assert_equal fixture('iris-count.txt'), @stderr_file.read
|
# end
|
||||||
end
|
|
||||||
|
|
||||||
test :count do
|
# test :count do
|
||||||
omit
|
# YouPlot::Command.new(['c', '-H', '-d,']).run
|
||||||
YouPlot::Command.new(['c', '-H', '-d,']).run
|
# assert_equal fixture('iris-count.txt'), @stderr_file.read
|
||||||
assert_equal fixture('iris-count.txt'), @stderr_file.read
|
# end
|
||||||
end
|
|
||||||
|
|
||||||
test :plot_output_stdout do
|
test :plot_output_stdout do
|
||||||
YouPlot::Command.new(['bar', '-o', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
YouPlot::Command.new(['bar', '-o', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
||||||
assert_equal '', @stderr_file.read
|
assert_equal '', @stderr_file.read
|
||||||
|
assert_equal fixture('iris-barplot.txt'), @stdout_file.read
|
||||||
end
|
end
|
||||||
|
|
||||||
test :data_output_stdout do
|
test :data_output_stdout do
|
||||||
YouPlot::Command.new(['bar', '-O', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
YouPlot::Command.new(['bar', '-O', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
||||||
assert_equal fixture('iris-barplot.txt'), @stderr_file.read
|
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
|
end
|
||||||
|
|
||||||
%i[colors color colours colour].each do |cmd_name|
|
%i[colors color colours colour].each do |cmd_name|
|
||||||
|
@ -40,70 +40,77 @@ class YouPlotSimpleTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# test :barplot do
|
test :barplot do
|
||||||
# YouPlot::Command.new(['barplot', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
assert_raise(ArgumentError) do
|
||||||
# assert_equal fixture('iris-barplot.txt'), @stderr_file.read
|
YouPlot::Command.new(['barplot']).run
|
||||||
# end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# test :hist do
|
test :hist do
|
||||||
# YouPlot::Command.new(['hist', '-H', '-d,', '-t', 'IRIS-HISTOGRAM']).run
|
YouPlot::Command.new(['hist']).run
|
||||||
# assert_equal fixture('iris-histogram.txt'), @stderr_file.read
|
assert_equal fixture('simple-histogram.txt'), @stderr_file.read
|
||||||
# end
|
end
|
||||||
|
|
||||||
# test :histogram do
|
test :histogram do
|
||||||
# YouPlot::Command.new(['histogram', '-H', '-d,', '-t', 'IRIS-HISTOGRAM']).run
|
YouPlot::Command.new(['histogram']).run
|
||||||
# assert_equal fixture('iris-histogram.txt'), @stderr_file.read
|
assert_equal fixture('simple-histogram.txt'), @stderr_file.read
|
||||||
# end
|
end
|
||||||
|
|
||||||
# test :line do
|
test :line do
|
||||||
# YouPlot::Command.new(['line', '-H', '-d,', '-t', 'IRIS-LINEPLOT']).run
|
YouPlot::Command.new(['line']).run
|
||||||
# assert_equal fixture('iris-lineplot.txt'), @stderr_file.read
|
assert_equal fixture('simple-lineplot.txt'), @stderr_file.read
|
||||||
# end
|
end
|
||||||
|
|
||||||
# test :lineplot do
|
test :lineplot do
|
||||||
# YouPlot::Command.new(['lineplot', '-H', '-d,', '-t', 'IRIS-LINEPLOT']).run
|
YouPlot::Command.new(['lineplot']).run
|
||||||
# assert_equal fixture('iris-lineplot.txt'), @stderr_file.read
|
assert_equal fixture('simple-lineplot.txt'), @stderr_file.read
|
||||||
# end
|
end
|
||||||
|
|
||||||
# test :lines do
|
test :lines do
|
||||||
# YouPlot::Command.new(['lines', '-H', '-d,', '-t', 'IRIS-LINEPLOTS']).run
|
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do
|
||||||
# assert_equal fixture('iris-lineplots.txt'), @stderr_file.read
|
YouPlot::Command.new(['lines']).run
|
||||||
# end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# test :lineplots do
|
test :lineplots do
|
||||||
# YouPlot::Command.new(['lineplots', '-H', '-d,', '-t', 'IRIS-LINEPLOTS']).run
|
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do
|
||||||
# assert_equal fixture('iris-lineplots.txt'), @stderr_file.read
|
YouPlot::Command.new(['lineplots']).run
|
||||||
# end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# test :s do
|
test :s do
|
||||||
# YouPlot::Command.new(['s', '-H', '-d,', '-t', 'IRIS-SCATTER']).run
|
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do
|
||||||
# assert_equal fixture('iris-scatter.txt'), @stderr_file.read
|
YouPlot::Command.new(['s']).run
|
||||||
# end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# test :scatter do
|
test :scatter do
|
||||||
# YouPlot::Command.new(['scatter', '-H', '-d,', '-t', 'IRIS-SCATTER']).run
|
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do
|
||||||
# assert_equal fixture('iris-scatter.txt'), @stderr_file.read
|
YouPlot::Command.new(['scatter']).run
|
||||||
# end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# test :d do
|
test :d do
|
||||||
# YouPlot::Command.new(['d', '-H', '-d,', '-t', 'IRIS-DENSITY']).run
|
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do
|
||||||
# assert_equal fixture('iris-density.txt'), @stderr_file.read
|
YouPlot::Command.new(['d']).run
|
||||||
# end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# test :density do
|
test :density do
|
||||||
# YouPlot::Command.new(['density', '-H', '-d,', '-t', 'IRIS-DENSITY']).run
|
assert_raise(YouPlot::Backends::UnicodePlotBackend::Error) do
|
||||||
# assert_equal fixture('iris-density.txt'), @stderr_file.read
|
YouPlot::Command.new(['density']).run
|
||||||
# end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# test :box do
|
test :box do
|
||||||
# YouPlot::Command.new(['box', '-H', '-d,', '-t', 'IRIS-BOXPLOT']).run
|
YouPlot::Command.new(['box']).run
|
||||||
# assert_equal fixture('iris-boxplot.txt'), @stderr_file.read
|
assert_equal fixture('simple-boxplot.txt'), @stderr_file.read
|
||||||
# end
|
end
|
||||||
|
|
||||||
# test :boxplot do
|
test :boxplot do
|
||||||
# YouPlot::Command.new(['boxplot', '-H', '-d,', '-t', 'IRIS-BOXPLOT']).run
|
YouPlot::Command.new(['boxplot']).run
|
||||||
# assert_equal fixture('iris-boxplot.txt'), @stderr_file.read
|
assert_equal fixture('simple-boxplot.txt'), @stderr_file.read
|
||||||
# end
|
end
|
||||||
|
|
||||||
# test :c do
|
# test :c do
|
||||||
# omit
|
# omit
|
||||||
@ -117,36 +124,15 @@ class YouPlotSimpleTest < Test::Unit::TestCase
|
|||||||
# assert_equal fixture('iris-count.txt'), @stderr_file.read
|
# assert_equal fixture('iris-count.txt'), @stderr_file.read
|
||||||
# end
|
# end
|
||||||
|
|
||||||
# test :plot_output_stdout do
|
test :plot_output_stdout do
|
||||||
# YouPlot::Command.new(['bar', '-o', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
YouPlot::Command.new(['line', '-o']).run
|
||||||
# assert_equal '', @stderr_file.read
|
assert_equal '', @stderr_file.read
|
||||||
# end
|
assert_equal fixture('simple-lineplot.txt'), @stdout_file.read
|
||||||
|
end
|
||||||
|
|
||||||
# test :data_output_stdout do
|
test :data_output_stdout do
|
||||||
# YouPlot::Command.new(['bar', '-O', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
YouPlot::Command.new(['box', '-O']).run
|
||||||
# assert_equal fixture('iris-barplot.txt'), @stderr_file.read
|
assert_equal fixture('simple-boxplot.txt'), @stderr_file.read
|
||||||
# assert_equal File.read(File.expand_path('../fixtures/iris.csv', __dir__)), @stdout_file.read
|
assert_equal fixture('simple.tsv'), @stdout_file.read
|
||||||
# end
|
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
|
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user