chunky_png 1.0.0.rc1 → 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
@@ -182,6 +182,14 @@ describe ChunkyPNG::Canvas::Operations do
182
182
  subject.rotate_left.should == ChunkyPNG::Canvas.new(3, 2, [2, 4, 6, 1, 3, 5] )
183
183
  end
184
184
 
185
+ it "should not return itself" do
186
+ subject.rotate_left.should_not equal(subject)
187
+ end
188
+
189
+ it "should not change the image dimensions" do
190
+ lambda { subject.rotate_left }.should_not change(subject, :dimension)
191
+ end
192
+
185
193
  it "it should rotate 180 degrees when applied twice" do
186
194
  subject.rotate_left.rotate_left.should == subject.rotate_180
187
195
  end
@@ -194,12 +202,35 @@ describe ChunkyPNG::Canvas::Operations do
194
202
  subject.rotate_left.rotate_left.rotate_left.rotate_left.should == subject
195
203
  end
196
204
  end
205
+
206
+ describe '#rotate_left!' do
207
+ it "should rotate the pixels 90 degrees clockwise" do
208
+ subject.rotate_left!
209
+ subject.should == ChunkyPNG::Canvas.new(3, 2, [2, 4, 6, 1, 3, 5] )
210
+ end
211
+
212
+ it "should return itself" do
213
+ subject.rotate_left!.should equal(subject)
214
+ end
215
+
216
+ it "should change the image dimensions" do
217
+ lambda { subject.rotate_left! }.should change(subject, :dimension).from(ChunkyPNG::Dimension('2x3')).to(ChunkyPNG::Dimension('3x2'))
218
+ end
219
+ end
197
220
 
198
221
  describe '#rotate_right' do
199
222
  it "should rotate the pixels 90 degrees clockwise" do
200
223
  subject.rotate_right.should == ChunkyPNG::Canvas.new(3, 2, [5, 3, 1, 6, 4, 2] )
201
224
  end
202
225
 
226
+ it "should not return itself" do
227
+ subject.rotate_right.should_not equal(subject)
228
+ end
229
+
230
+ it "should not change the image dimensions" do
231
+ lambda { subject.rotate_right }.should_not change(subject, :dimension)
232
+ end
233
+
203
234
  it "it should rotate 180 degrees when applied twice" do
204
235
  subject.rotate_right.rotate_right.should == subject.rotate_180
205
236
  end
@@ -212,6 +243,21 @@ describe ChunkyPNG::Canvas::Operations do
212
243
  subject.rotate_right.rotate_right.rotate_right.rotate_right.should == subject
213
244
  end
214
245
  end
246
+
247
+ describe '#rotate_right!' do
248
+ it "should rotate the pixels 90 degrees clockwise" do
249
+ subject.rotate_right!
250
+ subject.should == ChunkyPNG::Canvas.new(3, 2, [5, 3, 1, 6, 4, 2] )
251
+ end
252
+
253
+ it "should return itself" do
254
+ subject.rotate_right!.should equal(subject)
255
+ end
256
+
257
+ it "should change the image dimensions" do
258
+ lambda { subject.rotate_right! }.should change(subject, :dimension).from(ChunkyPNG::Dimension('2x3')).to(ChunkyPNG::Dimension('3x2'))
259
+ end
260
+ end
215
261
 
216
262
  describe '#rotate_180' do
217
263
  it "should rotate the pixels 180 degrees" do
@@ -27,5 +27,38 @@ describe ChunkyPNG::Canvas::Resampling do
27
27
  it "should downscale the x-axis and upscale the y-axis of the image" do
28
28
  subject.resample_nearest_neighbor(20, 50).should == reference_canvas('clock_nn_xdown_yup')
29
29
  end
30
+
31
+ it "should not return itself" do
32
+ subject.resample_nearest_neighbor(1, 1).should_not equal(subject)
33
+ end
34
+
35
+ it "should not change the original image's dimensions" do
36
+ lambda { subject.resample_nearest_neighbor(1, 1) }.should_not change(subject, :dimension)
37
+ end
38
+ end
39
+
40
+ describe '#resample_nearest_neighbor!' do
41
+ it "should upscale both axis of the image" do
42
+ subject.resample_nearest_neighbor!(45, 45)
43
+ subject.should == reference_canvas('clock_nn_xup_yup')
44
+ end
45
+
46
+ it "should downscale both axis of the image" do
47
+ subject.resample_nearest_neighbor!(12, 12)
48
+ subject.should == reference_canvas('clock_nn_xdown_ydown')
49
+ end
50
+
51
+ it "should downscale the x-axis and upscale the y-axis of the image" do
52
+ subject.resample_nearest_neighbor!(20, 50)
53
+ subject.should == reference_canvas('clock_nn_xdown_yup')
54
+ end
55
+
56
+ it "should return itself" do
57
+ subject.resample_nearest_neighbor!(1, 1).should equal(subject)
58
+ end
59
+
60
+ it "should change the original image's dimensions" do
61
+ lambda { subject.resample_nearest_neighbor!(1, 1) }.should change(subject, :dimension).to(ChunkyPNG::Dimension('1x1'))
62
+ end
30
63
  end
