Skip to content

Commit 888a073

Browse files
committed
Add test cases of barplot
1 parent 3cdcf87 commit 888a073

4 files changed

Lines changed: 72 additions & 0 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
 Relative sizes of cities
2+
 ┌ ┐
3+
Paris ┤■■■■■■ 2.244  
4+
New York ┤■■■■■■■■■■■■■■■■■■■■■■■ 8.406  
5+
Moskau ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 11.92  
6+
Madrid ┤■■■■■■■■■ 3.165  
7+
 └ ┘
8+
 population [in mil]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
 Relative sizes of cities
2+
 ┌ ┐
3+
 ┤■■■■■■ 2.244  
4+
 ┤■■■■■■■■■■■■■■■■■■■■■■■ 8.406  
5+
 ┤■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■■ 11.92  
6+
 ┤■■■■■■■■■ 3.165  
7+
 └ ┘
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
 Relative sizes of cities
2+
 ┌────────────────────────────────────────────────────────────┐
3+
Paris │========== 2.244 │
4+
New York │===================================== 8.406 │
5+
Moskau │===================================================== 11.92 │
6+
Madrid │============== 3.165 │
7+
 └────────────────────────────────────────────────────────────┘
8+
 population [in mil]

test/test-barplot.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,55 @@ class BarplotTest < Test::Unit::TestCase
7272
end
7373
end
7474

75+
sub_test_case("with parameters") do
76+
test("parameters1") do
77+
plot = UnicodePlot.barplot(
78+
["Paris", "New York", "Moskau", "Madrid"],
79+
[2.244, 8.406, 11.92, 3.165],
80+
title: "Relative sizes of cities",
81+
xlabel: "population [in mil]",
82+
color: :blue,
83+
margin: 7,
84+
padding: 3
85+
)
86+
_, output = with_term { plot.render($stdout) }
87+
assert_equal(fixture_path("barplot/parameters1.txt").read,
88+
output)
89+
end
90+
91+
test("parameters1_nolabels") do
92+
plot = UnicodePlot.barplot(
93+
["Paris", "New York", "Moskau", "Madrid"],
94+
[2.244, 8.406, 11.92, 3.165],
95+
title: "Relative sizes of cities",
96+
xlabel: "population [in mil]",
97+
color: :blue,
98+
margin: 7,
99+
padding: 3,
100+
labels: false
101+
)
102+
_, output = with_term { plot.render($stdout) }
103+
assert_equal(fixture_path("barplot/parameters1_nolabels.txt").read,
104+
output)
105+
end
106+
107+
test("parameters2") do
108+
plot = UnicodePlot.barplot(
109+
["Paris", "New York", "Moskau", "Madrid"],
110+
[2.244, 8.406, 11.92, 3.165],
111+
title: "Relative sizes of cities",
112+
xlabel: "population [in mil]",
113+
color: :yellow,
114+
border: :solid,
115+
symbol: "=",
116+
width: 60
117+
)
118+
_, output = with_term { plot.render($stdout) }
119+
assert_equal(fixture_path("barplot/parameters2.txt").read,
120+
output)
121+
end
122+
end
123+
75124
test("ranges") do
76125
plot = UnicodePlot.barplot(2..6, 11..15)
77126
_, output = with_term { plot.render($stdout) }

0 commit comments

Comments
 (0)