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