mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-07 23:51:12 +08:00
Add some basic tests
This commit is contained in:
parent
a0c3863b4c
commit
7034a83dea
1
test/fixtures/colors.txt
vendored
Normal file
1
test/fixtures/colors.txt
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -1,4 +1,4 @@
|
|||||||
sepal_width
|
IRIS-BARPLOT
|
||||||
┌ ┐
|
┌ ┐
|
||||||
5.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.5
|
5.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.5
|
||||||
4.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0
|
4.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0
|
19
test/fixtures/iris-boxplot.txt
vendored
Normal file
19
test/fixtures/iris-boxplot.txt
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
IRIS-BOXPLOT
|
||||||
|
┌ ┐
|
||||||
|
╷ ┌──┬──┐ ╷
|
||||||
|
sepal_length ├───┤ │ ├───────┤
|
||||||
|
╵ └──┴──┘ ╵
|
||||||
|
╷ ┌┬┐ ╷
|
||||||
|
sepal_width ├───┤│├─────┤
|
||||||
|
╵ └┴┘ ╵
|
||||||
|
╷ ┌─────────────┬───┐ ╷
|
||||||
|
petal_length ├──┤ │ ├───────┤
|
||||||
|
╵ └─────────────┴───┘ ╵
|
||||||
|
╷┌───┬──┐ ╷
|
||||||
|
petal_width ├┤ │ ├──┤
|
||||||
|
╵└───┴──┘ ╵
|
||||||
|
╷
|
||||||
|
species ┤
|
||||||
|
╵
|
||||||
|
└ ┘
|
||||||
|
0 4 8
|
20
test/fixtures/iris-density.txt
vendored
Normal file
20
test/fixtures/iris-density.txt
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
IRIS-DENSITY
|
||||||
|
┌────────────────────────────────────────┐
|
||||||
|
6.9 │ │ sepal_width
|
||||||
|
│ │ petal_length
|
||||||
|
│ │ petal_width
|
||||||
|
│ │ species
|
||||||
|
│ ░ │
|
||||||
|
│ │
|
||||||
|
│ ░ │
|
||||||
|
│ ░ │
|
||||||
|
│ ░ ░ ░░ ░ │
|
||||||
|
│ ░ ░ ░ │
|
||||||
|
│ │
|
||||||
|
│ ░ ░▒ ░ ░ ░ ░ │
|
||||||
|
│ ░ ░ ░ │
|
||||||
|
│ │
|
||||||
|
0 │ ░░ ▒ ░█ ░ ░▒ ░░ ░ ░░░ ░ │
|
||||||
|
└────────────────────────────────────────┘
|
||||||
|
4 8
|
||||||
|
sepal_length
|
12
test/fixtures/iris-histogram.txt
vendored
Normal file
12
test/fixtures/iris-histogram.txt
vendored
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
IRIS-HISTOGRAM
|
||||||
|
┌ ┐
|
||||||
|
[4.0, 4.5) ┤▇▇▇▇▇ 4
|
||||||
|
[4.5, 5.0) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 18
|
||||||
|
[5.0, 5.5) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 30
|
||||||
|
[5.5, 6.0) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 31
|
||||||
|
[6.0, 6.5) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 32
|
||||||
|
[6.5, 7.0) ┤▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇▇ 22
|
||||||
|
[7.0, 7.5) ┤▇▇▇▇▇▇▇▇ 7
|
||||||
|
[7.5, 8.0) ┤▇▇▇▇▇▇▇ 6
|
||||||
|
└ ┘
|
||||||
|
Frequency
|
20
test/fixtures/iris-lineplot.txt
vendored
Normal file
20
test/fixtures/iris-lineplot.txt
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
IRIS-LINEPLOT
|
||||||
|
┌────────────────────────────────────────┐
|
||||||
|
5 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
|
||||||
|
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
|
||||||
|
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
|
||||||
|
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠎⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
|
||||||
|
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡔⠒⣽⠋⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
|
||||||
|
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢣⣼⠇⡠⠠⠊⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
|
||||||
|
│⠀⠀⠀⠀⠀⢀⣀⣀⠤⢤⣼⢿⣿⣿⠯⠛⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠤⢊⡧⡺⠁│
|
||||||
|
sepal_width │⠀⠀⠀⠀⠀⠈⢑⠦⣺⣵⣿⣿⡝⢵⡠⠆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠔⣺⠥⢊⠥⠊⠁⡷⠁⠀│
|
||||||
|
│⠀⠀⠀⠀⢀⡨⡽⣿⣯⢟⣿⡯⠿⠭⠥⠤⠤⢤⠤⠮⢍⣕⣣⣏⣉⣒⣦⣶⣭⣤⣺⣥⠊⠁⠀⠀⡰⡇⠀⠀│
|
||||||
|
│⠀⠀⠀⡠⣗⣭⣞⣿⣾⣟⡇⠀⠀⠀⢀⠤⢊⣁⣰⣣⣾⣟⣥⣾⣿⣽⢿⣿⡿⡿⠛⠉⠓⠢⠤⣴⣁⡇⠀⠀│
|
||||||
|
│⠀⠀⠈⠉⡟⠋⠉⡝⠀⠉⠁⠀⠀⠀⠉⢺⣷⣷⢿⣿⣿⣿⣷⣾⣿⣿⣿⣿⣿⣿⣯⢿⡿⢟⡻⠋⠉⡇⠀⠀│
|
||||||
|
│⠀⠀⠀⠀⢱⠀⡰⠁⠀⠀⠀⢀⢖⣶⣾⣿⣿⣻⡿⣿⣿⣿⣿⢿⣿⠟⠛⢻⢛⡻⠛⠉⠉⠉⠉⠉⠉⡇⠀⠀│
|
||||||
|
│⠀⠀⠀⠀⢸⢠⠃⠀⠀⢔⣶⡾⡿⣟⡿⢿⠷⣟⡿⢿⡟⢅⡱⢏⠎⠀⠀⠗⢁⣀⣀⠤⠤⠒⠒⠉⠉⠁⠀⠀│
|
||||||
|
│⠀⠀⠀⠀⠸⠇⠀⠀⠀⠁⢴⠋⡩⠊⠀⠗⠋⠁⠉⢺⣷⣎⡱⠮⠔⠒⠊⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
|
||||||
|
2 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡮⠊⠀⠀⠀⠀⠀⠀⠀⠀⠁⠈⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
|
||||||
|
└────────────────────────────────────────┘
|
||||||
|
4 8
|
||||||
|
sepal_length
|
20
test/fixtures/iris-lineplots.txt
vendored
Normal file
20
test/fixtures/iris-lineplots.txt
vendored
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
IRIS-LINEPLOTS
|
||||||
|
┌────────────────────────────────────────┐
|
||||||
|
6.9 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣲⠭⠃⠀⠀│ sepal_width
|
||||||
|
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⢀⣀⣠⣤⣶⣿⣿⣯⣴⣒⠖⠉⠁│ petal_length
|
||||||
|
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⢮⣤⣤⣶⣿⣿⣿⠿⠛⠛⠋⠉⠀⠀⠀⠀⠀⠀│ petal_width
|
||||||
|
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⣴⣷⣿⣿⣿⣿⣿⣿⣟⣟⡂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ species
|
||||||
|
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⠤⠔⠒⢙⡻⠝⢋⡽⢝⣳⣾⣫⣥⣒⣪⣵⣖⣂⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
|
||||||
|
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠀⠀⢀⣉⣟⣻⣿⣻⣿⣿⣿⠿⣿⣿⠿⠟⡢⠒⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
|
||||||
|
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣿⣷⣾⣿⡿⣿⡯⠿⠛⠋⠉⠀⣀⠔⠉⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣄⣀⠄│
|
||||||
|
│⠀⠀⠀⠀⢀⣨⣽⣿⣿⣿⣿⣿⣿⣿⣵⣚⣉⣃⣀⣠⣤⣤⣔⣮⣤⣄⣀⣠⣤⣔⣲⣾⡳⠮⠛⠋⢉⡗⠁⠀│
|
||||||
|
│⠀⠀⠐⠒⡿⠿⠟⡻⠛⠛⠛⠚⠉⠀⠲⣶⣿⣷⣾⣷⣿⣿⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣶⣷⡇⠀⠀│
|
||||||
|
│⠀⠀⠀⠀⢱⡠⠊⠀⠀⣤⣤⣶⣿⣿⠿⣿⣿⣿⣿⣿⣟⣿⣿⣟⣟⣉⣉⣝⣛⣫⣭⣥⣤⣤⣔⣒⣒⡃⠀⠀│
|
||||||
|
│⠀⠀⠀⠀⠀⠁⠀⢀⡀⠀⢯⠒⠉⡠⠔⠡⠤⠮⣤⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣶⣶⣶⣶⣿⣿⠥⠤⠄│
|
||||||
|
│⠀⠀⠀⠀⣀⣠⣄⣤⣭⣿⣿⣿⣿⣿⣿⣿⣿⣯⣯⣯⣭⣽⣿⣿⣿⣿⣿⣯⣭⣍⡙⠛⠝⠉⠀⠀⠀⠀⠀⠀│
|
||||||
|
│⠀⠀⠠⠴⠿⢯⠭⠿⠯⣭⣷⡾⠿⠿⠿⣿⢿⡿⡻⠿⡟⠛⢛⣛⠯⠭⠒⠒⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
|
||||||
|
│⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣄⠀⠀⠀⢀⣀⡠⠤⠔⠒⠊⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
|
||||||
|
0 │⠀⠀⢀⣀⣴⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣻⣷⣄⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⡀│
|
||||||
|
└────────────────────────────────────────┘
|
||||||
|
4 8
|
||||||
|
sepal_length
|
2
test/fixtures/iris-scatter.txt
vendored
2
test/fixtures/iris-scatter.txt
vendored
@ -1,4 +1,4 @@
|
|||||||
IRIS
|
IRIS-SCATTER
|
||||||
┌────────────────────────────────────────┐
|
┌────────────────────────────────────────┐
|
||||||
6.9 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠄⠃⠀⠀│ sepal_width
|
6.9 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠄⠃⠀⠀│ sepal_width
|
||||||
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⡄⠂⠄⠀⠀⠄⠀⠁│ petal_length
|
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⡄⠂⠄⠀⠀⠄⠀⠁│ petal_length
|
||||||
|
@ -1,41 +1,102 @@
|
|||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require "tempfile"
|
require 'tempfile'
|
||||||
require_relative '../test_helper'
|
require_relative '../test_helper'
|
||||||
|
|
||||||
class YouPlotCommandTest < Test::Unit::TestCase
|
class YouPlotCommandTest < Test::Unit::TestCase
|
||||||
def startup
|
class << self
|
||||||
|
def startup
|
||||||
|
@stdin = $stdin.dup
|
||||||
|
@stderr = $stderr.dup
|
||||||
|
end
|
||||||
|
|
||||||
|
def shutdown
|
||||||
|
$stdin = @stdin
|
||||||
|
$stderr = @stderr
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
@stdin = $stdin.dup
|
$stdin = File.open(File.expand_path('../fixtures/iris.csv', __dir__), 'r')
|
||||||
$stdin = File.open(File.expand_path("../fixtures/iris.csv", __dir__), "r")
|
@tmp_file = Tempfile.new
|
||||||
@stderr = $stderr.dup
|
$stderr = @tmp_file
|
||||||
end
|
end
|
||||||
|
|
||||||
def cleanup
|
def teardown
|
||||||
$stdin = @stdin
|
@tmp_file.close
|
||||||
$stderr = @stderr
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def fixture(fname)
|
def fixture(fname)
|
||||||
File.read(File.expand_path("../fixtures/#{fname}", __dir__))
|
File.read(File.expand_path("../fixtures/#{fname}", __dir__))
|
||||||
end
|
end
|
||||||
|
|
||||||
test :scatter do
|
test :bar do
|
||||||
Tempfile.new do |tmp_file|
|
YouPlot::Command.new(['bar', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
||||||
$stderr = tmp_file
|
assert_equal fixture('iris-barplot.txt'), @tmp_file.read
|
||||||
YouPlot::Command.new(["scatter", "-H", "-d,", "-t", "IRIS"]).run
|
|
||||||
assert_equal fixture('iris-scatter.txt'), tmp_file.read
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test :barplot do
|
test :barplot do
|
||||||
Tempfile.new do |tmp_file|
|
YouPlot::Command.new(['barplot', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
|
||||||
$stderr = tmp_file
|
assert_equal fixture('iris-barplot.txt'), @tmp_file.read
|
||||||
YouPlot::Command.new(["barplot", "-H", "-d,", "-t", "IRIS"]).run
|
|
||||||
assert_equal fixture('iris-bar.txt'), tmp_file.read
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test :hist do
|
||||||
|
YouPlot::Command.new(['hist', '-H', '-d,', '-t', 'IRIS-HISTOGRAM']).run
|
||||||
|
assert_equal fixture('iris-histogram.txt'), @tmp_file.read
|
||||||
|
end
|
||||||
|
|
||||||
|
test :histogram do
|
||||||
|
YouPlot::Command.new(['histogram', '-H', '-d,', '-t', 'IRIS-HISTOGRAM']).run
|
||||||
|
assert_equal fixture('iris-histogram.txt'), @tmp_file.read
|
||||||
|
end
|
||||||
|
|
||||||
|
test :line do
|
||||||
|
YouPlot::Command.new(['line', '-H', '-d,', '-t', 'IRIS-LINEPLOT']).run
|
||||||
|
assert_equal fixture('iris-lineplot.txt'), @tmp_file.read
|
||||||
|
end
|
||||||
|
|
||||||
|
test :lineplot do
|
||||||
|
YouPlot::Command.new(['lineplot', '-H', '-d,', '-t', 'IRIS-LINEPLOT']).run
|
||||||
|
assert_equal fixture('iris-lineplot.txt'), @tmp_file.read
|
||||||
|
end
|
||||||
|
|
||||||
|
test :lines do
|
||||||
|
YouPlot::Command.new(['lines', '-H', '-d,', '-t', 'IRIS-LINEPLOTS']).run
|
||||||
|
assert_equal fixture('iris-lineplots.txt'), @tmp_file.read
|
||||||
|
end
|
||||||
|
|
||||||
|
test :lineplots do
|
||||||
|
YouPlot::Command.new(['lineplots', '-H', '-d,', '-t', 'IRIS-LINEPLOTS']).run
|
||||||
|
assert_equal fixture('iris-lineplots.txt'), @tmp_file.read
|
||||||
|
end
|
||||||
|
|
||||||
|
test :s do
|
||||||
|
YouPlot::Command.new(['s', '-H', '-d,', '-t', 'IRIS-SCATTER']).run
|
||||||
|
assert_equal fixture('iris-scatter.txt'), @tmp_file.read
|
||||||
|
end
|
||||||
|
|
||||||
|
test :scatter do
|
||||||
|
YouPlot::Command.new(['scatter', '-H', '-d,', '-t', 'IRIS-SCATTER']).run
|
||||||
|
assert_equal fixture('iris-scatter.txt'), @tmp_file.read
|
||||||
|
end
|
||||||
|
|
||||||
|
test :d do
|
||||||
|
YouPlot::Command.new(['d', '-H', '-d,', '-t', 'IRIS-DENSITY']).run
|
||||||
|
assert_equal fixture('iris-density.txt'), @tmp_file.read
|
||||||
|
end
|
||||||
|
|
||||||
|
test :density do
|
||||||
|
YouPlot::Command.new(['density', '-H', '-d,', '-t', 'IRIS-DENSITY']).run
|
||||||
|
assert_equal fixture('iris-density.txt'), @tmp_file.read
|
||||||
|
end
|
||||||
|
|
||||||
|
test :box do
|
||||||
|
YouPlot::Command.new(['box', '-H', '-d,', '-t', 'IRIS-BOXPLOT']).run
|
||||||
|
assert_equal fixture('iris-boxplot.txt'), @tmp_file.read
|
||||||
|
end
|
||||||
|
|
||||||
|
test :boxplot do
|
||||||
|
YouPlot::Command.new(['boxplot', '-H', '-d,', '-t', 'IRIS-BOXPLOT']).run
|
||||||
|
assert_equal fixture('iris-boxplot.txt'), @tmp_file.read
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user