3 require File.dirname(__FILE__) + "/gruff_test_case"
5 class TestGruffLine < GruffTestCase
7 # TODO Delete old output files once when starting tests
9 def test_line_graph_with_themes
10 line_graph_with_themes()
11 line_graph_with_themes(400)
23 g.write("test/output/line_one_value.png")
26 def test_one_value_array
28 g.title = "One Value in an Array"
35 g.write("test/output/line_one_value_array.png")
39 def test_should_not_hang_with_0_0_100
40 g = Gruff::Line.new(320)
41 g.title = "Hang Value Graph Test"
42 g.data('test', [0,0,100])
44 g.write("test/output/line_hang_value.png")
49 # g = Gruff::Line.new(370)
50 # g.title = "Crash Test"
55 # g.write("test/output/line_crash_fix_test.png")
59 def test_line_small_values
61 [:small, [0.1, 0.14356, 0.0, 0.5674839, 0.456]],
62 [:small2, [0.2, 0.3, 0.1, 0.05, 0.9]]
66 g.title = "Small Values Line Graph Test"
67 @datasets.each do |data|
68 g.data(data[0], data[1])
70 g.write("test/output/line_small.png")
72 g = Gruff::Line.new(400)
73 g.title = "Small Values Line Graph Test 400px"
74 @datasets.each do |data|
75 g.data(data[0], data[1])
77 g.write("test/output/line_small_small.png")
80 def test_line_starts_with_zero
82 [:first0, [0, 5, 10, 8, 18]],
83 [:normal, [1, 2, 3, 4, 5]]
87 g.title = "Small Values Line Graph Test"
88 @datasets.each do |data|
89 g.data(data[0], data[1])
91 g.write("test/output/line_small_zero.png")
93 g = Gruff::Line.new(400)
94 g.title = "Small Values Line Graph Test 400px"
95 @datasets.each do |data|
96 g.data(data[0], data[1])
98 g.write("test/output/line_small_small_zero.png")
102 def test_line_large_values
104 [:large, [100_005, 35_000, 28_000, 27_000]],
105 [:large2, [35_000, 28_000, 27_000, 100_005]],
106 [:large3, [28_000, 27_000, 100_005, 35_000]],
107 [:large4, [1_238, 39_092, 27_938, 48_876]]
111 g.title = "Very Large Values Line Graph Test"
112 g.baseline_value = 50_000
113 g.baseline_color = 'green'
114 @datasets.each do |data|
115 g.data(data[0], data[1])
118 g.write("test/output/line_large.png")
129 def test_request_too_many_colors
137 def test_many_datapoints
139 g.title = "Many Multi-Line Graph Test"
146 g.data('many points', (0..50).collect {|i| rand(100) })
147 g.x_axis_label = "Months"
150 g.write("test/output/line_many.png")
154 def test_similar_high_end_values
155 @dataset = %w(29.43 29.459 29.498 29.53 29.548 29.589 29.619 29.66 29.689 29.849 29.878 29.74 29.769 29.79 29.808 29.828).collect {|i| i.to_f}
158 g.title = "Similar High End Values Test"
159 g.data('similar points', @dataset )
160 g.write("test/output/line_similar_high_end_values.png")
163 g.title = "Similar High End Values With Floor"
164 g.data('similar points', @dataset )
166 g.y_axis_label = "Barometric Pressure"
167 g.write("test/output/line_similar_high_end_values_with_floor.png")
170 def test_many_lines_graph_small
171 g = Gruff::Line.new(400)
172 g.title = "Many Values Line Test 400px"
181 %w{jimmy jane philip arthur julie bert}.each do |student_name|
182 g.data(student_name, (0..50).collect { |i| rand 100 })
186 g.write("test/output/line_many_lines_small.png")
190 g = Gruff::Line.new(300)
191 g.title = "Tiny Test 300px"
200 %w{jimmy jane philip arthur julie bert}.each do |student_name|
201 g.data(student_name, (0..50).collect { |i| rand 100 })
205 g.write("test/output/line_tiny.png")
209 g = Gruff::Line.new(400)
212 g.write("test/output/line_no_data.png")
214 g = Gruff::Line.new(400)
215 g.title = "No Data Title"
216 g.no_data_message = 'There is no data'
217 g.write("test/output/line_no_data_msg.png")
222 g = Gruff::Line.new(400)
223 g.title = "All Zeros"
225 g.data(:gus, [0,0,0,0])
228 g.write("test/output/line_no_data_other.png")
232 def test_some_nil_points
234 g.title = "Some Nil Points"
237 [:data1, [1, 2, 3, nil, 3, 5, 6]],
238 [:data2, [5, nil, nil, nil, nil, nil, 5]],
239 [:data3, [4, nil, 2, 1, 0]],
240 [:data4, [nil, nil, 3, 1, 2]]
243 @datasets.each do |data|
248 g.write("test/output/line_some_nil_points.png")
252 g = Gruff::Line.new(400)
254 @datasets.each do |data|
255 g.data(data[0], data[1])
258 g.write("test/output/line_no_title.png")
261 def test_no_line_markers
262 g = setup_basic_graph(400)
263 g.title = "No Line Markers"
264 g.hide_line_markers = true
265 g.write("test/output/line_no_line_markers.png")
269 g = setup_basic_graph(400)
270 g.title = "No Legend"
272 g.write("test/output/line_no_legend.png")
275 def test_nothing_but_the_graph
276 g = setup_basic_graph(400)
277 g.title = "THIS TITLE SHOULD NOT DISPLAY!!!"
278 g.hide_line_markers = true
281 g.write("test/output/line_nothing_but_the_graph.png")
284 def test_baseline_larger_than_data
285 g = setup_basic_graph(400)
286 g.title = "Baseline Larger Than Data"
287 g.baseline_value = 150
288 g.write("test/output/line_large_baseline.png")
293 g = setup_basic_graph(400)
294 g.title = "Hide Dots"
296 g.write("test/output/line_hide_dots.png")
300 g = setup_basic_graph(400)
301 g.title = "Hide Lines"
303 g.write("test/output/line_hide_lines.png")
307 g = setup_basic_graph('800x400')
308 g.title = "Wide Graph"
309 g.write("test/output/line_wide_graph.png")
311 g = setup_basic_graph('400x200')
312 g.title = "Wide Graph Small"
313 g.write("test/output/line_wide_graph_small.png")
317 g = setup_pos_neg(800)
318 g.write("test/output/line_pos_neg.png")
320 g = setup_pos_neg(400)
321 g.title = 'Pos/Neg Line Test Small'
322 g.write("test/output/line_pos_neg_400.png")
325 def test_all_negative
326 g = setup_all_neg(800)
327 g.write("test/output/line_all_neg.png")
329 g = setup_all_neg(400)
330 g.title = 'All Neg Line Test Small'
331 g.write("test/output/line_all_neg_400.png")
334 def test_many_numbers
335 g = Gruff::Line.new('400x170')
336 g.title = "Line Test, Many Numbers"
395 [:wpm, :errors, :accuracy].each do |field|
396 g.data(field.to_s, data.collect {|d| d[field] })
400 data.each_with_index do |d, i|
405 g.write('test/output/line_many_numbers.png')
408 def test_no_hide_line_no_labels
410 g.title = "No Hide Line No Labels"
411 @datasets.each do |data|
412 g.data(data[0], data[1])
414 g.hide_line_markers = false
415 g.write('test/output/line_no_hide.png')
420 # TODO Reset data after each theme
421 def line_graph_with_themes(size=nil)
422 g = Gruff::Line.new(size)
423 g.title = "Multi-Line Graph Test #{size}"
425 g.baseline_value = 90
426 @datasets.each do |data|
427 g.data(data[0], data[1])
430 g.write("test/output/line_theme_keynote_#{size}.png")
432 g = Gruff::Line.new(size)
433 g.title = "Multi-Line Graph Test #{size}"
435 g.baseline_value = 90
437 @datasets.each do |data|
438 g.data(data[0], data[1])
440 g.write("test/output/line_theme_37signals_#{size}.png")
443 g = Gruff::Line.new(size)
444 g.title = "Multi-Line Graph Test #{size}"
446 g.baseline_value = 90
447 g.theme_rails_keynote
448 @datasets.each do |data|
449 g.data(data[0], data[1])
451 g.write("test/output/line_theme_rails_keynote_#{size}.png")
453 g = Gruff::Line.new(size)
454 g.title = "Multi-Line Graph Test #{size}"
456 g.baseline_value = 90
458 @datasets.each do |data|
459 g.data(data[0], data[1])
461 g.write("test/output/line_theme_odeo_#{size}.png")
464 def setup_pos_neg(size=800)
465 g = Gruff::Line.new(size)
466 g.title = "Pos/Neg Line Graph Test"
473 g.data(:apples, [-1, 0, 4, -4])
474 g.data(:peaches, [10, 8, 6, 3])
479 def setup_all_neg(size=800)
480 g = Gruff::Line.new(size)
481 g.title = "All Neg Line Graph Test"
488 g.data(:apples, [-1, -5, -20, -4])
489 g.data(:peaches, [-10, -8, -6, -3])