processing 0.5.30 → 0.5.31

Sign up to get free protection for your applications and to get access to all the features.
data/test/helper.rb CHANGED
@@ -5,28 +5,62 @@
5
5
  require 'xot/test'
6
6
  require 'processing/all'
7
7
 
8
+ require 'digest/md5'
9
+ require 'fileutils'
8
10
  require 'tempfile'
9
11
  require 'test/unit'
10
12
 
11
13
  include Xot::Test
12
14
 
13
15
 
14
- def temppath(ext: nil, &block)
16
+ DEFAULT_DRAW_HEADER = <<~END
17
+ background 100
18
+ fill 255, 0, 0
19
+ stroke 0, 255, 0
20
+ strokeWeight 50
21
+ END
22
+
23
+
24
+ def test_with_p5?()
25
+ ENV['TEST_WITH_P5'] == '1'
26
+ end
27
+
28
+ def md5(s)
29
+ Digest::MD5.hexdigest s
30
+ end
31
+
32
+ def mkdir(dir: nil, filename: nil)
33
+ path = dir || File.dirname(filename)
34
+ FileUtils.mkdir_p path unless File.exist? path
35
+ end
36
+
37
+ def test_label(index = 1)
38
+ caller_locations[index].then {|loc| "#{loc.label}_#{loc.lineno}"}
39
+ end
40
+
41
+ def temp_path(ext: nil, &block)
15
42
  f = Tempfile.new
16
43
  path = f.path
17
- path += ".#{ext}" if ext
44
+ path += ext if ext
18
45
  f.close!
19
46
  block.call path
20
47
  File.delete path
21
48
  end
22
49
 
50
+ def draw_output_path(label, *sources, ext: '.png', dir: ext)
51
+ src = sources.compact.then {|ary| ary.empty? ? '' : "_#{md5 ary.join("\n")}"}
52
+ path = File.join __dir__, dir, label + src + ext
53
+ mkdir filename: path
54
+ path
55
+ end
56
+
23
57
  def get_pixels(image)
24
58
  %i[@image @image__]
25
59
  .map {image.instance_variable_get _1}
26
60
  .compact
27
61
  .first
28
62
  .bitmap
29
- .to_a
63
+ .pixels
30
64
  end
31
65
 
32
66
  def graphics(width = 10, height = 10, *args, &block)
@@ -35,6 +69,14 @@ def graphics(width = 10, height = 10, *args, &block)
35
69
  end
36
70
  end
37
71
 
72
+ def test_draw(*sources, width: 1000, height: 1000, pixelDensity: 1, label: nil)
73
+ graphics(width, height, pixelDensity).tap do |g|
74
+ g.beginDraw {g.instance_eval sources.compact.join("\n")}
75
+ g.save draw_output_path(label, *sources) if label
76
+ end
77
+ end
78
+
79
+
38
80
  def assert_equal_vector(v1, v2, delta = 0.000001)
39
81
  assert_in_delta v1.x, v2.x, delta
40
82
  assert_in_delta v1.y, v2.y, delta
@@ -52,3 +94,44 @@ def assert_equal_pixels(expected, actual, threshold: 1.0)
52
94
  The rate of the same pixel #{equal_rate} is below the threshold #{threshold}
53
95
  EOS
54
96
  end
