66class BitmapTest < Minitest ::Test
77 def test_default_constructor
88 image = Bmp ::Bitmap . new
9- assert_equal 0 , image . width
10- assert_equal 0 , image . height
11- assert image . empty?
9+ assert_equal ( 0 , image . width )
10+ assert_equal ( 0 , image . height )
11+ assert ( image . empty? )
1212 end
1313
1414 def test_dimensions_constructor
1515 image = Bmp ::Bitmap . new ( 640 , 480 )
1616 assert_equal ( 640 , image . width )
1717 assert_equal ( 480 , image . height )
18- refute image . empty?
18+ refute ( image . empty? )
1919 end
2020
2121 def test_clone
2222 original = Bmp ::Bitmap . new ( 100 , 100 )
2323 original . set ( 50 , 50 , Bmp ::Red )
2424
2525 copy = original . clone
26- assert_equal 100 , copy . width
27- assert_equal 100 , copy . height
28- assert_equal Bmp ::Red . r , copy . get ( 50 , 50 ) . r
26+ assert_equal ( 100 , copy . width )
27+ assert_equal ( 100 , copy . height )
28+ assert_equal ( Bmp ::Red . r , copy . get ( 50 , 50 ) . r )
2929 end
3030
3131 def test_clear_default
@@ -34,29 +34,29 @@ def test_clear_default
3434
3535 # Should be black by default
3636 pixel = image . get ( 5 , 5 )
37- assert_equal 0 , pixel . r
38- assert_equal 0 , pixel . g
39- assert_equal 0 , pixel . b
37+ assert_equal ( 0 , pixel . r )
38+ assert_equal ( 0 , pixel . g )
39+ assert_equal ( 0 , pixel . b )
4040 end
4141
4242 def test_clear_with_color
4343 image = Bmp ::Bitmap . new ( 10 , 10 )
4444 image . clear ( Bmp ::Red )
4545
4646 pixel = image . get ( 5 , 5 )
47- assert_equal 255 , pixel . r
48- assert_equal 0 , pixel . g
49- assert_equal 0 , pixel . b
47+ assert_equal ( 255 , pixel . r )
48+ assert_equal ( 0 , pixel . g )
49+ assert_equal ( 0 , pixel . b )
5050 end
5151
5252 def test_get_and_set
5353 image = Bmp ::Bitmap . new ( 10 , 10 )
5454 image . set ( 5 , 5 , Bmp ::Blue )
5555
5656 pixel = image . get ( 5 , 5 )
57- assert_equal Bmp ::Blue . r , pixel . r
58- assert_equal Bmp ::Blue . g , pixel . g
59- assert_equal Bmp ::Blue . b , pixel . b
57+ assert_equal ( Bmp ::Blue . r , pixel . r )
58+ assert_equal ( Bmp ::Blue . g , pixel . g )
59+ assert_equal ( Bmp ::Blue . b , pixel . b )
6060 end
6161
6262 def test_array_access
@@ -65,19 +65,19 @@ def test_array_access
6565
6666 # Linear index = x + width * y = 5 + 10 * 5 = 55
6767 pixel = image [ 55 ]
68- assert_equal Bmp ::Green . r , pixel . r
69- assert_equal Bmp ::Green . g , pixel . g
70- assert_equal Bmp ::Green . b , pixel . b
68+ assert_equal ( Bmp ::Green . r , pixel . r )
69+ assert_equal ( Bmp ::Green . g , pixel . g )
70+ assert_equal ( Bmp ::Green . b , pixel . b )
7171 end
7272
7373 def test_array_assignment
7474 image = Bmp ::Bitmap . new ( 10 , 10 )
7575 image [ 55 ] = Bmp ::Yellow
7676
7777 pixel = image . get ( 5 , 5 )
78- assert_equal Bmp ::Yellow . r , pixel . r
79- assert_equal Bmp ::Yellow . g , pixel . g
80- assert_equal Bmp ::Yellow . b , pixel . b
78+ assert_equal ( Bmp ::Yellow . r , pixel . r )
79+ assert_equal ( Bmp ::Yellow . g , pixel . g )
80+ assert_equal ( Bmp ::Yellow . b , pixel . b )
8181 end
8282
8383 def test_equality
@@ -90,32 +90,48 @@ def test_equality
9090 image3 = Bmp ::Bitmap . new ( 10 , 10 )
9191 image3 . clear ( Bmp ::Blue )
9292
93- assert image1 == image2
94- assert image1 != image3
93+ assert ( image1 == image2 )
94+ assert ( image1 != image3 )
9595 end
9696
9797 def test_each_iterator
98- image = Bmp ::Bitmap . new ( 10 , 10 )
98+ image = Bmp ::Bitmap . new ( 2 , 2 )
9999 count = 0
100100
101- image . each do |pixel |
102- count += 1
103- pixel . r = 128
101+ image . each . with_index do |pixel , i |
102+ count +=1
103+ pixel . r = i
104+ pixel . g = i + 1
105+ pixel . b = i + 2
104106 end
105107
106- assert_equal 100 , count
107- assert_equal 128 , image . get ( 0 , 0 ) . r
108+ assert_equal ( 4 , count )
109+ expected = [ Bmp ::Pixel . new ( red : 0 , green : 1 , blue : 2 ) ,
110+ Bmp ::Pixel . new ( red : 1 , green : 2 , blue : 3 ) ,
111+ Bmp ::Pixel . new ( red : 2 , green : 3 , blue : 4 ) ,
112+ Bmp ::Pixel . new ( red : 3 , green : 4 , blue : 5 ) ]
113+
114+ assert_equal ( expected , image . each . to_a )
108115 end
109116
110117 def test_each_reverse_iterator
111- image = Bmp ::Bitmap . new ( 10 , 10 )
112- count = 0
113-
114- image . each_reverse do |_pixel |
115- count += 1
116- end
117-
118- assert_equal 100 , count
118+ image = Bmp ::Bitmap . new ( 2 , 2 )
119+ count = 0
120+
121+ image . each_reverse . with_index do |pixel , i |
122+ count +=1
123+ pixel . r = i
124+ pixel . g = i + 1
125+ pixel . b = i + 2
126+ end
127+
128+ assert_equal ( 4 , count )
129+ expected = [ Bmp ::Pixel . new ( red : 3 , green : 4 , blue : 5 ) ,
130+ Bmp ::Pixel . new ( red : 2 , green : 3 , blue : 4 ) ,
131+ Bmp ::Pixel . new ( red : 1 , green : 2 , blue : 3 ) ,
132+ Bmp ::Pixel . new ( red : 0 , green : 1 , blue : 2 ) ]
133+
134+ assert_equal ( expected , image . each . to_a )
119135 end
120136
121137 def test_inspect
0 commit comments