Added the Gruff library to the lib/ directory of the the rails folder, and the
[selectricity-live] / lib / gruff-0.2.8 / test / test_scene.rb
1 #!/usr/bin/ruby
2
3 require File.dirname(__FILE__) + "/gruff_test_case"
4 require 'yaml'
5
6 class LayerStub < Gruff::Layer; attr_reader :base_dir, :filenames, :selected_filename; end
7
8 class TestGruffScene < GruffTestCase
9
10   def test_hazy
11     g = setup_scene
12     g.weather = "cloudy"
13     g.haze = true
14     g.time = Time.mktime(2006, 7, 4, 4, 35)
15     g.write "test/output/scene_hazy_night.png"
16   end
17
18   def test_stormy_night
19     g = setup_scene
20     g.weather = "stormy"
21     g.time = Time.mktime(2006, 7, 4, 0, 0)
22     g.write "test/output/scene_stormy_night.png"
23   end
24
25
26   def test_not_hazy
27     g = setup_scene
28     g.weather = "cloudy"
29     g.haze = false
30     g.time = Time.mktime(2006, 7, 4, 6, 00)
31     g.write "test/output/scene_not_hazy_day.png"
32   end
33
34   def test_partly_cloudy
35     g = setup_scene
36     g.weather = "partly cloudy"
37     g.haze = false
38     g.time = Time.mktime(2006, 7, 4, 13, 00)
39     g.write "test/output/scene_partly_cloudy_day.png"
40   end
41
42
43   def test_stormy_day
44     g = setup_scene
45     g.weather = "stormy"
46     g.haze = false
47     g.time = Time.mktime(2006, 7, 4, 8, 00)
48     g.write "test/output/scene_stormy_day.png"
49   end
50
51
52   def test_layer
53     l = LayerStub.new(File.expand_path("../assets/city_scene", File.dirname(__FILE__)), "clouds")
54     assert_equal %w(cloudy.png partly_cloudy.png stormy.png), l.filenames
55     
56     l = LayerStub.new(File.expand_path("../assets/city_scene", File.dirname(__FILE__)), "grass")
57     assert_equal 'default.png', l.selected_filename
58     
59     l = LayerStub.new(File.expand_path("../assets/city_scene", File.dirname(__FILE__)), "sky")
60     l.update Time.mktime(2006, 7, 4, 12, 35) # 12:35, July 4, 2006
61     assert_equal '1200.png', l.selected_filename
62
63     l = LayerStub.new(File.expand_path("../assets/city_scene", File.dirname(__FILE__)), "sky")
64     l.update Time.mktime(2006, 7, 4, 0, 0) # 00:00, July 4, 2006
65     assert_equal '0000.png', l.selected_filename
66
67     l = LayerStub.new(File.expand_path("../assets/city_scene", File.dirname(__FILE__)), "sky")
68     l.update Time.mktime(2006, 7, 4, 23, 35) # 23:35, July 4, 2006
69     assert_equal '2000.png', l.selected_filename
70
71     l = LayerStub.new(File.expand_path("../assets/city_scene", File.dirname(__FILE__)), "sky")
72     l.update Time.mktime(2006, 7, 4, 0, 1) # 00:01, July 4, 2006
73     assert_equal '0000.png', l.selected_filename
74
75     l = LayerStub.new(File.expand_path("../assets/city_scene", File.dirname(__FILE__)), "sky")
76     l.update Time.mktime(2006, 7, 4, 2, 0) # 02:00, July 4, 2006
77     assert_equal '0200.png', l.selected_filename
78
79     l = LayerStub.new(File.expand_path("../assets/city_scene", File.dirname(__FILE__)), "sky")
80     l.update Time.mktime(2006, 7, 4, 4, 00) # 04:00, July 4, 2006
81     assert_equal '0400.png', l.selected_filename
82     
83     # TODO Need number_sample folder
84     # l = LayerStub.new(File.expand_path("../assets/city_scene", File.dirname(__FILE__)), "number_sample")
85     # assert_equal %w(1.png 2.png default.png), l.filenames
86     # l.update 3
87     # assert_equal 'default.png', l.selected_filename
88   end
89
90 private
91
92   def setup_scene
93     g = Gruff::Scene.new("500x100", File.expand_path("../assets/city_scene", File.dirname(__FILE__)) )
94     g.layers = %w(background haze sky clouds)
95     g.weather_group = %w(clouds)
96     g.time_group = %w(background sky)
97     g    
98   end
99
100 end

Benjamin Mako Hill || Want to submit a patch?