97
+
98
+ def assert_equal_draw(
99
+ *shared_header, expected, actual, default_header: DEFAULT_DRAW_HEADER,
100
+ width: 1000, height: 1000, threshold: 1.0, label: test_label)
101
+
102
+ e = test_draw default_header, *shared_header, expected, label: "#{label}_expected"
103
+ a = test_draw default_header, *shared_header, actual, label: "#{label}_actual"
104
+
105
+ assert_equal_pixels e, a, threshold: threshold
106
+ end
107
+
108
+ def assert_p5_draw(
109
+ *sources, default_header: DEFAULT_DRAW_HEADER,
110
+ width: 1000, height: 1000, threshold: 0.99, label: test_label)
111
+
112
+ return unless test_with_p5?
113
+
114
+ source = [default_header, *sources].compact.join("\n")
115
+ path = draw_output_path "#{label}_expected", source
116
+
117
+ pd = draw_p5rb width, height, source, path, headless: true
118
+ actual = test_draw source, width: width, height: height, pixelDensity: pd
119
+ actual.save path.sub('_expected', '_actual')
120
+
121
+ assert_equal_pixels actual.loadImage(path), actual, threshold: threshold
122
+ end
123
+
124
+ def assert_p5_fill(*sources, **kwargs)
125
+ assert_p5_draw 'noStroke', *sources, label: test_label, **kwargs
126
+ end
127
+
128
+ def assert_p5_stroke(*sources, **kwargs)
129
+ assert_p5_draw 'noFill; stroke 0, 255, 0', *sources, label: test_label, **kwargs
130
+ end
131
+
132
+ def assert_p5_fill_stroke(*sources, **kwargs)
133
+ assert_p5_draw 'stroke 0, 255, 0', *sources, label: test_label, **kwargs
134
+ end
135
+
136
+
137
+ require_relative 'p5' if test_with_p5?
@@ -37,9 +37,6 @@ def get_p5rb_html(width, height, draw_src)
37
37
  createCanvas #{width}, #{height}
38
38
  end
39
39
  def draw()
40
- background 0
41
- fill 255, 0, 0
42
- noStroke
43
40
  #{draw_src}
44
41
  JS.global.completed
45
42
  end
@@ -51,12 +48,28 @@ def get_p5rb_html(width, height, draw_src)
51
48
  END
52
49
  end
53
50
 
51
+ def sleep_until (try: 3, timeout: 10, &block)
52
+ now = -> offset = 0 {Time.now.to_f + offset}
53
+ limit = now[timeout]
54
+ until block.call
55
+ if now[] > limit
56
+ limit = now[timeout]
57
+ try -= 1
58
+ next if try > 0
59
+ raise 'Drawing timed out in p5.rb'
60
+ end
61
+ sleep 0.1
62
+ end
63
+ end
64
+
54
65
  def draw_p5rb(width, height, draw_src, path, headless: true)
55
66
  b = browser width, height, headless: headless
56
67
  unless File.exist? path
57
68
  b.reset
58
69
  b.main_frame.content = get_p5rb_html width, height, draw_src
59
- sleep 0.1 until b.evaluate 'document.querySelector("#completed") != null'
70
+ sleep_until do
71
+ b.evaluate 'document.querySelector("#completed") != null'
72
+ end
60
73
  b.screenshot path: path
61
74
  end
62
75
  b.device_pixel_ratio
@@ -3,12 +3,6 @@ require_relative 'helper'
3
3
 
4
4
  class TestGraphics < Test::Unit::TestCase
5
5
 
6
- P = Processing
7
-
8
- def graphics(w = 10, h = 10)
9
- P::Graphics.new w, h
10
- end
11
-
12
6
  def test_beginDraw()
13
7
  g = graphics
14
8
  g.beginDraw
@@ -24,7 +18,7 @@ class TestGraphics < Test::Unit::TestCase
24
18
  g.ellipseMode :corner
25
19
  g.ellipse 0, 0, g.width, g.height
26
20
  end
27
- temppath(ext: 'png') do |path|
21
+ temp_path(ext: '.png') do |path|
28
22
  assert_nothing_raised {g.save path}
29
23
  assert_equal_pixels g, g.loadImage(path)
30
24
  end
@@ -6,9 +6,7 @@ class TestGraphicsContext < Test::Unit::TestCase
6
6
  P = Processing
7
7
  G = P::Graphics
8
8
 
9
- def graphics(w = 10, h = 10)
10
- G.new w, h
11
- end
9
+ THRESHOLD_TO_BE_FIXED = 0.0
12
10
 
