@@ -3,30 +3,37 @@ class BarplotTest < Test::Unit::TestCase
33 include Helper ::WithTerm
44
55 sub_test_case ( "UnicodePlot.barplot" ) do
6- sub_test_case ( "print to tty" ) do
7- test ( "the output is colored" ) do
8- data = { bar : 23 , foo : 37 }
9- plot = UnicodePlot . barplot ( data : data )
10- _ , output = with_term do
11- plot . render ( $stdout)
12- end
13- assert_equal ( fixture_path ( "barplot/default.txt" ) . read ,
14- output )
15- end
6+ test ( "colored" ) do
7+ data = { bar : 23 , foo : 37 }
8+ plot = UnicodePlot . barplot ( data : data )
9+ _ , output = with_term { plot . render ( $stdout) }
10+ assert_equal ( fixture_path ( "barplot/default.txt" ) . read ,
11+ output )
12+
13+ plot = UnicodePlot . barplot ( [ :bar , :foo ] , [ 23 , 37 ] )
14+ _ , output = with_term { plot . render ( $stdout) }
15+ assert_equal ( fixture_path ( "barplot/default.txt" ) . read ,
16+ output )
1617 end
1718
18- sub_test_case ( "print to non-tty IO" ) do
19- test ( "the output is not colored" ) do
20- data = { bar : 23 , foo : 37 }
21- plot = UnicodePlot . barplot ( data : data )
22- output = StringIO . open do |sio |
23- sio . print ( plot )
24- sio . close
25- sio . string
26- end
27- assert_equal ( fixture_path ( "barplot/nocolor.txt" ) . read ,
28- output )
19+ test ( "not colored" ) do
20+ data = { bar : 23 , foo : 37 }
21+ plot = UnicodePlot . barplot ( data : data )
22+ output = StringIO . open do |sio |
23+ sio . print ( plot )
24+ sio . close
25+ sio . string
2926 end
27+ assert_equal ( fixture_path ( "barplot/nocolor.txt" ) . read ,
28+ output )
29+ end
30+
31+ test ( "mixed" ) do
32+ data = { bar : 23.0 , 2.1 => 10 , foo : 37.0 }
33+ plot = UnicodePlot . barplot ( data : data )
34+ _ , output = with_term { plot . render ( $stdout) }
35+ assert_equal ( fixture_path ( "barplot/default_mixed.txt" ) . read ,
36+ output )
3037 end
3138
3239 sub_test_case ( "xscale: :log10" ) do
@@ -55,5 +62,57 @@ class BarplotTest < Test::Unit::TestCase
5562 output )
5663 end
5764 end
65+
66+ test ( "ranges" ) do
67+ plot = UnicodePlot . barplot ( 2 ..6 , 11 ..15 )
68+ _ , output = with_term { plot . render ( $stdout) }
69+ assert_equal ( fixture_path ( "barplot/ranges.txt" ) . read ,
70+ output )
71+ end
72+ end
73+
74+ sub_test_case ( "UnicodePlot.barplot!" ) do
75+ test ( "errors" ) do
76+ plot = UnicodePlot . barplot ( [ :bar , :foo ] , [ 23 , 37 ] )
77+ assert_raise ( ArgumentError ) do
78+ UnicodePlot . barplot! ( plot , [ "zoom" ] , [ 90 , 80 ] )
79+ end
80+ assert_raise ( ArgumentError ) do
81+ UnicodePlot . barplot! ( plot , [ "zoom" , "boom" ] , [ 90 ] )
82+ end
83+ UnicodePlot . barplot! ( plot , "zoom" , 90.1 )
84+ end
85+
86+ test ( "return value" ) do
87+ plot = UnicodePlot . barplot ( [ :bar , :foo ] , [ 23 , 37 ] )
88+ assert_same ( plot ,
89+ UnicodePlot . barplot! ( plot , [ "zoom" ] , [ 90 ] ) )
90+ _ , output = with_term { plot . render ( $stdout) }
91+ assert_equal ( fixture_path ( "barplot/default2.txt" ) . read ,
92+ output )
93+
94+ plot = UnicodePlot . barplot ( [ :bar , :foo ] , [ 23 , 37 ] )
95+ assert_same ( plot ,
96+ UnicodePlot . barplot! ( plot , "zoom" , 90 ) )
97+ _ , output = with_term { plot . render ( $stdout) }
98+ assert_equal ( fixture_path ( "barplot/default2.txt" ) . read ,
99+ output )
100+
101+ plot = UnicodePlot . barplot ( [ :bar , :foo ] , [ 23 , 37 ] )
102+ assert_same ( plot ,
103+ UnicodePlot . barplot! ( plot , data : { zoom : 90 } ) )
104+ _ , output = with_term { plot . render ( $stdout) }
105+ assert_equal ( fixture_path ( "barplot/default2.txt" ) . read ,
106+ output )
107+ end
108+
109+ test ( "ranges" ) do
110+ plot = UnicodePlot . barplot ( 2 ..6 , 11 ..15 )
111+ assert_same ( plot ,
112+ UnicodePlot . barplot! ( plot , 9 ..10 , 20 ..21 ) )
113+ _ , output = with_term { plot . render ( $stdout) }
114+ assert_equal ( fixture_path ( "barplot/ranges2.txt" ) . read ,
115+ output )
116+ end
58117 end
59118end
0 commit comments