geometry_test.rb
2.74 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
require 'test/unit'
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/geometry')) unless Object.const_defined?(:Geometry)
class GeometryTest < Test::Unit::TestCase
def test_should_resize
assert_geometry 50, 64,
"50x50" => [39, 50],
"60x60" => [47, 60],
"100x100" => [78, 100]
end
def test_should_resize_no_width
assert_geometry 50, 64,
"x50" => [39, 50],
"x60" => [47, 60],
"x100" => [78, 100]
end
def test_should_resize_no_height
assert_geometry 50, 64,
"50" => [50, 64],
"60" => [60, 77],
"100" => [100, 128]
end
def test_should_resize_no_height_with_x
assert_geometry 50, 64,
"50x" => [50, 64],
"60x" => [60, 77],
"100x" => [100, 128]
end
def test_should_resize_with_percent
assert_geometry 50, 64,
"50x50%" => [25, 32],
"60x60%" => [30, 38],
"120x112%" => [60, 72]
end
def test_should_resize_with_percent_and_no_width
assert_geometry 50, 64,
"x50%" => [50, 32],
"x60%" => [50, 38],
"x112%" => [50, 72]
end
def test_should_resize_with_percent_and_no_height
assert_geometry 50, 64,
"50%" => [25, 32],
"60%" => [30, 38],
"120%" => [60, 77]
end
def test_should_resize_with_less
assert_geometry 50, 64,
"50x50<" => [50, 64],
"60x60<" => [50, 64],
"100x100<" => [78, 100],
"100x112<" => [88, 112],
"40x70<" => [50, 64]
end
def test_should_resize_with_less_and_no_width
assert_geometry 50, 64,
"x50<" => [50, 64],
"x60<" => [50, 64],
"x100<" => [78, 100]
end
def test_should_resize_with_less_and_no_height
assert_geometry 50, 64,
"50<" => [50, 64],
"60<" => [60, 77],
"100<" => [100, 128]
end
def test_should_resize_with_greater
assert_geometry 50, 64,
"50x50>" => [39, 50],
"60x60>" => [47, 60],
"100x100>" => [50, 64],
"100x112>" => [50, 64],
"40x70>" => [40, 51]
end
def test_should_resize_with_greater_and_no_width
assert_geometry 50, 64,
"x40>" => [31, 40],
"x60>" => [47, 60],
"x100>" => [50, 64]
end
def test_should_resize_with_greater_and_no_height
assert_geometry 50, 64,
"40>" => [40, 51],
"60>" => [50, 64],
"100>" => [50, 64]
end
def test_should_resize_with_aspect
assert_geometry 50, 64,
"35x35!" => [35, 35],
"70x70!" => [70, 70]
end
protected
def assert_geometry(width, height, values)
values.each do |geo, result|
# run twice to verify the Geometry string isn't modified after a run
geo = Geometry.from_s(geo)
2.times { assert_equal result, [width, height] / geo }
end
end
end