13
11
  def test_color()
14
12
  g = graphics
@@ -57,8 +55,29 @@ class TestGraphicsContext < Test::Unit::TestCase
57
55
  assert_raise {g.blendMode LEFT}
58
56
  end
59
57
 
58
+ def test_default_background_color()
59
+ assert_p5_draw '', default_header: '', threshold: THRESHOLD_TO_BE_FIXED
60
+ end
61
+
62
+ def test_default_fill_color()
63
+ assert_p5_draw <<~END, default_header: nil
64
+ background 100
65
+ noStroke
66
+ rect 100, 100, 500, 500
67
+ END
68
+ end
69
+
70
+ def test_default_stroke_color()
71
+ assert_p5_draw <<~END, default_header: nil
72
+ background 100
73
+ noFill
74
+ strokeWeight 50
75
+ line 100, 100, 500, 500
76
+ END
77
+ end
78
+
60
79
  def test_clear()
61
- colors = -> g {get_pixels(g).map(&:to_a).flatten.uniq}
80
+ colors = -> g {get_pixels(g).uniq}
62
81
 
63
82
  g = graphics
64
83
  assert_equal [0], colors[g]
@@ -70,6 +89,385 @@ class TestGraphicsContext < Test::Unit::TestCase
70
89
  assert_equal [0], colors[g]
71
90
  end
72
91
 
