Skip to content

Commit 1a5e054

Browse files
committed
Check border type
[Fix GH-41]
1 parent a4bbdcc commit 1a5e054

7 files changed

Lines changed: 54 additions & 1 deletion

File tree

lib/unicode_plot/plot.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def initialize(title: nil,
1717
@title = title
1818
@xlabel = xlabel
1919
@ylabel = ylabel
20-
@border = border
20+
@border = check_border(border)
2121
@margin = check_margin(margin)
2222
@padding = padding
2323
@labels_left = {}
@@ -142,5 +142,10 @@ def to_s
142142
raise ArgumentError, "row_index out of bounds"
143143
end
144144
end
145+
146+
private def check_border(border)
147+
return border if BORDER_MAP.key?(border)
148+
raise ArgumentError, "unknown border type: #{border}"
149+
end
145150
end
146151
end

test/test-barplot.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ class BarplotTest < Test::Unit::TestCase
1212
end
1313
end
1414

15+
sub_test_case("with invalid arguments") do
16+
test("unknown border type") do
17+
assert_raise(ArgumentError.new("unknown border type: invalid_border_name")) do
18+
UnicodePlot.barplot(data: {bar: 23, foo: 37}, border: :invalid_border_name)
19+
end
20+
end
21+
end
22+
1523
test("colored") do
1624
data = { bar: 23, foo: 37 }
1725
plot = UnicodePlot.barplot(data: data)

test/test-boxplot.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ class BoxplotTest < Test::Unit::TestCase
33
include Helper::WithTerm
44

55
sub_test_case("UnicodePlot.boxplot") do
6+
sub_test_case("with invalid arguments") do
7+
test("unknown border type") do
8+
assert_raise(ArgumentError.new("unknown border type: invalid_border_name")) do
9+
UnicodePlot.boxplot([1, 2, 3, 4, 5], border: :invalid_border_name)
10+
end
11+
end
12+
end
13+
614
sub_test_case("print to tty") do
715
test("without name") do
816
plot = UnicodePlot.boxplot([1, 2, 3, 4, 5])

test/test-densityplot.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ def setup
1010
assert_equal(1000, @dy.length)
1111
end
1212

13+
sub_test_case("with invalid arguments") do
14+
test("unknown border type") do
15+
assert_raise(ArgumentError.new("unknown border type: invalid_border_name")) do
16+
UnicodePlot.densityplot(@dx, @dy, border: :invalid_border_name)
17+
end
18+
end
19+
end
20+
1321
test("default") do
1422
plot = UnicodePlot.densityplot(@dx, @dy)
1523
dx2 = @dx.map {|x| x + 2 }

test/test-histogram.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ def setup
77
@x = fixture_path("randn.txt").read.lines.map(&:to_f)
88
end
99

10+
sub_test_case("with invalid arguments") do
11+
test("unknown border type") do
12+
assert_raise(ArgumentError.new("unknown border type: invalid_border_name")) do
13+
UnicodePlot.histogram(@x, border: :invalid_border_name)
14+
end
15+
end
16+
end
17+
1018
test("default") do
1119
plot = UnicodePlot.histogram(@x)
1220
_, output = with_term { plot.render($stdout) }

test/test-lineplot.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ def setup
2323
assert_raise(ArgumentError) { UnicodePlot.lineplot(1..3, 1..2) }
2424
end
2525

26+
sub_test_case("with invalid arguments") do
27+
test("unknown border type") do
28+
assert_raise(ArgumentError.new("unknown border type: invalid_border_name")) do
29+
UnicodePlot.lineplot(@x, @y, border: :invalid_border_name)
30+
end
31+
end
32+
end
33+
2634
sub_test_case("with numeric array") do
2735
test("default") do
2836
plot = UnicodePlot.lineplot(@x, @y)

test/test-scatterplot.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ def setup
2222
end
2323
end
2424

25+
sub_test_case("with invalid arguments") do
26+
test("unknown border type") do
27+
assert_raise(ArgumentError.new("unknown border type: invalid_border_name")) do
28+
UnicodePlot.scatterplot(@x, @y, border: :invalid_border_name)
29+
end
30+
end
31+
end
32+
2533
test("default") do
2634
plot = UnicodePlot.scatterplot(@x, @y)
2735
_, output = with_term { plot.render($stdout, newline: false) }

0 commit comments

Comments
 (0)