]> projects.mako.cc - selectricity-live/blob - vendor/plugins/attachment_fu/test/geometry_test.rb
scrollbar appears if two many electons on control panel. ooks pretty nasty.
[selectricity-live] / vendor / plugins / attachment_fu / test / geometry_test.rb
1 require 'test/unit'
2 require File.expand_path(File.join(File.dirname(__FILE__), '../lib/geometry')) unless Object.const_defined?(:Geometry)
3
4 class GeometryTest < Test::Unit::TestCase
5   def test_should_resize
6     assert_geometry 50, 64,
7       "50x50"   => [39, 50],
8       "60x60"   => [47, 60],
9       "100x100" => [78, 100]
10   end
11   
12   def test_should_resize_no_width
13     assert_geometry 50, 64,
14       "x50"  => [39, 50],
15       "x60"  => [47, 60],
16       "x100" => [78, 100]
17   end
18   
19   def test_should_resize_no_height
20     assert_geometry 50, 64,
21       "50"  => [50, 64],
22       "60"  => [60, 77],
23       "100" => [100, 128]
24   end
25   
26   def test_should_resize_with_percent
27     assert_geometry 50, 64,
28       "50x50%"   => [25, 32],
29       "60x60%"   => [30, 38],
30       "120x112%" => [60, 72]
31   end
32   
33   def test_should_resize_with_percent_and_no_width
34     assert_geometry 50, 64,
35       "x50%"  => [50, 32],
36       "x60%"  => [50, 38],
37       "x112%" => [50, 72]
38   end
39   
40   def test_should_resize_with_percent_and_no_height
41     assert_geometry 50, 64,
42       "50%"  => [25, 32],
43       "60%"  => [30, 38],
44       "120%" => [60, 77]
45   end
46   
47   def test_should_resize_with_less
48     assert_geometry 50, 64,
49       "50x50<"   => [50, 64],
50       "60x60<"   => [50, 64],
51       "100x100<" => [78, 100],
52       "100x112<" => [88, 112],
53       "40x70<"   => [50, 64]
54   end
55   
56   def test_should_resize_with_less_and_no_width
57     assert_geometry 50, 64,
58       "x50<"  => [50, 64],
59       "x60<"  => [50, 64],
60       "x100<" => [78, 100]
61   end
62   
63   def test_should_resize_with_less_and_no_height
64     assert_geometry 50, 64,
65       "50<"  => [50, 64],
66       "60<"  => [60, 77],
67       "100<" => [100, 128]
68   end
69
70   def test_should_resize_with_greater
71     assert_geometry 50, 64,
72       "50x50>"   => [39, 50],
73       "60x60>"   => [47, 60],
74       "100x100>" => [50, 64],
75       "100x112>" => [50, 64],
76       "40x70>"   => [40, 51]
77   end
78   
79   def test_should_resize_with_greater_and_no_width
80     assert_geometry 50, 64,
81       "x40>"  => [31, 40],
82       "x60>"  => [47, 60],
83       "x100>" => [50, 64]
84   end
85   
86   def test_should_resize_with_greater_and_no_height
87     assert_geometry 50, 64,
88       "40>"  => [40, 51],
89       "60>"  => [50, 64],
90       "100>" => [50, 64]
91   end
92
93   protected
94     def assert_geometry(width, height, values)
95       values.each do |geo, result|
96         # run twice to verify the Geometry string isn't modified after a run
97         geo = Geometry.from_s(geo)
98         2.times { assert_equal result, [width, height] / geo }
99       end
100     end
101 end

Benjamin Mako Hill || Want to submit a patch?