92
+ def test_point()
93
+ src = 'strokeWeight 300; point 500, 600'
94
+ assert_p5_fill src
95
+ assert_p5_stroke src, threshold: THRESHOLD_TO_BE_FIXED
96
+ assert_p5_fill_stroke src, threshold: THRESHOLD_TO_BE_FIXED
97
+ end
98
+
99
+ def test_line()
100
+ src = 'strokeWeight 100; line 100, 200, 500, 600'
101
+ assert_p5_fill src
102
+ assert_p5_stroke src
103
+ assert_p5_fill_stroke src
104
+ end
105
+
106
+ def test_rect()
107
+ src = 'rect 100, 200, 300, 400'
108
+ assert_p5_fill src
109
+ assert_p5_stroke src
110
+ assert_p5_fill_stroke src
111
+ end
112
+
113
+ def test_rect_with_rectMode()
114
+ assert_p5_draw 'rectMode CORNER; rect 100, 200, 300, 400'
115
+ assert_p5_draw 'rectMode CORNERS; rect 100, 200, 300, 500'
116
+ assert_p5_draw 'rectMode CENTER; rect 400, 500, 300, 400'
117
+ assert_p5_draw 'rectMode RADIUS; rect 400, 500, 300, 400'
118
+ end
119
+
120
+ def test_ellipse()
121
+ src = 'ellipse 500, 600, 300, 400'
122
+ assert_p5_fill src
123
+ assert_p5_stroke src
124
+ assert_p5_fill_stroke src
125
+ end
126
+
127
+ def test_ellipse_with_ellipseMode()
128
+ assert_p5_draw 'ellipseMode CORNER; ellipse 100, 200, 300, 400'
129
+ assert_p5_draw 'ellipseMode CORNERS; ellipse 100, 200, 300, 500'
130
+ assert_p5_draw 'ellipseMode CENTER; ellipse 400, 500, 300, 400'
131
+ assert_p5_draw 'ellipseMode RADIUS; ellipse 400, 500, 300, 400'
132
+ end
133
+
134
+ def test_circle()
135
+ src = 'circle 500, 600, 300'
136
+ assert_p5_fill src
137
+ assert_p5_stroke src
138
+ assert_p5_fill_stroke src
139
+ end
140
+
141
+ def test_circle_with_ellipseMode()
142
+ assert_p5_draw 'ellipseMode CORNER; circle 100, 200, 300'
143
+ assert_p5_draw 'ellipseMode CORNERS; circle 100, 200, 300'
144
+ assert_p5_draw 'ellipseMode CENTER; circle 400, 500, 300'
145
+ assert_p5_draw 'ellipseMode RADIUS; circle 400, 500, 300'
146
+ end
147
+
148
+ def test_arc()
149
+ src = 'arc 500, 600, 300, 400, PI * 0.25, PI * 0.75'
150
+ assert_p5_fill src, threshold: THRESHOLD_TO_BE_FIXED
151
+ assert_p5_stroke src, threshold: THRESHOLD_TO_BE_FIXED
152
+ assert_p5_fill_stroke src, threshold: THRESHOLD_TO_BE_FIXED
153
+ end
154
+
155
+ def test_arc_with_ellipseMode()
156
+ assert_p5_draw 'ellipseMode CORNER; arc 100, 200, 300, 400, 0, PI * 0.75',
157
+ threshold: THRESHOLD_TO_BE_FIXED
158
+ assert_p5_draw 'ellipseMode CORNERS; arc 100, 200, 300, 500, 0, PI * 0.75',
159
+ threshold: THRESHOLD_TO_BE_FIXED
160
+ assert_p5_draw 'ellipseMode CENTER; arc 400, 500, 300, 400, 0, PI * 0.75',
161
+ threshold: THRESHOLD_TO_BE_FIXED
162
+ assert_p5_draw 'ellipseMode RADIUS; arc 400, 500, 300, 400, 0, PI * 0.75',
163
+ threshold: THRESHOLD_TO_BE_FIXED
164
+ end
165
+
166
+ def test_square()
167
+ src = 'square 500, 600, 300'
168
+ assert_p5_fill src
169
+ assert_p5_stroke src
170
+ assert_p5_fill_stroke src
171
+ end
172
+
173
+ def test_triangle()
174
+ src = 'triangle 100,100, 100,500, 500,200'
175
+ assert_p5_fill src
176
+ assert_p5_stroke src
177
+ assert_p5_fill_stroke src
178
+ end
179
+
180
+ def test_quad()
181
+ src = 'quad 100,100, 100,500, 500,500, 600,100'
182
+ assert_p5_fill src
183
+ assert_p5_stroke src
184
+ assert_p5_fill_stroke src
185
+ end
186
+
187
+ def test_curve()
188
+ src = 'curve 100,100, 100,500, 500,500, 600,100'
189
+ assert_p5_fill src, threshold: 0
190
+ assert_p5_stroke src, threshold: 0
191
+ assert_p5_fill_stroke src, threshold: 0
192
+ end
193
+
194
+ def test_bezier()
195
+ src = 'curve 100,100, 100,500, 500,500, 600,100'
196
+ assert_p5_fill src, threshold: 0
197
+ assert_p5_stroke src, threshold: 0
198
+ assert_p5_fill_stroke src, threshold: 0
199
+ end
200
+
201
+ def test_shape_with_shapeMode_corner()
202
+ header = 'noStroke'
203
+
204
+ assert_equal_draw header, <<~EXPECTED, <<~ACTUAL
205
+ rect 100, 200, 300, 400
206
+ EXPECTED
207
+ shapeMode CORNER
208
+ shape createShape(RECT, 100, 200, 300, 400)
209
+ ACTUAL
210
+
211
+ assert_equal_draw header, <<~EXPECTED, <<~ACTUAL
212
+ rect 100, 200, 300, 400
213
+ EXPECTED
214
+ shapeMode CORNER
215
+ shape createShape(RECT, 0, 0, 300, 400), 100, 200
216
+ ACTUAL
217
+
218
+ assert_equal_draw header, <<~EXPECTED, <<~ACTUAL
219
+ rect 100, 200, 300, 400
220
+ EXPECTED
221
+ shapeMode CORNER
222
+ shape createShape(RECT, 0, 0, 500, 600), 100, 200, 300, 400
223
+ ACTUAL
224
+ end
225
+
226
+ def test_shape_with_shapeMode_corners()
227
+ header = 'noStroke'
228
+
229
+ assert_equal_draw header, <<~EXPECTED, <<~ACTUAL
230
+ rect 100, 200, 300, 400
231
+ EXPECTED
232
+ shapeMode CORNERS
233
+ shape createShape(RECT, 100, 200, 300, 400)
234
+ ACTUAL
235
+
236
+ assert_equal_draw header, <<~EXPECTED, <<~ACTUAL
237
+ rect 100, 200, 200, 200
238
+ EXPECTED
239
+ shapeMode CORNERS
240
+ shape createShape(RECT, 0, 0, 300, 400), 100, 200
241
+ ACTUAL
242
+
243
+ assert_equal_draw header, <<~EXPECTED, <<~ACTUAL
244
+ rect 100, 200, 200, 200
245
+ EXPECTED
246
+ shapeMode CORNERS
247
+ shape createShape(RECT, 0, 0, 500, 600), 100, 200, 300, 400
248
+ ACTUAL
249
+ end
250
+
251
+ def test_shape_with_shapeMode_center()
252
+ header = 'noStroke'
253
+
254
+ assert_equal_draw header, <<~EXPECTED, <<~ACTUAL
255
+ rect 400, 400, 200, 400
256
+ EXPECTED
257
+ shapeMode CENTER
258
+ shape createShape(RECT, 500, 600, 200, 400)
259
+ ACTUAL
260
+
261
+ assert_equal_draw header, <<~EXPECTED, <<~ACTUAL
262
+ rect 400, 400, 200, 400
263
+ EXPECTED
264
+ shapeMode CENTER
265
+ shape createShape(RECT, 0, 0, 200, 400), 500, 600
266
+ ACTUAL
267
+
268
+ assert_equal_draw header, <<~EXPECTED, <<~ACTUAL
269
+ rect 400, 400, 200, 400
270
+ EXPECTED
271
+ shapeMode CENTER
272
+ shape createShape(RECT, 0, 0, 700, 800), 500, 600, 200, 400
273
+ ACTUAL
274
+ end
275
+
276
+ def test_shape_with_groups()
277
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
278
+ rect 100, 100, 300, 200
279
+ rect 200, 200, 300, 200
280
+ EXPECTED
281
+ group = createShape GROUP
282
+ group.addChild createShape(RECT, 100, 100, 300, 200)
283
+ group.addChild createShape(RECT, 200, 200, 300, 200)
284
+ shape group
285
+ ACTUAL
286
+
287
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
288
+ rect 100, 100, 300, 200
289
+ rect 200, 200, 300, 200
290
+ EXPECTED
291
+ group1 = createShape GROUP
292
+ group2 = createShape GROUP
293
+ group1.addChild createShape(RECT, 100, 100, 300, 200)
294
+ group1.addChild group2
295
+ group2.addChild createShape(RECT, 200, 200, 300, 200)
296
+ shape group1
297
+ ACTUAL
298
+ end
299
+
300
+ def test_shape_with_non_groups()
301
+ assert_equal_draw '', <<~ACTUAL
302
+ s = createShape
303
+ s.addChild createShape(RECT, 100, 100, 300, 200)
304
+ s.addChild createShape(RECT, 200, 200, 300, 200)
305
+ shape s
306
+ ACTUAL
307
+ end
308
+
309
+ def test_beginShape_points()
310
+ src = <<~END
311
+ strokeWeight 200
312
+ beginShape POINTS
313
+ vertex 200, 300
314
+ vertex 500, 600
315
+ END
316
+ assert_p5_fill src, 'endShape'
317
+ assert_p5_stroke src, 'endShape', threshold: THRESHOLD_TO_BE_FIXED
318
+ assert_p5_fill_stroke src, 'endShape', threshold: THRESHOLD_TO_BE_FIXED
319
+ end
320
+
321
+ def test_beginShape_lines()
322
+ src = <<~END
323
+ strokeWeight 200
324
+ beginShape LINES
325
+ vertex 100, 200
326
+ vertex 300, 400
327
+ vertex 500, 600
328
+ vertex 700, 800
329
+ END
330
+ assert_p5_fill src, 'endShape'
331
+ assert_p5_stroke src, 'endShape'
332
+ assert_p5_fill_stroke src, 'endShape'
333
+ assert_p5_fill src, 'endShape CLOSE'
334
+ assert_p5_stroke src, 'endShape CLOSE'
335
+ assert_p5_fill_stroke src, 'endShape CLOSE'
336
+ end
337
+
338
+ def test_beginShape_triangles()
339
+ src = <<~END
340
+ beginShape TRIANGLES
341
+ vertex 100, 100
342
+ vertex 100, 500
343
+ vertex 400, 200
344
+ vertex 500, 100
345
+ vertex 500, 500
346
+ vertex 900, 200
347
+ END
348
+ assert_p5_fill src, 'endShape'
349
+ assert_p5_stroke src, 'endShape'
350
+ assert_p5_fill_stroke src, 'endShape'
351
+ assert_p5_fill src, 'endShape CLOSE'
352
+ assert_p5_stroke src, 'endShape CLOSE'
353
+ assert_p5_fill_stroke src, 'endShape CLOSE'
354
+ end
355
+
356
+ def test_beginShape_triangle_fan()
357
+ src = <<~END
358
+ beginShape TRIANGLE_FAN
359
+ vertex 100, 100
360
+ vertex 100, 500
361
+ vertex 200, 600
362
+ vertex 300, 500
363
+ vertex 400, 600
364
+ vertex 500, 200
365
+ vertex 400, 100
366
+ END
367
+ assert_p5_fill src, 'endShape'
368
+ assert_p5_stroke src, 'endShape', threshold: 0.98
369
+ assert_p5_fill_stroke src, 'endShape', threshold: 0.98
370
+ assert_p5_fill src, 'endShape CLOSE'
371
+ assert_p5_stroke src, 'endShape CLOSE', threshold: 0.98
372
+ assert_p5_fill_stroke src, 'endShape CLOSE', threshold: 0.98
373
+ end
374
+
375
+ def test_beginShape_triangle_strip()
376
+ src = <<~END
377
+ beginShape TRIANGLE_STRIP
378
+ vertex 100, 100
379
+ vertex 100, 900
380
+ vertex 500, 200
381
+ vertex 500, 800
382
+ vertex 900, 100
383
+ vertex 900, 900
384
+ END
385
+ assert_p5_fill src, 'endShape'
386
+ assert_p5_stroke src, 'endShape'
387
+ assert_p5_fill_stroke src, 'endShape'
388
+ assert_p5_fill src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
389
+ assert_p5_stroke src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
390
+ assert_p5_fill_stroke src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
391
+ end
392
+
393
+ def test_beginShape_quads()
394
+ src = <<~END
395
+ beginShape QUADS
396
+ vertex 100, 100
397
+ vertex 200, 500
398
+ vertex 300, 400
399
+ vertex 400, 200
400
+ vertex 500, 100
401
+ vertex 600, 500
402
+ vertex 700, 400
403
+ vertex 800, 200
404
+ END
405
+ assert_p5_fill src, 'endShape'
406
+ assert_p5_stroke src, 'endShape'
407
+ assert_p5_fill_stroke src, 'endShape'
408
+ assert_p5_fill src, 'endShape CLOSE'
409
+ assert_p5_stroke src, 'endShape CLOSE'
410
+ assert_p5_fill_stroke src, 'endShape CLOSE'
411
+ end
412
+
413
+ def test_beginShape_quad_strip()
414
+ src = <<~END
415
+ beginShape QUAD_STRIP
416
+ vertex 100, 100
417
+ vertex 100, 500
418
+ vertex 500, 200
419
+ vertex 500, 400
420
+ vertex 900, 100
421
+ vertex 900, 500
422
+ END
423
+ assert_p5_fill src, 'endShape'
424
+ assert_p5_stroke src, 'endShape'
425
+ assert_p5_fill_stroke src, 'endShape'
426
+ assert_p5_fill src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
427
+ assert_p5_stroke src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
428
+ assert_p5_fill_stroke src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
429
+ end
430
+
431
+ def test_beginShape_tess()
432
+ src = <<~END
433
+ beginShape TESS
434
+ vertex 100, 100
435
+ vertex 100, 500
436
+ vertex 500, 500
437
+ vertex 500, 400
438
+ vertex 300, 400
439
+ vertex 300, 300
440
+ vertex 500, 300
441
+ vertex 500, 100
442
+ END
443
+ assert_p5_fill src, 'endShape'
444
+ assert_p5_stroke src, 'endShape'
445
+ assert_p5_fill_stroke src, 'endShape'
446
+ assert_p5_fill src, 'endShape CLOSE'
447
+ assert_p5_stroke src, 'endShape CLOSE'
448
+ assert_p5_fill_stroke src, 'endShape CLOSE'
449
+ end
450
+
451
+ def test_beginShape_polygon()
452
+ src = <<~END
453
+ beginShape
454
+ vertex 100, 100
455
+ vertex 100, 500
456
+ vertex 500, 500
457
+ vertex 500, 400
458
+ vertex 300, 400
459
+ vertex 300, 300
460
+ vertex 500, 300
461
+ vertex 500, 100
462
+ END
463
+ assert_p5_fill src, 'endShape'
464
+ assert_p5_stroke src, 'endShape'
465
+ assert_p5_fill_stroke src, 'endShape'
466
+ assert_p5_fill src, 'endShape CLOSE'
467
+ assert_p5_stroke src, 'endShape CLOSE'
468
+ assert_p5_fill_stroke src, 'endShape CLOSE'
469
+ end
470
+
73
471
  def test_lerp()
