@@ -3,6 +3,15 @@ class BarplotTest < Test::Unit::TestCase
33 include Helper ::WithTerm
44
55 sub_test_case ( "UnicodePlot.barplot" ) do
6+ test ( "errors" ) do
7+ assert_raise ( ArgumentError ) do
8+ UnicodePlot . barplot ( [ :a ] , [ -1 , 2 ] )
9+ end
10+ assert_raise ( ArgumentError ) do
11+ UnicodePlot . barplot ( [ :a , :b ] , [ -1 , 2 ] )
12+ end
13+ end
14+
615 test ( "colored" ) do
716 data = { bar : 23 , foo : 37 }
817 plot = UnicodePlot . barplot ( data : data )
@@ -63,12 +72,75 @@ class BarplotTest < Test::Unit::TestCase
6372 end
6473 end
6574
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+
66124 test ( "ranges" ) do
67125 plot = UnicodePlot . barplot ( 2 ..6 , 11 ..15 )
68126 _ , output = with_term { plot . render ( $stdout) }
69127 assert_equal ( fixture_path ( "barplot/ranges.txt" ) . read ,
70128 output )
71129 end
130+
131+ test ( "all zeros" ) do
132+ plot = UnicodePlot . barplot ( [ 5 , 4 , 3 , 2 , 1 ] , [ 0 , 0 , 0 , 0 , 0 ] )
133+ _ , output = with_term { plot . render ( $stdout) }
134+ assert_equal ( fixture_path ( "barplot/edgecase_zeros.txt" ) . read ,
135+ output )
136+ end
137+
138+ test ( "one large" ) do
139+ plot = UnicodePlot . barplot ( [ :a , :b , :c , :d ] , [ 1 , 1 , 1 , 1000000 ] )
140+ _ , output = with_term { plot . render ( $stdout) }
141+ assert_equal ( fixture_path ( "barplot/edgecase_onelarge.txt" ) . read ,
142+ output )
143+ end
72144 end
73145
74146 sub_test_case ( "UnicodePlot.barplot!" ) do
0 commit comments