Added the Gruff library to the lib/ directory of the the rails folder, and the
[selectricity] / lib / gruff-0.2.8 / test / test_accumulator_bar.rb
1 require File.dirname(__FILE__) + "/gruff_test_case"
2
3 class TestGruffAccumulatorBar < GruffTestCase
4
5   # TODO Delete old output files once when starting tests
6
7   def setup
8     @datasets = [
9       (1..20).to_a.map { rand(10) }
10     ]
11   end
12
13   def test_accumulator
14     g = Gruff::AccumulatorBar.new 500
15     g.title = "Your Savings"
16     g.hide_legend = true
17
18     # g.font = File.expand_path(File.dirname(__FILE__) + "/../assets/fonts/ATMA____.TTF")
19
20     g.marker_font_size = 18
21     
22     g.theme = {
23       :colors => ['#aedaa9', '#12a702'], # 3077a9 blue, aedaa9 light green
24       :marker_color => '#dddddd',
25       :font_color => 'black',      
26       :background_colors => "white"
27       # :background_image => File.expand_path(File.dirname(__FILE__) + "/../assets/backgrounds/43things.png")
28     }
29
30     # Attempt at negative numbers
31     # g.data 'Savings', (1..20).to_a.map { rand(10) * (rand(2) > 0 ? 1 : -1) }
32     g.data 'Savings', (1..12).to_a.map { rand(100) }
33     g.labels = (0..11).to_a.inject({}) {|memo, index| {index => '12-26'}.merge(memo)}
34
35     g.maximum_value = 1000
36     g.minimum_value = 0
37
38     g.write("test/output/accum_bar.png")
39   end
40
41   def test_too_many_args
42     assert_raise(Gruff::IncorrectNumberOfDatasetsException) {
43       g = Gruff::AccumulatorBar.new
44       g.data 'First', [1,1,1]
45       g.data 'Too Many', [1,1,1]
46       g.write("test/output/_SHOULD_NOT_ACTUALLY_BE_WRITTEN.png")
47     }
48   end
49
50 end

Benjamin Mako Hill || Want to submit a patch?