test/bar_test.rb in gruff-0.1.1 vs test/bar_test.rb in gruff-0.1.2

- old
+ new

@@ -1,15 +1,11 @@ #!/usr/bin/ruby -$:.unshift(File.dirname(__FILE__) + "/../lib/") -#$:.unshift File.dirname(__FILE__) + "/fixtures/helpers" +require File.dirname(__FILE__) + "/gruff_test_case" -require 'test/unit' -require 'gruff' +class TestGruffBar < GruffTestCase -class TestGruffBar < Test::Unit::TestCase - # TODO Delete old output files once when starting tests def setup @datasets = [ [:Jimmy, [25, 36, 86, 39]], @@ -74,10 +70,12 @@ 3 => '5/30', } g.data(:Art, [0, 5, 8, 15], '#990000') g.data(:Philosophy, [10, 3, 2, 8], '#009900') g.data(:Science, [2, 15, 8, 11], '#990099') + + g.minimum_value = 0 g.write("test/output/bar_manual_colors.png") end def test_bar_graph_small @@ -94,27 +92,11 @@ end g.write("test/output/bar_keynote_small.png") end - def test_bar_image_bg - g = setup_basic_graph() - g.title = "With Image Background" - g.theme_image_based - g.write("test/output/bar_image.png") - g = setup_basic_graph(400) - g.title = "With Image Background Small" - g.theme_image_based - g.write("test/output/bar_image_small.png") - - g = setup_basic_graph('800x400') - g.title = "With Image Background Small" - g.theme_image_based - g.write("test/output/bar_image_wide.png") - end - def test_nil_font g = setup_basic_graph 400 g.title = "Nil Font" g.font = nil g.write "test/output/bar_nil_font.png" @@ -137,10 +119,23 @@ g.title = "Wide Graph Small" g.write("test/output/bar_wide_graph_small.png") end + def test_one_value + g = Gruff::Bar.new + g.title = "One Value Graph Test" + g.labels = { + 0 => '1', + 1 => '2' + } + g.data('one', [1,1]) + + g.write("test/output/bar_one_value.png") + end + + def test_negative g = Gruff::Bar.new g.title = "Pos/Neg Bar Graph Test" g.labels = { 0 => '5/6', @@ -153,10 +148,54 @@ g.write("test/output/bar_pos_neg.png") end + def test_nearly_zero + g = Gruff::Bar.new + g.title = "Nearly Zero Graph" + g.labels = { + 0 => '5/6', + 1 => '5/15', + 2 => '5/24', + 3 => '5/30', + } + g.data(:apples, [1, 2, 3, 4]) + g.data(:peaches, [4, 3, 2, 1]) + g.minimum_value = 0 + g.maximum_value = 10 + g.write("test/output/bar_nearly_zero.png") + end + + + def test_custom_theme + g = Gruff::Bar.new + g.title = "Custom Theme" + g.title_font_size = 60 + g.legend_font_size = 32 + g.marker_font_size = 32 + g.theme = { + :colors => %w(#efd250 #666699 #e5573f #9595e2), + :marker_color => 'white', + :background_image => "assets/pc306715.jpg" + } + g.labels = { + 0 => '5/6', + 1 => '5/15', + 2 => '5/24', + 3 => '5/30', + } + g.data(:vancouver, [1, 2, 3, 4]) + g.data(:seattle, [2, 4, 6, 8]) + g.data(:portland, [3, 1, 7, 3]) + g.data(:victoria, [4, 3, 5, 7]) + g.minimum_value = 0 + g.write("test/output/bar_themed.png") + end + + + protected def setup_basic_graph(size=800) g = Gruff::Bar.new(size) g.title = "My Bar Graph" @@ -173,24 +212,5 @@ end end -class Gruff::Base - # A color scheme from the colors used on the 2005 Rails keynote presentation at RubyConf. - def theme_image_based - reset_themes() - # Colors - @green = '#00ff00' - @grey = '#333333' - @orange = '#ff5d00' - @red = '#f61100' - @white = 'white' - @light_grey = '#999999' - @black = 'black' - @colors = [@green, @grey, @orange, @red, @white, @light_grey, @black] - - @marker_color = 'white' - - @base_image = render_image_background('assets/pc306715.jpg') - end -end