74
472
  g = graphics
75
473
 
@@ -93,4 +491,52 @@ class TestGraphicsContext < Test::Unit::TestCase
93
491
  assert_equal c[ 70, 80, 90], g.lerpColor(c[10, 20, 30], c[50, 60, 70], 1.5)
94
492
  end
95
493
 
96
- end# TestGraphics
494
+ def test_createShape_line()
495
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
496
+ line 100, 200, 800, 900
497
+ EXPECTED
498
+ shape createShape(LINE, 100, 200, 800, 900)
499
+ ACTUAL
500
+ end
501
+
502
+ def test_createShape_rect()
503
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
504
+ rect 100, 200, 500, 600
505
+ EXPECTED
506
+ shape createShape(RECT, 100, 200, 500, 600)
507
+ ACTUAL
508
+ end
509
+
510
+ def test_createShape_ellipse()
511
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
512
+ ellipse 500, 600, 300, 400
513
+ EXPECTED
514
+ shape createShape(ELLIPSE, 500, 600, 300, 400)
515
+ ACTUAL
516
+ end
517
+
518
+ def test_createShape_arc()
519
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
520
+ arc 500, 600, 300, 400, 0, PI / 2
521
+ EXPECTED
522
+ shape createShape(ARC, 500, 600, 300, 400, 0, PI / 2)
523
+ ACTUAL
524
+ end
525
+
526
+ def test_createShape_triangle()
527
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
528
+ triangle 100,100, 100,500, 400,200
529
+ EXPECTED
530
+ shape createShape(TRIANGLE, 100,100, 100,500, 400,200)
531
+ ACTUAL
532
+ end
533
+
534
+ def test_createShape_quad()
535
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
536
+ quad 100,100, 100,500, 500,500, 600,100
537
+ EXPECTED
538
+ shape createShape(QUAD, 100,100, 100,500, 500,500, 600,100)
539
+ ACTUAL
540
+ end
541
+
542
+ end# TestGraphicsContext