31
64
  end
@@ -16,17 +16,17 @@ end
16
16
  describe 'ChunkyPNG.Dimension' do
17
17
  subject { ChunkyPNG::Dimension.new(1, 2) }
18
18
 
19
- it "should create a point from a 2-item array" do
19
+ it "should create a dimension from a 2-item array" do
20
20
  ChunkyPNG::Dimension([1, 2]).should == subject
21
21
  ChunkyPNG::Dimension(['1', '2']).should == subject
22
22
  end
23
23
 
24
- it "should create a point from a hash with x and y keys" do
24
+ it "should create a dimension from a hash with x and y keys" do
25
25
  ChunkyPNG::Dimension(:width => 1, :height => 2).should == subject
26
26
  ChunkyPNG::Dimension('width' => '1', 'height' => '2').should == subject
27
27
  end
28
28
 
29
- it "should create a point from a point-like string" do
29
+ it "should create a dimension from a point-like string" do
30
30
  [
31
31
  ChunkyPNG::Dimension('1,2'),
32
32
  ChunkyPNG::Dimension('1 2'),
@@ -36,8 +36,13 @@ describe 'ChunkyPNG.Dimension' do
36
36
  ].all? { |point| point == subject }
37
37
  end
38
38
 
39
+ it "should create a dimension from an object that responds to width and height" do
40
+ mock_object = mock('Some object with width and height', :width => 1, :height => 2)
41
+ ChunkyPNG::Dimension(mock_object).should == subject
42
+ end
43
+
39
44
  it "should raise an exception if the input is not understood" do
40
- lambda { ChunkyPNG::Dimension(Object.new) }.should raise_error(ChunkyPNG::ExpectationFailed)
41
- lambda { ChunkyPNG::Dimension(1, 2, 3) }.should raise_error(ChunkyPNG::ExpectationFailed)
45
+ lambda { ChunkyPNG::Dimension(Object.new) }.should raise_error(ArgumentError)
46
+ lambda { ChunkyPNG::Dimension(1, 2, 3) }.should raise_error(ArgumentError)
42
47
  end
43
48
  end
@@ -64,8 +64,13 @@ describe 'ChunkyPNG.Point' do
64
64
  ].all? { |point| point == subject }
65
65
  end
66
66
 
67
+ it "should create a point from an object that responds to x and y" do
68
+ mock_object = mock('Some object with x and y', :x => 1, :y => 2)
69
+ ChunkyPNG::Point(mock_object).should == subject
70
+ end
71
+
67
72
  it "should raise an exception if the input is not understood" do
68
- lambda { ChunkyPNG::Point(Object.new) }.should raise_error(ChunkyPNG::ExpectationFailed)
69
- lambda { ChunkyPNG::Point(1, 2, 3) }.should raise_error(ChunkyPNG::ExpectationFailed)
73
+ lambda { ChunkyPNG::Point(Object.new) }.should raise_error(ArgumentError)
74
+ lambda { ChunkyPNG::Point(1, 2, 3) }.should raise_error(ArgumentError)
70
75
  end
71
76
  end
@@ -1,39 +1,85 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe ChunkyPNG::Vector do
4
- subject { ChunkyPNG::Vector.new([ChunkyPNG::Point.new(2, 4), ChunkyPNG::Point.new(1, 2), ChunkyPNG::Point.new(3, 6)]) }
4
+ subject { ChunkyPNG::Vector.new([ChunkyPNG::Point.new(2, 5), ChunkyPNG::Point.new(1, 3), ChunkyPNG::Point.new(4, 6)]) }
5
5
 
6
6
  it { should respond_to(:points) }
7
7
  it { should have(3).items }
8
8
 
9
9
  describe '#x_range' do
10
10
  it "should get the right range of x values" do
11
- subject.x_range.should == (1..3)
11
+ subject.x_range.should == (1..4)
12
+ end
13
+
14
+ it "should find the minimum x-coordinate" do
15
+ subject.min_x.should == 1
16
+ end
17
+
18
+ it "should find the maximum x-coordinate" do
19
+ subject.max_x.should == 4
20
+ end
21
+
22
+ it "should calculate the width correctly" do
23
+ subject.width.should == 4
12
24
  end
13
25
  end
14
26
 
15
27
  describe '#y_range' do
16
28
  it "should get the right range of y values" do
