eideticrml 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/Rakefile +55 -0
- data/lib/erml.rb +345 -0
- data/lib/erml_layout_managers.rb +667 -0
- data/lib/erml_rules.rb +104 -0
- data/lib/erml_styles.rb +304 -0
- data/lib/erml_support.rb +105 -0
- data/lib/erml_widget_factories.rb +38 -0
- data/lib/erml_widgets.rb +1895 -0
- data/samples/test10_rich_text.erml +17 -0
- data/samples/test11_table_layout.erml +30 -0
- data/samples/test12_shapes.erml +32 -0
- data/samples/test13_polygons.erml +28 -0
- data/samples/test14_images.erml +19 -0
- data/samples/test15_lines.erml +43 -0
- data/samples/test16_classes.erml +34 -0
- data/samples/test17_rules.erml +24 -0
- data/samples/test18_preformatted_text.erml +9 -0
- data/samples/test19_erb.erml.erb +26 -0
- data/samples/test1_empty_doc.erml +2 -0
- data/samples/test20_haml.erml.haml +20 -0
- data/samples/test21_shift_widgets.erml +47 -0
- data/samples/test22_multipage_flow_layout.erml +40 -0
- data/samples/test23_pageno.erml +17 -0
- data/samples/test24_headers_footers.erml.erb +37 -0
- data/samples/test25_overflow.erml.erb +37 -0
- data/samples/test26_columns.erml.erb +42 -0
- data/samples/test28_landscape.erml.erb +17 -0
- data/samples/test29_pages_up.erml.erb +17 -0
- data/samples/test2_empty_page.erml +6 -0
- data/samples/test30_encodings.erml.haml +35 -0
- data/samples/test3_hello_world.erml +7 -0
- data/samples/test4_two_pages.erml +10 -0
- data/samples/test5_rounded_rect.erml +10 -0
- data/samples/test6_bullets.erml +16 -0
- data/samples/test7_flow_layout.erml +20 -0
- data/samples/test8_vbox_layout.erml +23 -0
- data/samples/test9_hbox_layout.erml +22 -0
- data/samples/testimg.jpg +0 -0
- data/test/test_erml_layout_managers.rb +106 -0
- data/test/test_erml_rules.rb +116 -0
- data/test/test_erml_styles.rb +415 -0
- data/test/test_erml_support.rb +140 -0
- data/test/test_erml_widget_factories.rb +46 -0
- data/test/test_erml_widgets.rb +1235 -0
- data/test/test_helpers.rb +18 -0
- metadata +102 -0
@@ -0,0 +1,415 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created by Brent Rowland on 2008-01-07.
|
4
|
+
# Copyright (c) 2008, Eidetic Software. All rights reserved.
|
5
|
+
|
6
|
+
$: << File.dirname(__FILE__) + '/../'
|
7
|
+
require "minitest/autorun"
|
8
|
+
require 'erml'
|
9
|
+
require 'erml_styles'
|
10
|
+
require 'erml_layout_managers'
|
11
|
+
|
12
|
+
include EideticRML::Styles
|
13
|
+
include EideticRML::LayoutManagers
|
14
|
+
|
15
|
+
class TestStyle < Style
|
16
|
+
end
|
17
|
+
|
18
|
+
class StyleTestCases < Minitest::Test
|
19
|
+
def setup
|
20
|
+
Style.register('test', TestStyle)
|
21
|
+
@style = Style.new(nil)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_id
|
25
|
+
assert_equal(nil, @style.id)
|
26
|
+
@style.id 'foo'
|
27
|
+
assert_equal('foo', @style.id)
|
28
|
+
@style.id 33
|
29
|
+
assert_equal('33', @style.id)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_register
|
33
|
+
assert_equal(TestStyle, Style.class_eval("@@klasses['test']"))
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_for_name
|
37
|
+
assert_equal(TestStyle, Style.for_name('test'))
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class PenStyleTestCases < Minitest::Test
|
42
|
+
def setup
|
43
|
+
@pen_style = Style.for_name('pen').new(nil)
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_initialize
|
47
|
+
refute_nil(@pen_style)
|
48
|
+
assert_kind_of(PenStyle, @pen_style)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_units
|
52
|
+
assert_equal(:pt, @pen_style.units)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_width
|
56
|
+
assert_equal(0, @pen_style.width)
|
57
|
+
@pen_style.width 123
|
58
|
+
assert_equal(123, @pen_style.width)
|
59
|
+
assert_equal(:pt, @pen_style.units)
|
60
|
+
@pen_style.width 456.789
|
61
|
+
assert_equal(456.789, @pen_style.width)
|
62
|
+
assert_equal(:pt, @pen_style.units)
|
63
|
+
@pen_style.width '123'
|
64
|
+
assert_equal(123, @pen_style.width)
|
65
|
+
assert_equal(:pt, @pen_style.units)
|
66
|
+
@pen_style.width '2cm'
|
67
|
+
assert_equal(56.7, @pen_style.width)
|
68
|
+
assert_equal(2, @pen_style.width(:cm))
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_pattern
|
72
|
+
assert_equal(:solid, @pen_style.pattern)
|
73
|
+
@pen_style.pattern :dotted
|
74
|
+
assert_equal(:dotted, @pen_style.pattern)
|
75
|
+
@pen_style.pattern 'dashed'
|
76
|
+
assert_equal(:dashed, @pen_style.pattern)
|
77
|
+
@pen_style.pattern '[1, 10]'
|
78
|
+
assert_equal('[1, 10]', @pen_style.pattern)
|
79
|
+
end
|
80
|
+
|
81
|
+
def test_color
|
82
|
+
assert_equal(0, @pen_style.color)
|
83
|
+
@pen_style.color 'Blue'
|
84
|
+
assert_equal('Blue', @pen_style.color)
|
85
|
+
@pen_style.color 0xFF0000
|
86
|
+
assert_equal(0xFF0000, @pen_style.color)
|
87
|
+
end
|
88
|
+
|
89
|
+
def test_cap
|
90
|
+
assert_equal(:butt_cap, @pen_style.cap)
|
91
|
+
@pen_style.cap 'round_cap'
|
92
|
+
assert_equal(:round_cap, @pen_style.cap)
|
93
|
+
@pen_style.cap 'projecting_square_cap'
|
94
|
+
assert_equal(:projecting_square_cap, @pen_style.cap)
|
95
|
+
@pen_style.cap 'butt_cap'
|
96
|
+
assert_equal(:butt_cap, @pen_style.cap)
|
97
|
+
@pen_style.cap 'bogus_cap_style'
|
98
|
+
assert_equal(:butt_cap, @pen_style.cap) # unchanged
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
class BrushStyleTestCases < Minitest::Test
|
103
|
+
def setup
|
104
|
+
@brush_style = Style.for_name('brush').new(nil)
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_initialize
|
108
|
+
refute_nil(@brush_style)
|
109
|
+
assert_kind_of(BrushStyle, @brush_style)
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_color
|
113
|
+
assert_equal(0, @brush_style.color)
|
114
|
+
@brush_style.color 'Blue'
|
115
|
+
assert_equal('Blue', @brush_style.color)
|
116
|
+
@brush_style.color 0xFF0000
|
117
|
+
assert_equal(0xFF0000, @brush_style.color)
|
118
|
+
@brush_style.color "#EEEEEE"
|
119
|
+
assert_equal(0xEEEEEE, @brush_style.color)
|
120
|
+
@brush_style.color "#999"
|
121
|
+
assert_equal(0x999999, @brush_style.color)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
class FontStyleTestCases < Minitest::Test
|
126
|
+
def setup
|
127
|
+
@font_style = Style.for_name('font').new(nil)
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_initialize
|
131
|
+
refute_nil(@font_style)
|
132
|
+
assert_kind_of(FontStyle, @font_style)
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_color
|
136
|
+
assert_equal(0, @font_style.color)
|
137
|
+
@font_style.color 'Red'
|
138
|
+
assert_equal('Red', @font_style.color)
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_name
|
142
|
+
assert_equal('Helvetica', @font_style.name)
|
143
|
+
@font_style.name 'bigred'
|
144
|
+
assert_equal('bigred', @font_style.name)
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_size
|
148
|
+
assert_equal(12, @font_style.size)
|
149
|
+
@font_style.size 14.5
|
150
|
+
assert_equal(14.5, @font_style.size)
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_strikeout
|
154
|
+
assert(!@font_style.strikeout)
|
155
|
+
@font_style.strikeout(true)
|
156
|
+
assert(@font_style.strikeout)
|
157
|
+
@font_style.strikeout(false)
|
158
|
+
assert(!@font_style.strikeout)
|
159
|
+
@font_style.strikeout("true")
|
160
|
+
assert(@font_style.strikeout)
|
161
|
+
@font_style.strikeout("false")
|
162
|
+
assert(!@font_style.strikeout)
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_style
|
166
|
+
assert_equal('', @font_style.style)
|
167
|
+
@font_style.style 'Italic'
|
168
|
+
assert_equal('Italic', @font_style.style)
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_encoding
|
172
|
+
assert_equal('WinAnsiEncoding', @font_style.encoding)
|
173
|
+
@font_style.encoding 'StandardEncoding'
|
174
|
+
assert_equal('StandardEncoding', @font_style.encoding)
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_sub_type
|
178
|
+
assert_equal('Type1', @font_style.sub_type)
|
179
|
+
@font_style.sub_type 'TrueType'
|
180
|
+
assert_equal('TrueType', @font_style.sub_type)
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_underline
|
184
|
+
assert(!@font_style.underline)
|
185
|
+
@font_style.underline(true)
|
186
|
+
assert(@font_style.underline)
|
187
|
+
@font_style.underline(false)
|
188
|
+
assert(!@font_style.underline)
|
189
|
+
@font_style.underline("true")
|
190
|
+
assert(@font_style.underline)
|
191
|
+
@font_style.underline("false")
|
192
|
+
assert(!@font_style.underline)
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_weight
|
196
|
+
assert_nil(@font_style.weight)
|
197
|
+
@font_style.weight('Bold')
|
198
|
+
assert_equal('Bold', @font_style.weight)
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
class BulletStyleTestCases < Minitest::Test
|
203
|
+
def setup
|
204
|
+
@styles = StyleCollection.new
|
205
|
+
@font_style = @styles.add('font', :id => 'f1', :name => 'Courier', :size => 13)
|
206
|
+
@bullet_style = @styles.add('bullet', :id => 'b1')
|
207
|
+
end
|
208
|
+
|
209
|
+
def test_font
|
210
|
+
assert_nil(@bullet_style.font)
|
211
|
+
@bullet_style.font('f1')
|
212
|
+
assert_equal(@font_style, @bullet_style.font)
|
213
|
+
end
|
214
|
+
|
215
|
+
def test_text
|
216
|
+
assert_nil(@bullet_style.text)
|
217
|
+
@bullet_style.text("*")
|
218
|
+
assert_equal("*", @bullet_style.text)
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_width1
|
222
|
+
assert_equal(:pt, @bullet_style.units) # default units
|
223
|
+
assert_equal(36, @bullet_style.width) # default width
|
224
|
+
assert_equal(0.5, @bullet_style.width(:in)) # in specified units
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_width2
|
228
|
+
@bullet_style.width('18pt')
|
229
|
+
assert_equal(18, @bullet_style.width)
|
230
|
+
assert_equal(0.25, @bullet_style.width(:in))
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_width3
|
234
|
+
@bullet_style.units('cm')
|
235
|
+
assert_equal(:cm, @bullet_style.units)
|
236
|
+
@bullet_style.width('1')
|
237
|
+
assert_equal(28.35, @bullet_style.width)
|
238
|
+
assert_equal(1, @bullet_style.width(:cm))
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
class ParagraphStyleTestCases < Minitest::Test
|
243
|
+
def setup
|
244
|
+
@styles = StyleCollection.new
|
245
|
+
@bullet_style = @styles.add('bullet', :id => '*')
|
246
|
+
@paragraph_style = @styles.add('para', :id => 'p')
|
247
|
+
end
|
248
|
+
|
249
|
+
def test_initialize
|
250
|
+
refute_nil(@paragraph_style)
|
251
|
+
assert_kind_of(ParagraphStyle, @paragraph_style)
|
252
|
+
end
|
253
|
+
|
254
|
+
def test_color
|
255
|
+
assert_equal(0, @paragraph_style.color)
|
256
|
+
@paragraph_style.color 'Red'
|
257
|
+
assert_equal('Red', @paragraph_style.color)
|
258
|
+
end
|
259
|
+
|
260
|
+
def test_align
|
261
|
+
assert_equal(:left, @paragraph_style.text_align)
|
262
|
+
[:left, :center, :right, :justify].each do |align|
|
263
|
+
@paragraph_style.text_align align
|
264
|
+
assert_equal(align, @paragraph_style.text_align)
|
265
|
+
end
|
266
|
+
['left', 'center', 'right', 'justify'].each do |align|
|
267
|
+
@paragraph_style.text_align align
|
268
|
+
assert_equal(align.to_sym, @paragraph_style.text_align)
|
269
|
+
end
|
270
|
+
@paragraph_style.text_align 'bogus'
|
271
|
+
assert_equal(:justify, @paragraph_style.text_align) # last style successfully set
|
272
|
+
end
|
273
|
+
|
274
|
+
def test_bullet
|
275
|
+
assert_nil(@paragraph_style.bullet)
|
276
|
+
@paragraph_style.bullet '*'
|
277
|
+
assert_equal(@bullet_style, @paragraph_style.bullet)
|
278
|
+
end
|
279
|
+
end
|
280
|
+
|
281
|
+
class PageStyleTestCases < Minitest::Test
|
282
|
+
def setup
|
283
|
+
@page_style = Style.for_name('page').new(nil)
|
284
|
+
end
|
285
|
+
|
286
|
+
def test_initialize
|
287
|
+
refute_nil(@page_style)
|
288
|
+
assert_kind_of(PageStyle, @page_style)
|
289
|
+
end
|
290
|
+
|
291
|
+
def test_size
|
292
|
+
assert_equal(:letter, @page_style.size)
|
293
|
+
@page_style.size 'bogus'
|
294
|
+
assert_equal(:letter, @page_style.size) # unchanged
|
295
|
+
@page_style.size :legal
|
296
|
+
assert_equal(:legal, @page_style.size)
|
297
|
+
['A4', 'B5', 'C5'].each do |size|
|
298
|
+
@page_style.size size
|
299
|
+
assert_equal(size.to_sym, @page_style.size)
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
def test_orientation
|
304
|
+
assert_equal(:portrait, @page_style.orientation)
|
305
|
+
@page_style.orientation :landscape
|
306
|
+
assert_equal(:landscape, @page_style.orientation)
|
307
|
+
['portrait', 'landscape'].each do |orientation|
|
308
|
+
@page_style.orientation orientation
|
309
|
+
assert_equal(orientation.to_sym, @page_style.orientation)
|
310
|
+
end
|
311
|
+
@page_style.orientation 'bogus'
|
312
|
+
assert_equal(:landscape, @page_style.orientation)
|
313
|
+
end
|
314
|
+
|
315
|
+
def test_height
|
316
|
+
assert_equal(792, @page_style.height)
|
317
|
+
assert_equal(11, @page_style.height(:in))
|
318
|
+
end
|
319
|
+
|
320
|
+
def test_width
|
321
|
+
assert_equal(612, @page_style.width)
|
322
|
+
assert_equal(8.5, @page_style.width(:in))
|
323
|
+
end
|
324
|
+
end
|
325
|
+
|
326
|
+
class LayoutStyleTestCases < Minitest::Test
|
327
|
+
def setup
|
328
|
+
@layout_style = Style.for_name('layout').new(nil)
|
329
|
+
end
|
330
|
+
|
331
|
+
def test_initialize
|
332
|
+
refute_nil(@layout_style)
|
333
|
+
assert_kind_of(LayoutStyle, @layout_style)
|
334
|
+
end
|
335
|
+
|
336
|
+
def test_padding
|
337
|
+
assert_equal(0, @layout_style.padding)
|
338
|
+
assert_equal(:pt, @layout_style.units)
|
339
|
+
|
340
|
+
@layout_style.padding 5
|
341
|
+
assert_equal(5, @layout_style.padding)
|
342
|
+
|
343
|
+
@layout_style.padding 2, :cm
|
344
|
+
assert_equal(56.7, @layout_style.padding)
|
345
|
+
assert_equal(2, @layout_style.padding(:cm))
|
346
|
+
|
347
|
+
@layout_style.padding 1, 'in'
|
348
|
+
assert_equal(1, @layout_style.padding(:in))
|
349
|
+
assert_equal(72, @layout_style.padding)
|
350
|
+
|
351
|
+
@layout_style.padding '5pt'
|
352
|
+
assert_equal(5, @layout_style.padding)
|
353
|
+
|
354
|
+
@layout_style.padding '2cm'
|
355
|
+
assert_equal(2, @layout_style.padding(:cm))
|
356
|
+
assert_equal(56.7, @layout_style.padding)
|
357
|
+
|
358
|
+
@layout_style.padding '1.25in'
|
359
|
+
assert_equal(1.25, @layout_style.padding(:in))
|
360
|
+
end
|
361
|
+
|
362
|
+
def test_hpadding
|
363
|
+
assert_equal(0, @layout_style.hpadding)
|
364
|
+
|
365
|
+
@layout_style.hpadding 5
|
366
|
+
assert_equal(5, @layout_style.hpadding)
|
367
|
+
|
368
|
+
@layout_style.hpadding 2, :cm
|
369
|
+
assert_equal(2, @layout_style.hpadding(:cm))
|
370
|
+
|
371
|
+
@layout_style.hpadding 1, 'in'
|
372
|
+
assert_equal(1, @layout_style.hpadding(:in))
|
373
|
+
assert_equal(72, @layout_style.hpadding)
|
374
|
+
|
375
|
+
@layout_style.hpadding '5pt'
|
376
|
+
assert_equal(5, @layout_style.hpadding)
|
377
|
+
|
378
|
+
@layout_style.hpadding '2cm'
|
379
|
+
assert_equal(2, @layout_style.hpadding(:cm))
|
380
|
+
assert_equal(56.7, @layout_style.hpadding)
|
381
|
+
|
382
|
+
@layout_style.hpadding '1.25in'
|
383
|
+
assert_equal(1.25, @layout_style.hpadding(:in))
|
384
|
+
end
|
385
|
+
|
386
|
+
def test_vpadding
|
387
|
+
assert_equal(0, @layout_style.vpadding)
|
388
|
+
|
389
|
+
@layout_style.vpadding 5
|
390
|
+
assert_equal(5, @layout_style.vpadding)
|
391
|
+
|
392
|
+
@layout_style.vpadding 2, :cm
|
393
|
+
assert_equal(2, @layout_style.vpadding(:cm))
|
394
|
+
|
395
|
+
@layout_style.vpadding 1, 'in'
|
396
|
+
assert_equal(1, @layout_style.vpadding(:in))
|
397
|
+
assert_equal(72, @layout_style.vpadding)
|
398
|
+
|
399
|
+
@layout_style.vpadding '5pt'
|
400
|
+
assert_equal(5, @layout_style.vpadding)
|
401
|
+
|
402
|
+
@layout_style.vpadding '2cm'
|
403
|
+
assert_equal(2, @layout_style.vpadding(:cm))
|
404
|
+
assert_equal(56.7, @layout_style.vpadding)
|
405
|
+
|
406
|
+
@layout_style.vpadding '1.25in'
|
407
|
+
assert_equal(1.25, @layout_style.vpadding(:in))
|
408
|
+
end
|
409
|
+
|
410
|
+
def test_manager
|
411
|
+
assert_nil(@layout_style.manager)
|
412
|
+
@layout_style.manager('absolute')
|
413
|
+
assert_kind_of(AbsoluteLayout, @layout_style.manager)
|
414
|
+
end
|
415
|
+
end
|
@@ -0,0 +1,140 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created by Brent Rowland on 2008-01-07.
|
4
|
+
# Copyright (c) 2008, Eidetic Software. All rights reserved.
|
5
|
+
|
6
|
+
$: << File.dirname(__FILE__) + '/../'
|
7
|
+
require "minitest/autorun"
|
8
|
+
require 'erml_support'
|
9
|
+
|
10
|
+
include EideticRML
|
11
|
+
|
12
|
+
class ErmlSupportTestCases < Minitest::Test
|
13
|
+
def test_parse_measurement
|
14
|
+
assert_equal([123, :pt], Support::parse_measurement("123"))
|
15
|
+
assert_equal([123.456, :pt], Support::parse_measurement("123.456"))
|
16
|
+
assert_equal([123, :cm], Support::parse_measurement("123cm"))
|
17
|
+
assert_equal([123.456, :cm], Support::parse_measurement("123.456cm"))
|
18
|
+
assert_equal([2, :in], Support::parse_measurement("2", :in))
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_parse_measurement_pts
|
22
|
+
assert_equal(123, Support::parse_measurement_pts("123"))
|
23
|
+
assert_equal(123.456, Support::parse_measurement_pts("123.456"))
|
24
|
+
assert_equal(3487.05, Support::parse_measurement_pts("123cm"))
|
25
|
+
assert_equal(3499.9776, Support::parse_measurement_pts("123.456cm"))
|
26
|
+
assert_equal(144, Support::parse_measurement_pts("2", :in))
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class GridTestCases < Minitest::Test
|
31
|
+
def setup
|
32
|
+
@grid = Support::Grid.new(3, 2)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_index_get
|
36
|
+
3.times do |c|
|
37
|
+
2.times do |r|
|
38
|
+
assert_equal(nil, @grid[c,r])
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def set6
|
44
|
+
@grid[0, 0] = 1
|
45
|
+
@grid[1, 0] = 2
|
46
|
+
@grid[2, 0] = 3
|
47
|
+
@grid[0, 1] = 4
|
48
|
+
@grid[1, 1] = 5
|
49
|
+
@grid[2, 1] = 6
|
50
|
+
end
|
51
|
+
|
52
|
+
def get3
|
53
|
+
assert_equal(1, @grid[0, 0])
|
54
|
+
assert_equal(2, @grid[1, 0])
|
55
|
+
assert_equal(3, @grid[2, 0])
|
56
|
+
end
|
57
|
+
|
58
|
+
def get4
|
59
|
+
assert_equal(1, @grid[0, 0])
|
60
|
+
assert_equal(2, @grid[1, 0])
|
61
|
+
assert_equal(4, @grid[0, 1])
|
62
|
+
assert_equal(5, @grid[1, 1])
|
63
|
+
end
|
64
|
+
|
65
|
+
def get6
|
66
|
+
get3
|
67
|
+
assert_equal(4, @grid[0, 1])
|
68
|
+
assert_equal(5, @grid[1, 1])
|
69
|
+
assert_equal(6, @grid[2, 1])
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_index_set
|
73
|
+
set6
|
74
|
+
get6
|
75
|
+
end
|
76
|
+
|
77
|
+
def test_col
|
78
|
+
set6
|
79
|
+
assert_equal([1, 4], @grid.col(0))
|
80
|
+
assert_equal([2, 5], @grid.col(1))
|
81
|
+
assert_equal([3, 6], @grid.col(2))
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_row
|
85
|
+
set6
|
86
|
+
assert_equal([1, 2, 3], @grid.row(0))
|
87
|
+
assert_equal([4, 5, 6], @grid.row(1))
|
88
|
+
end
|
89
|
+
|
90
|
+
def test_resize_rows_larger
|
91
|
+
set6
|
92
|
+
@grid.rows = 4
|
93
|
+
assert_equal(4, @grid.rows)
|
94
|
+
get6
|
95
|
+
end
|
96
|
+
|
97
|
+
def test_resize_rows_smaller
|
98
|
+
set6
|
99
|
+
@grid.rows = 1
|
100
|
+
assert_equal(1, @grid.rows)
|
101
|
+
get3
|
102
|
+
end
|
103
|
+
|
104
|
+
def test_resize_cols_larger
|
105
|
+
set6
|
106
|
+
@grid.cols = 5
|
107
|
+
assert_equal(5, @grid.cols)
|
108
|
+
get6
|
109
|
+
end
|
110
|
+
|
111
|
+
def test_resize_cols_smaller
|
112
|
+
set6
|
113
|
+
@grid.cols = 2
|
114
|
+
get4
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
class BoundsTestCases < Minitest::Test
|
119
|
+
def test_init_empty
|
120
|
+
b = Support::Bounds.new
|
121
|
+
assert_equal nil, b.left
|
122
|
+
assert_equal nil, b.top
|
123
|
+
assert_equal nil, b.right
|
124
|
+
assert_equal nil, b.bottom
|
125
|
+
end
|
126
|
+
|
127
|
+
def test_init_full
|
128
|
+
b = Support::Bounds.new(3,5,7,11)
|
129
|
+
assert_equal 3, b.left
|
130
|
+
assert_equal 5, b.top
|
131
|
+
assert_equal 7, b.right
|
132
|
+
assert_equal 11, b.bottom
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_width_height
|
136
|
+
b = Support::Bounds.new(3,5,7,11)
|
137
|
+
assert_equal 4, b.width
|
138
|
+
assert_equal 6, b.height
|
139
|
+
end
|
140
|
+
end
|