]> projects.mako.cc - selectricity-live/blob - vendor/plugins/attachment_fu/test/geometry_test.rb
improved dependency information
[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_no_height_with_x
27     assert_geometry 50, 64,
28       "50x"  => [50, 64],
29       "60x"  => [60, 77],
30       "100x" => [100, 128]
31   end
32   
33   def test_should_resize_with_percent
34     assert_geometry 50, 64,
35       "50x50%"   => [25, 32],
36       "60x60%"   => [30, 38],
37       "120x112%" => [60, 72]
38   end
39   
40   def test_should_resize_with_percent_and_no_width
41     assert_geometry 50, 64,
42       "x50%"  => [50, 32],
43       "x60%"  => [50, 38],
44       "x112%" => [50, 72]
45   end
46   
47   def test_should_resize_with_percent_and_no_height
48     assert_geometry 50, 64,
49       "50%"  => [25, 32],
50       "60%"  => [30, 38],
51       "120%" => [60, 77]
52   end
53   
54   def test_should_resize_with_less
55     assert_geometry 50, 64,
56       "50x50<"   => [50, 64],
57       "60x60<"   => [50, 64],
58       "100x100<" => [78, 100],
59       "100x112<" => [88, 112],
60       "40x70<"   => [50, 64]
61   end
62   
63   def test_should_resize_with_less_and_no_width
64     assert_geometry 50, 64,
65       "x50<"  => [50, 64],
66       "x60<"  => [50, 64],
67       "x100<" => [78, 100]
68   end
69   
70   def test_should_resize_with_less_and_no_height
71     assert_geometry 50, 64,
72       "50<"  => [50, 64],
73       "60<"  => [60, 77],
74       "100<" => [100, 128]
75   end
76
77   def test_should_resize_with_greater
78     assert_geometry 50, 64,
79       "50x50>"   => [39, 50],
80       "60x60>"   => [47, 60],
81       "100x100>" => [50, 64],
82       "100x112>" => [50, 64],
83       "40x70>"   => [40, 51]
84   end
85   
86   def test_should_resize_with_greater_and_no_width
87     assert_geometry 50, 64,
88       "x40>"  => [31, 40],
89       "x60>"  => [47, 60],
90       "x100>" => [50, 64]
91   end
92   
93   def test_should_resize_with_greater_and_no_height
94     assert_geometry 50, 64,
95       "40>"  => [40, 51],
96       "60>"  => [50, 64],
97       "100>" => [50, 64]
98   end
99
100   protected
101     def assert_geometry(width, height, values)
102       values.each do |geo, result|
103         # run twice to verify the Geometry string isn't modified after a run
104         geo = Geometry.from_s(geo)
105         2.times { assert_equal result, [width, height] / geo }
106       end
107     end
108 end

Benjamin Mako Hill || Want to submit a patch?