17
- subject.y_range.should == (2..6)
29
+ subject.y_range.should == (3..6)
30
+ end
31
+
32
+ it "should find the minimum x-coordinate" do
33
+ subject.min_y.should == 3
34
+ end
35
+
36
+ it "should find the maximum x-coordinate" do
37
+ subject.max_y.should == 6
38
+ end
39
+
40
+ it "should calculate the height correctly" do
41
+ subject.height.should == 4
42
+ end
43
+ end
44
+
45
+ describe '#offset' do
46
+ it "should return a ChunkyPNG::Point" do
47
+ subject.offset.should be_kind_of(ChunkyPNG::Point)
48
+ end
49
+
50
+ it "should use the mininum x and y coordinates as values for the point" do
51
+ subject.offset.x.should == subject.min_x
52
+ subject.offset.y.should == subject.min_y
53
+ end
54
+ end
55
+
56
+ describe '#dimension' do
57
+ it "should return a ChunkyPNG::Dimension" do
58
+ subject.dimension.should be_kind_of(ChunkyPNG::Dimension)
59
+ end
60
+
61
+ it "should use the width and height of the vector for the dimension" do
62
+ subject.dimension.width.should == subject.width
63
+ subject.dimension.height.should == subject.height
18
64
  end
19
65
  end
20
66
 
21
67
  describe '#edges' do
22
68
  it "should get three edges when closing the path" do
23
- subject.edges(true).to_a.should == [[ChunkyPNG::Point.new(2, 4), ChunkyPNG::Point.new(1, 2)],
24
- [ChunkyPNG::Point.new(1, 2), ChunkyPNG::Point.new(3, 6)],
25
- [ChunkyPNG::Point.new(3, 6), ChunkyPNG::Point.new(2, 4)]]
69
+ subject.edges(true).to_a.should == [[ChunkyPNG::Point.new(2, 5), ChunkyPNG::Point.new(1, 3)],
70
+ [ChunkyPNG::Point.new(1, 3), ChunkyPNG::Point.new(4, 6)],
71
+ [ChunkyPNG::Point.new(4, 6), ChunkyPNG::Point.new(2, 5)]]
26
72
  end
27
73
 
28
74
  it "should get two edges when not closing the path" do
29
- subject.edges(false).to_a.should == [[ChunkyPNG::Point.new(2, 4), ChunkyPNG::Point.new(1, 2)],
30
- [ChunkyPNG::Point.new(1, 2), ChunkyPNG::Point.new(3, 6)]]
75
+ subject.edges(false).to_a.should == [[ChunkyPNG::Point.new(2, 5), ChunkyPNG::Point.new(1, 3)],
76
+ [ChunkyPNG::Point.new(1, 3), ChunkyPNG::Point.new(4, 6)]]
31
77
  end
32
78
  end
33
79
  end
34
80
 
35
81
  describe 'ChunkyPNG.Vector' do
36
- subject { ChunkyPNG::Vector.new([ChunkyPNG::Point.new(2, 4), ChunkyPNG::Point.new(1, 2), ChunkyPNG::Point.new(3, 6)]) }
82
+ let(:example) { ChunkyPNG::Vector.new([ChunkyPNG::Point.new(2, 4), ChunkyPNG::Point.new(1, 2), ChunkyPNG::Point.new(3, 6)]) }
37
83
 
38
84
  it "should return an empty vector when given an empty array" do
39
85
  ChunkyPNG::Vector().should == ChunkyPNG::Vector.new([])
@@ -41,18 +87,18 @@ describe 'ChunkyPNG.Vector' do
41
87
  end
42
88
 
43
89
  it "should raise an error when an odd number of numerics is given" do
44
- lambda { ChunkyPNG::Vector(1, 2, 3) }.should raise_error(ChunkyPNG::ExpectationFailed)
90
+ lambda { ChunkyPNG::Vector(1, 2, 3) }.should raise_error(ArgumentError)
45
91
  end
46
92
 
47
93
  it "should create a vector from a string" do
48
- ChunkyPNG::Vector('(2,4) (1,2) (3,6)').should == subject
94
+ ChunkyPNG::Vector('(2,4) (1,2) (3,6)').should == example
49
95
  end
50
96
 
51
97
  it "should create a vector from a flat array" do
52
- ChunkyPNG::Vector(2,4,1,2,3,6).should == subject
98
+ ChunkyPNG::Vector(2,4,1,2,3,6).should == example
53
99
  end
54
100
 
55
101
  it "should create a vector from a nested array" do
56
- ChunkyPNG::Vector('(2,4)', [1, 2], :x => 3, :y => 6).should == subject
102
+ ChunkyPNG::Vector('(2,4)', [1, 2], :x => 3, :y => 6).should == example
57
103
  end
58
104
  end
metadata CHANGED
@@ -6,8 +6,8 @@ version: !ruby/object:Gem::Version
6
6
  - 1
7
7
  - 0
8
8
  - 0
9
- - rc1
10
- version: 1.0.0.rc1
9
+ - rc2
10
+ version: 1.0.0.rc2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Willem van Bergen
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-02-24 00:00:00 -05:00
18
+ date: 2011-03-02 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency