Add some basic tests

This commit is contained in:
kojix2 2020-11-23 21:31:16 +09:00
parent a0c3863b4c
commit 7034a83dea
9 changed files with 174 additions and 21 deletions

1
test/fixtures/colors.txt vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
sepal_width
IRIS-BARPLOT
┌ ┐
5.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.5
4.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0

19
test/fixtures/iris-boxplot.txt vendored Normal file
View 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
View 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
View 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
View File

@ -0,0 +1,20 @@
IRIS-LINEPLOT
┌────────────────────────────────────────┐
5 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠎⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡔⠒⣽⠋⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢣⣼⠇⡠⠠⠊⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⢀⣀⣀⠤⢤⣼⢿⣿⣿⠯⠛⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠤⢊⡧⡺⠁│
sepal_width │⠀⠀⠀⠀⠀⠈⢑⠦⣺⣵⣿⣿⡝⢵⡠⠆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠔⣺⠥⢊⠥⠊⠁⡷⠁⠀│
│⠀⠀⠀⠀⢀⡨⡽⣿⣯⢟⣿⡯⠿⠭⠥⠤⠤⢤⠤⠮⢍⣕⣣⣏⣉⣒⣦⣶⣭⣤⣺⣥⠊⠁⠀⠀⡰⡇⠀⠀│
│⠀⠀⠀⡠⣗⣭⣞⣿⣾⣟⡇⠀⠀⠀⢀⠤⢊⣁⣰⣣⣾⣟⣥⣾⣿⣽⢿⣿⡿⡿⠛⠉⠓⠢⠤⣴⣁⡇⠀⠀│
│⠀⠀⠈⠉⡟⠋⠉⡝⠀⠉⠁⠀⠀⠀⠉⢺⣷⣷⢿⣿⣿⣿⣷⣾⣿⣿⣿⣿⣿⣿⣯⢿⡿⢟⡻⠋⠉⡇⠀⠀│
│⠀⠀⠀⠀⢱⠀⡰⠁⠀⠀⠀⢀⢖⣶⣾⣿⣿⣻⡿⣿⣿⣿⣿⢿⣿⠟⠛⢻⢛⡻⠛⠉⠉⠉⠉⠉⠉⡇⠀⠀│
│⠀⠀⠀⠀⢸⢠⠃⠀⠀⢔⣶⡾⡿⣟⡿⢿⠷⣟⡿⢿⡟⢅⡱⢏⠎⠀⠀⠗⢁⣀⣀⠤⠤⠒⠒⠉⠉⠁⠀⠀│
│⠀⠀⠀⠀⠸⠇⠀⠀⠀⠁⢴⠋⡩⠊⠀⠗⠋⠁⠉⢺⣷⣎⡱⠮⠔⠒⠊⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
2 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡮⠊⠀⠀⠀⠀⠀⠀⠀⠀⠁⠈⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
└────────────────────────────────────────┘
4 8
sepal_length

20
test/fixtures/iris-lineplots.txt vendored Normal file
View File

@ -0,0 +1,20 @@
IRIS-LINEPLOTS
┌────────────────────────────────────────┐
6.9 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣲⠭⠃⠀⠀│ sepal_width
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⢀⣀⣠⣤⣶⣿⣿⣯⣴⣒⠖⠉⠁│ petal_length
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⢮⣤⣤⣶⣿⣿⣿⠿⠛⠛⠋⠉⠀⠀⠀⠀⠀⠀│ petal_width
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⣴⣷⣿⣿⣿⣿⣿⣿⣟⣟⡂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ species
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⠤⠔⠒⢙⡻⠝⢋⡽⢝⣳⣾⣫⣥⣒⣪⣵⣖⣂⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠀⠀⢀⣉⣟⣻⣿⣻⣿⣿⣿⠿⣿⣿⠿⠟⡢⠒⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣿⣷⣾⣿⡿⣿⡯⠿⠛⠋⠉⠀⣀⠔⠉⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣄⣀⠄│
│⠀⠀⠀⠀⢀⣨⣽⣿⣿⣿⣿⣿⣿⣿⣵⣚⣉⣃⣀⣠⣤⣤⣔⣮⣤⣄⣀⣠⣤⣔⣲⣾⡳⠮⠛⠋⢉⡗⠁⠀│
│⠀⠀⠐⠒⡿⠿⠟⡻⠛⠛⠛⠚⠉⠀⠲⣶⣿⣷⣾⣷⣿⣿⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣶⣷⡇⠀⠀│
│⠀⠀⠀⠀⢱⡠⠊⠀⠀⣤⣤⣶⣿⣿⠿⣿⣿⣿⣿⣿⣟⣿⣿⣟⣟⣉⣉⣝⣛⣫⣭⣥⣤⣤⣔⣒⣒⡃⠀⠀│
│⠀⠀⠀⠀⠀⠁⠀⢀⡀⠀⢯⠒⠉⡠⠔⠡⠤⠮⣤⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣶⣶⣶⣶⣿⣿⠥⠤⠄│
│⠀⠀⠀⠀⣀⣠⣄⣤⣭⣿⣿⣿⣿⣿⣿⣿⣿⣯⣯⣯⣭⣽⣿⣿⣿⣿⣿⣯⣭⣍⡙⠛⠝⠉⠀⠀⠀⠀⠀⠀│
│⠀⠀⠠⠴⠿⢯⠭⠿⠯⣭⣷⡾⠿⠿⠿⣿⢿⡿⡻⠿⡟⠛⢛⣛⠯⠭⠒⠒⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
│⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣄⠀⠀⠀⢀⣀⡠⠤⠔⠒⠊⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│
0 │⠀⠀⢀⣀⣴⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣻⣷⣄⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⡀│
└────────────────────────────────────────┘
4 8
sepal_length

View File

@ -1,4 +1,4 @@
IRIS
IRIS-SCATTER
┌────────────────────────────────────────┐
6.9 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠄⠃⠀⠀│ sepal_width
│⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⡄⠂⠄⠀⠀⠄⠀⠁│ petal_length

View File

@ -1,41 +1,102 @@
# frozen_string_literal: true
require "tempfile"
require 'tempfile'
require_relative '../test_helper'
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
def setup
@stdin = $stdin.dup
$stdin = File.open(File.expand_path("../fixtures/iris.csv", __dir__), "r")
@stderr = $stderr.dup
$stdin = File.open(File.expand_path('../fixtures/iris.csv', __dir__), 'r')
@tmp_file = Tempfile.new
$stderr = @tmp_file
end
def cleanup
$stdin = @stdin
$stderr = @stderr
def teardown
@tmp_file.close
end
def fixture(fname)
File.read(File.expand_path("../fixtures/#{fname}", __dir__))
end
test :scatter do
Tempfile.new do |tmp_file|
$stderr = tmp_file
YouPlot::Command.new(["scatter", "-H", "-d,", "-t", "IRIS"]).run
assert_equal fixture('iris-scatter.txt'), tmp_file.read
end
test :bar do
YouPlot::Command.new(['bar', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
assert_equal fixture('iris-barplot.txt'), @tmp_file.read
end
test :barplot do
Tempfile.new do |tmp_file|
$stderr = tmp_file
YouPlot::Command.new(["barplot", "-H", "-d,", "-t", "IRIS"]).run
assert_equal fixture('iris-bar.txt'), tmp_file.read
end
YouPlot::Command.new(['barplot', '-H', '-d,', '-t', 'IRIS-BARPLOT']).run
assert_equal fixture('iris-barplot.txt'), @tmp_file.read
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