From 7034a83dead332133e8a02fdf758524662a39585 Mon Sep 17 00:00:00 2001 From: kojix2 <2xijok@gmail.com> Date: Mon, 23 Nov 2020 21:31:16 +0900 Subject: [PATCH] Add some basic tests --- test/fixtures/colors.txt | 1 + .../{iris-bar.txt => iris-barplot.txt} | 2 +- test/fixtures/iris-boxplot.txt | 19 ++++ test/fixtures/iris-density.txt | 20 ++++ test/fixtures/iris-histogram.txt | 12 +++ test/fixtures/iris-lineplot.txt | 20 ++++ test/fixtures/iris-lineplots.txt | 20 ++++ test/fixtures/iris-scatter.txt | 2 +- test/uplot/command_test.rb | 99 +++++++++++++++---- 9 files changed, 174 insertions(+), 21 deletions(-) create mode 100644 test/fixtures/colors.txt rename test/fixtures/{iris-bar.txt => iris-barplot.txt} (99%) create mode 100644 test/fixtures/iris-boxplot.txt create mode 100644 test/fixtures/iris-density.txt create mode 100644 test/fixtures/iris-histogram.txt create mode 100644 test/fixtures/iris-lineplot.txt create mode 100644 test/fixtures/iris-lineplots.txt diff --git a/test/fixtures/colors.txt b/test/fixtures/colors.txt new file mode 100644 index 0000000..f4ad866 --- /dev/null +++ b/test/fixtures/colors.txt @@ -0,0 +1 @@ +black ● red ● green ● yellow ● blue ● magenta ● cyan ● white ● gray ● light_black ● light_red ● light_green ● light_yellow ● light_blue ● light_magenta ● light_cyan ● normal ● default ● bold ● underline ● blink ● reverse ● hidden ● nothing ● 0 ● 1 ● 2 ● 3 ● 4 ● 5 ● 6 ● 7 ● 8 ● 9 ● 10 ● 11 ● 12 ● 13 ● 14 ● 15 ● 16 ● 17 ● 18 ● 19 ● 20 ● 21 ● 22 ● 23 ● 24 ● 25 ● 26 ● 27 ● 28 ● 29 ● 30 ● 31 ● 32 ● 33 ● 34 ● 35 ● 36 ● 37 ● 38 ● 39 ● 40 ● 41 ● 42 ● 43 ● 44 ● 45 ● 46 ● 47 ● 48 ● 49 ● 50 ● 51 ● 52 ● 53 ● 54 ● 55 ● 56 ● 57 ● 58 ● 59 ● 60 ● 61 ● 62 ● 63 ● 64 ● 65 ● 66 ● 67 ● 68 ● 69 ● 70 ● 71 ● 72 ● 73 ● 74 ● 75 ● 76 ● 77 ● 78 ● 79 ● 80 ● 81 ● 82 ● 83 ● 84 ● 85 ● 86 ● 87 ● 88 ● 89 ● 90 ● 91 ● 92 ● 93 ● 94 ● 95 ● 96 ● 97 ● 98 ● 99 ● 100 ● 101 ● 102 ● 103 ● 104 ● 105 ● 106 ● 107 ● 108 ● 109 ● 110 ● 111 ● 112 ● 113 ● 114 ● 115 ● 116 ● 117 ● 118 ● 119 ● 120 ● 121 ● 122 ● 123 ● 124 ● 125 ● 126 ● 127 ● 128 ● 129 ● 130 ● 131 ● 132 ● 133 ● 134 ● 135 ● 136 ● 137 ● 138 ● 139 ● 140 ● 141 ● 142 ● 143 ● 144 ● 145 ● 146 ● 147 ● 148 ● 149 ● 150 ● 151 ● 152 ● 153 ● 154 ● 155 ● 156 ● 157 ● 158 ● 159 ● 160 ● 161 ● 162 ● 163 ● 164 ● 165 ● 166 ● 167 ● 168 ● 169 ● 170 ● 171 ● 172 ● 173 ● 174 ● 175 ● 176 ● 177 ● 178 ● 179 ● 180 ● 181 ● 182 ● 183 ● 184 ● 185 ● 186 ● 187 ● 188 ● 189 ● 190 ● 191 ● 192 ● 193 ● 194 ● 195 ● 196 ● 197 ● 198 ● 199 ● 200 ● 201 ● 202 ● 203 ● 204 ● 205 ● 206 ● 207 ● 208 ● 209 ● 210 ● 211 ● 212 ● 213 ● 214 ● 215 ● 216 ● 217 ● 218 ● 219 ● 220 ● 221 ● 222 ● 223 ● 224 ● 225 ● 226 ● 227 ● 228 ● 229 ● 230 ● 231 ● 232 ● 233 ● 234 ● 235 ● 236 ● 237 ● 238 ● 239 ● 240 ● 241 ● 242 ● 243 ● 244 ● 245 ● 246 ● 247 ● 248 ● 249 ● 250 ● 251 ● 252 ● 253 ● 254 ● 255 ● diff --git a/test/fixtures/iris-bar.txt b/test/fixtures/iris-barplot.txt similarity index 99% rename from test/fixtures/iris-bar.txt rename to test/fixtures/iris-barplot.txt index 0a747f2..7f38cb8 100644 --- a/test/fixtures/iris-bar.txt +++ b/test/fixtures/iris-barplot.txt @@ -1,4 +1,4 @@ - sepal_width + IRIS-BARPLOT ┌ ┐ 5.1 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 3.5 4.9 ┤■■■■■■■■■■■■■■■■■■■■■■■■ 3.0 diff --git a/test/fixtures/iris-boxplot.txt b/test/fixtures/iris-boxplot.txt new file mode 100644 index 0000000..2d309a5 --- /dev/null +++ b/test/fixtures/iris-boxplot.txt @@ -0,0 +1,19 @@ + IRIS-BOXPLOT + ┌ ┐ + ╷ ┌──┬──┐ ╷ + sepal_length ├───┤ │ ├───────┤ + ╵ └──┴──┘ ╵ + ╷ ┌┬┐ ╷ + sepal_width ├───┤│├─────┤ + ╵ └┴┘ ╵ + ╷ ┌─────────────┬───┐ ╷ + petal_length ├──┤ │ ├───────┤ + ╵ └─────────────┴───┘ ╵ + ╷┌───┬──┐ ╷ + petal_width ├┤ │ ├──┤ + ╵└───┴──┘ ╵ + ╷ + species ┤ + ╵ + └ ┘ + 0 4 8 diff --git a/test/fixtures/iris-density.txt b/test/fixtures/iris-density.txt new file mode 100644 index 0000000..96ed69f --- /dev/null +++ b/test/fixtures/iris-density.txt @@ -0,0 +1,20 @@ + IRIS-DENSITY + ┌────────────────────────────────────────┐ + 6.9 │ │ sepal_width + │ │ petal_length + │ │ petal_width + │ │ species + │ ░ │ + │ │ + │ ░ │ + │ ░ │ + │ ░ ░ ░░ ░ │ + │ ░ ░ ░ │ + │ │ + │ ░ ░▒ ░ ░ ░ ░ │ + │ ░ ░ ░ │ + │ │ + 0 │ ░░ ▒ ░█ ░ ░▒ ░░ ░ ░░░ ░ │ + └────────────────────────────────────────┘ + 4 8 + sepal_length diff --git a/test/fixtures/iris-histogram.txt b/test/fixtures/iris-histogram.txt new file mode 100644 index 0000000..8ad78ad --- /dev/null +++ b/test/fixtures/iris-histogram.txt @@ -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 diff --git a/test/fixtures/iris-lineplot.txt b/test/fixtures/iris-lineplot.txt new file mode 100644 index 0000000..be27b20 --- /dev/null +++ b/test/fixtures/iris-lineplot.txt @@ -0,0 +1,20 @@ + IRIS-LINEPLOT + ┌────────────────────────────────────────┐ + 5 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠎⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡔⠒⣽⠋⠀⢸⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢣⣼⠇⡠⠠⠊⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⢀⣀⣀⠤⢤⣼⢿⣿⣿⠯⠛⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠤⢊⡧⡺⠁│ + sepal_width │⠀⠀⠀⠀⠀⠈⢑⠦⣺⣵⣿⣿⡝⢵⡠⠆⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡠⠔⣺⠥⢊⠥⠊⠁⡷⠁⠀│ + │⠀⠀⠀⠀⢀⡨⡽⣿⣯⢟⣿⡯⠿⠭⠥⠤⠤⢤⠤⠮⢍⣕⣣⣏⣉⣒⣦⣶⣭⣤⣺⣥⠊⠁⠀⠀⡰⡇⠀⠀│ + │⠀⠀⠀⡠⣗⣭⣞⣿⣾⣟⡇⠀⠀⠀⢀⠤⢊⣁⣰⣣⣾⣟⣥⣾⣿⣽⢿⣿⡿⡿⠛⠉⠓⠢⠤⣴⣁⡇⠀⠀│ + │⠀⠀⠈⠉⡟⠋⠉⡝⠀⠉⠁⠀⠀⠀⠉⢺⣷⣷⢿⣿⣿⣿⣷⣾⣿⣿⣿⣿⣿⣿⣯⢿⡿⢟⡻⠋⠉⡇⠀⠀│ + │⠀⠀⠀⠀⢱⠀⡰⠁⠀⠀⠀⢀⢖⣶⣾⣿⣿⣻⡿⣿⣿⣿⣿⢿⣿⠟⠛⢻⢛⡻⠛⠉⠉⠉⠉⠉⠉⡇⠀⠀│ + │⠀⠀⠀⠀⢸⢠⠃⠀⠀⢔⣶⡾⡿⣟⡿⢿⠷⣟⡿⢿⡟⢅⡱⢏⠎⠀⠀⠗⢁⣀⣀⠤⠤⠒⠒⠉⠉⠁⠀⠀│ + │⠀⠀⠀⠀⠸⠇⠀⠀⠀⠁⢴⠋⡩⠊⠀⠗⠋⠁⠉⢺⣷⣎⡱⠮⠔⠒⠊⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + 2 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡮⠊⠀⠀⠀⠀⠀⠀⠀⠀⠁⠈⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + └────────────────────────────────────────┘ + 4 8 + sepal_length diff --git a/test/fixtures/iris-lineplots.txt b/test/fixtures/iris-lineplots.txt new file mode 100644 index 0000000..2400ed6 --- /dev/null +++ b/test/fixtures/iris-lineplots.txt @@ -0,0 +1,20 @@ + IRIS-LINEPLOTS + ┌────────────────────────────────────────┐ + 6.9 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⣲⠭⠃⠀⠀│ sepal_width + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⢀⣀⣠⣤⣶⣿⣿⣯⣴⣒⠖⠉⠁│ petal_length + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣤⢮⣤⣤⣶⣿⣿⣿⠿⠛⠛⠋⠉⠀⠀⠀⠀⠀⠀│ petal_width + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣤⣴⣷⣿⣿⣿⣿⣿⣿⣟⣟⡂⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ species + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⠤⠔⠒⢙⡻⠝⢋⡽⢝⣳⣾⣫⣥⣒⣪⣵⣖⣂⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠁⠀⠀⢀⣉⣟⣻⣿⣻⣿⣿⣿⠿⣿⣿⠿⠟⡢⠒⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⣤⣿⣷⣾⣿⡿⣿⡯⠿⠛⠋⠉⠀⣀⠔⠉⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣄⣀⠄│ + │⠀⠀⠀⠀⢀⣨⣽⣿⣿⣿⣿⣿⣿⣿⣵⣚⣉⣃⣀⣠⣤⣤⣔⣮⣤⣄⣀⣠⣤⣔⣲⣾⡳⠮⠛⠋⢉⡗⠁⠀│ + │⠀⠀⠐⠒⡿⠿⠟⡻⠛⠛⠛⠚⠉⠀⠲⣶⣿⣷⣾⣷⣿⣿⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣶⣶⣷⡇⠀⠀│ + │⠀⠀⠀⠀⢱⡠⠊⠀⠀⣤⣤⣶⣿⣿⠿⣿⣿⣿⣿⣿⣟⣿⣿⣟⣟⣉⣉⣝⣛⣫⣭⣥⣤⣤⣔⣒⣒⡃⠀⠀│ + │⠀⠀⠀⠀⠀⠁⠀⢀⡀⠀⢯⠒⠉⡠⠔⠡⠤⠮⣤⣴⣿⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣶⣶⣶⣶⣿⣿⠥⠤⠄│ + │⠀⠀⠀⠀⣀⣠⣄⣤⣭⣿⣿⣿⣿⣿⣿⣿⣿⣯⣯⣯⣭⣽⣿⣿⣿⣿⣿⣯⣭⣍⡙⠛⠝⠉⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠠⠴⠿⢯⠭⠿⠯⣭⣷⡾⠿⠿⠿⣿⢿⡿⡻⠿⡟⠛⢛⣛⠯⠭⠒⠒⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + │⠀⠀⠀⠀⠀⠀⠀⠀⣀⣀⣄⠀⠀⠀⢀⣀⡠⠤⠔⠒⠊⠉⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀│ + 0 │⠀⠀⢀⣀⣴⣶⣾⣿⣿⣿⣿⣿⣿⣿⣿⣿⣻⣷⣄⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⣀⡀│ + └────────────────────────────────────────┘ + 4 8 + sepal_length diff --git a/test/fixtures/iris-scatter.txt b/test/fixtures/iris-scatter.txt index 8020adb..6e85680 100644 --- a/test/fixtures/iris-scatter.txt +++ b/test/fixtures/iris-scatter.txt @@ -1,4 +1,4 @@ - IRIS + IRIS-SCATTER ┌────────────────────────────────────────┐ 6.9 │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠄⠃⠀⠀│ sepal_width │⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⠀⠀⠀⠀⠀⠀⠀⡄⠂⠄⠀⠀⠄⠀⠁│ petal_length diff --git a/test/uplot/command_test.rb b/test/uplot/command_test.rb index 1d1a0c1..91a71c5 100644 --- a/test/uplot/command_test.rb +++ b/test/uplot/command_test.rb @@ -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