Added the Gruff library to the lib/ directory of the the rails folder, and the
[selectricity] / lib / gruff-0.2.8 / test / test_area.rb
1 #!/usr/bin/ruby
2
3 require File.dirname(__FILE__) + "/gruff_test_case"
4
5 class TestGruffArea < GruffTestCase
6
7   def setup
8     @datasets = [
9       [:Jimmy, [25, 36, 86, 39, 25, 31, 79, 88]],
10       [:Charles, [80, 54, 67, 54, 68, 70, 90, 95]],
11       [:Julie, [22, 29, 35, 38, 36, 40, 46, 57]],
12       [:Jane, [95, 95, 95, 90, 85, 80, 88, 100]],
13       [:Philip, [90, 34, 23, 12, 78, 89, 98, 88]],
14       ["Arthur", [5, 10, 13, 11, 6, 16, 22, 32]],
15       ]
16     @sample_labels = {
17         0 => '5/6', 
18         1 => '5/15', 
19         2 => '5/24', 
20         3 => '5/30', 
21         4 => '6/4', 
22         5 => '6/12', 
23         6 => '6/21', 
24         7 => '6/28', 
25       }      
26
27   end
28   
29   def test_area_graph
30     g = Gruff::Area.new
31     g.title = "Visual Multi-Area Graph Test"
32     g.labels = {
33       0 => '5/6', 
34       2 => '5/15', 
35       4 => '5/24', 
36       6 => '5/30', 
37     }
38     @datasets.each do |data|
39       g.data(data[0], data[1])
40     end
41
42     # Default theme
43     g.write("test/output/area_keynote.png")
44   end
45   
46   def test_resize
47     g = Gruff::Area.new(400)
48     g.title = "Small Size Multi-Area Graph Test"
49     g.labels = {
50       0 => '5/6', 
51       2 => '5/15', 
52       4 => '5/24', 
53       6 => '5/30', 
54     }
55     @datasets.each do |data|
56       g.data(data[0], data[1])
57     end
58
59     # Default theme
60     g.write("test/output/area_keynote_small.png")
61   end
62   
63   def test_many_datapoints
64     g = Gruff::Area.new
65     g.title = "Many Multi-Area Graph Test"
66     g.labels = {
67       0 => 'June', 
68       10 => 'July', 
69       30 => 'August', 
70       50 => 'September', 
71     }
72     g.data('many points', (0..50).collect {|i| rand(100) })
73
74     # Default theme
75     g.write("test/output/area_many.png")
76   end
77
78   def test_many_areas_graph_small
79     g = Gruff::Area.new(400)
80     g.title = "Many Values Area Test 400px"
81     g.labels = {
82       0 => '5/6', 
83       10 => '5/15', 
84       20 => '5/24', 
85       30 => '5/30', 
86       40 => '6/4', 
87       50 => '6/16'
88     }
89     %w{jimmy jane philip arthur julie bert}.each do |student_name|
90       g.data(student_name, (0..50).collect { |i| rand 100 })
91     end
92
93     # Default theme
94     g.write("test/output/area_many_areas_small.png")
95   end
96
97   def test_area_graph_tiny
98     g = Gruff::Area.new(300)
99     g.title = "Area Test 300px"
100     g.labels = {
101       0 => '5/6', 
102       10 => '5/15', 
103       20 => '5/24', 
104       30 => '5/30', 
105       40 => '6/4', 
106       50 => '6/16'
107     }
108     %w{jimmy jane philip arthur julie bert}.each do |student_name|
109       g.data(student_name, (0..50).collect { |i| rand 100 })
110     end
111
112     # Default theme
113     g.write("test/output/area_tiny.png")
114   end
115
116   def test_wide
117     g = setup_basic_graph('800x400')
118     g.title = "Area Wide"
119     g.write("test/output/area_wide.png")
120   end
121
122 protected
123   
124   def setup_basic_graph(size=800)
125     g = Gruff::Area.new(size)
126     g.title = "My Graph Title"
127     g.labels = @sample_labels
128     @datasets.each do |data|
129       g.data(data[0], data[1])
130     end
131     return g
132   end
133   
134 end

Benjamin Mako Hill || Want to submit a patch?