processing 0.5.30 → 0.5.32

Sign up to get free protection for your applications and to get access to all the features.
@@ -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,90 @@ 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
+
79
+ def test_textFont()
80
+ graphics do |g|
81
+ arial10 = g.createFont 'Arial', 10
82
+ helvetica11 = g.createFont 'Helvetica', 11
83
+
84
+ font = -> {g.instance_variable_get(:@textFont__).getInternal__}
85
+ painterFont = -> {g.instance_variable_get(:@painter__).font}
86
+
87
+ assert_not_nil font[] .name
88
+ assert_not_equal 'Arial', font[] .name
89
+ assert_equal 12, font[] .size
90
+ assert_equal 12, painterFont[].size
91
+
92
+ g.textFont arial10
93
+ assert_equal 'Arial', font[] .name
94
+ assert_equal 10, font[] .size
95
+ assert_equal 10, painterFont[].size
96
+
97
+ g.push do
98
+ g.textFont helvetica11
99
+ assert_equal 'Helvetica', font[] .name
100
+ assert_equal 11, font[] .size
101
+ assert_equal 11, painterFont[].size
102
+ end
103
+
104
+ assert_equal 'Arial', font[] .name
105
+ assert_equal 10, font[] .size
106
+ assert_equal 10, painterFont[].size
107
+
108
+ g.push do
109
+ g.textFont arial10, 13
110
+ assert_equal 'Arial', font[] .name
111
+ assert_equal 13, font[] .size
112
+ assert_equal 13, painterFont[].size
113
+ end
114
+
115
+ assert_equal 'Arial', font[] .name
116
+ assert_equal 10, font[] .size
117
+ assert_equal 10, painterFont[].size
118
+ end
119
+ end
120
+
121
+ def test_textSize()
122
+ graphics do |g|
123
+ font = -> {g.instance_variable_get(:@textFont__).getInternal__}
124
+ painterFont = -> {g.instance_variable_get(:@painter__).font}
125
+
126
+ assert_equal 12, font[] .size
127
+ assert_equal 12, painterFont[].size
128
+
129
+ g.push do
130
+ g.textSize 10
131
+ assert_equal 10, font[] .size
132
+ assert_equal 10, painterFont[].size
133
+ end
134
+
135
+ assert_equal 12, font[] .size
136
+ assert_equal 12, painterFont[].size
137
+ end
138
+ end
139
+
60
140
  def test_clear()
61
- colors = -> g {get_pixels(g).map(&:to_a).flatten.uniq}
141
+ colors = -> g {get_pixels(g).uniq}
62
142
 
63
143
  g = graphics
64
144
  assert_equal [0], colors[g]
@@ -70,6 +150,534 @@ class TestGraphicsContext < Test::Unit::TestCase
70
150
  assert_equal [0], colors[g]
71
151
  end
72
152
 
153
+ def test_point()
154
+ src = 'strokeWeight 300; point 500, 600'
155
+ assert_p5_fill src
156
+ assert_p5_stroke src, threshold: THRESHOLD_TO_BE_FIXED
157
+ assert_p5_fill_stroke src, threshold: THRESHOLD_TO_BE_FIXED
158
+ end
159
+
160
+ def test_line()
161
+ src = 'strokeWeight 100; line 100, 200, 500, 600'
162
+ assert_p5_fill src
163
+ assert_p5_stroke src
164
+ assert_p5_fill_stroke src
165
+ end
166
+
167
+ def test_rect()
168
+ src = 'rect 100, 200, 300, 400'
169
+ assert_p5_fill src
170
+ assert_p5_stroke src
171
+ assert_p5_fill_stroke src
172
+ end
173
+
174
+ def test_rect_with_rectMode()
175
+ assert_p5_draw 'rectMode CORNER; rect 100, 200, 300, 400'
176
+ assert_p5_draw 'rectMode CORNERS; rect 100, 200, 300, 500'
177
+ assert_p5_draw 'rectMode CENTER; rect 400, 500, 300, 400'
178
+ assert_p5_draw 'rectMode RADIUS; rect 400, 500, 300, 400'
179
+ end
180
+
181
+ def test_ellipse()
182
+ src = 'ellipse 500, 600, 300, 400'
183
+ assert_p5_fill src
184
+ assert_p5_stroke src
185
+ assert_p5_fill_stroke src
186
+ end
187
+
188
+ def test_ellipse_with_ellipseMode()
189
+ assert_p5_draw 'ellipseMode CORNER; ellipse 100, 200, 300, 400'
190
+ assert_p5_draw 'ellipseMode CORNERS; ellipse 100, 200, 300, 500'
191
+ assert_p5_draw 'ellipseMode CENTER; ellipse 400, 500, 300, 400'
192
+ assert_p5_draw 'ellipseMode RADIUS; ellipse 400, 500, 300, 400'
193
+ end
194
+
195
+ def test_circle()
196
+ src = 'circle 500, 600, 300'
197
+ assert_p5_fill src
198
+ assert_p5_stroke src
199
+ assert_p5_fill_stroke src
200
+ end
201
+
202
+ def test_circle_with_ellipseMode()
203
+ assert_p5_draw 'ellipseMode CORNER; circle 100, 200, 300'
204
+ assert_p5_draw 'ellipseMode CORNERS; circle 100, 200, 300'
205
+ assert_p5_draw 'ellipseMode CENTER; circle 400, 500, 300'
206
+ assert_p5_draw 'ellipseMode RADIUS; circle 400, 500, 300'
207
+ end
208
+
209
+ def test_arc()
210
+ src = 'arc 500, 600, 300, 400, PI * 0.25, PI * 0.75'
211
+ assert_p5_fill src, threshold: THRESHOLD_TO_BE_FIXED
212
+ assert_p5_stroke src, threshold: THRESHOLD_TO_BE_FIXED
213
+ assert_p5_fill_stroke src, threshold: THRESHOLD_TO_BE_FIXED
214
+ end
215
+
216
+ def test_arc_with_ellipseMode()
217
+ assert_p5_draw 'ellipseMode CORNER; arc 100, 200, 300, 400, 0, PI * 0.75',
218
+ threshold: THRESHOLD_TO_BE_FIXED
219
+ assert_p5_draw 'ellipseMode CORNERS; arc 100, 200, 300, 500, 0, PI * 0.75',
220
+ threshold: THRESHOLD_TO_BE_FIXED
221
+ assert_p5_draw 'ellipseMode CENTER; arc 400, 500, 300, 400, 0, PI * 0.75',
222
+ threshold: THRESHOLD_TO_BE_FIXED
223
+ assert_p5_draw 'ellipseMode RADIUS; arc 400, 500, 300, 400, 0, PI * 0.75',
224
+ threshold: THRESHOLD_TO_BE_FIXED
225
+ end
226
+
227
+ def test_square()
228
+ src = 'square 500, 600, 300'
229
+ assert_p5_fill src
230
+ assert_p5_stroke src
231
+ assert_p5_fill_stroke src
232
+ end
233
+
234
+ def test_triangle()
235
+ src = 'triangle 100,100, 100,500, 500,200'
236
+ assert_p5_fill src
237
+ assert_p5_stroke src
238
+ assert_p5_fill_stroke src
239
+ end
240
+
241
+ def test_quad()
242
+ src = 'quad 100,100, 100,500, 500,500, 600,100'
243
+ assert_p5_fill src
244
+ assert_p5_stroke src
245
+ assert_p5_fill_stroke src
246
+ end
247
+
248
+ def test_curve()
249
+ src = 'curve 100,100, 100,500, 500,500, 600,100'
250
+ assert_p5_fill src, threshold: 0
251
+ assert_p5_stroke src, threshold: 0
252
+ assert_p5_fill_stroke src, threshold: 0
253
+ end
254
+
255
+ def test_bezier()
256
+ src = 'curve 100,100, 100,500, 500,500, 600,100'
257
+ assert_p5_fill src, threshold: 0
258
+ assert_p5_stroke src, threshold: 0
259
+ assert_p5_fill_stroke src, threshold: 0
260
+ end
261
+
262
+ def test_shape_with_shapeMode_corner()
263
+ header = 'noStroke'
264
+
265
+ assert_equal_draw header, <<~EXPECTED, <<~ACTUAL
266
+ rect 100, 200, 300, 400
267
+ EXPECTED
268
+ shapeMode CORNER
269
+ shape createShape(RECT, 100, 200, 300, 400)
270
+ ACTUAL
271
+
272
+ assert_equal_draw header, <<~EXPECTED, <<~ACTUAL
273
+ rect 100, 200, 300, 400
274
+ EXPECTED
275
+ shapeMode CORNER
276
+ shape createShape(RECT, 0, 0, 300, 400), 100, 200
277
+ ACTUAL
278
+
279
+ assert_equal_draw header, <<~EXPECTED, <<~ACTUAL
280
+ rect 100, 200, 300, 400
281
+ EXPECTED
282
+ shapeMode CORNER
283
+ shape createShape(RECT, 0, 0, 500, 600), 100, 200, 300, 400
284
+ ACTUAL
285
+ end
286
+
287
+ def test_shape_with_shapeMode_corners()
288
+ header = 'noStroke'
289
+
290
+ assert_equal_draw header, <<~EXPECTED, <<~ACTUAL
291
+ rect 100, 200, 300, 400
292
+ EXPECTED
293
+ shapeMode CORNERS
294
+ shape createShape(RECT, 100, 200, 300, 400)
295
+ ACTUAL
296
+
297
+ assert_equal_draw header, <<~EXPECTED, <<~ACTUAL
298
+ rect 100, 200, 200, 200
299
+ EXPECTED
300
+ shapeMode CORNERS
301
+ shape createShape(RECT, 0, 0, 300, 400), 100, 200
302
+ ACTUAL
303
+
304
+ assert_equal_draw header, <<~EXPECTED, <<~ACTUAL
305
+ rect 100, 200, 200, 200
306
+ EXPECTED
307
+ shapeMode CORNERS
308
+ shape createShape(RECT, 0, 0, 500, 600), 100, 200, 300, 400
309
+ ACTUAL
310
+ end
311
+
312
+ def test_shape_with_shapeMode_center()
313
+ header = 'noStroke'
314
+
315
+ assert_equal_draw header, <<~EXPECTED, <<~ACTUAL
316
+ rect 400, 400, 200, 400
317
+ EXPECTED
318
+ shapeMode CENTER
319
+ shape createShape(RECT, 500, 600, 200, 400)
320
+ ACTUAL
321
+
322
+ assert_equal_draw header, <<~EXPECTED, <<~ACTUAL
323
+ rect 400, 400, 200, 400
324
+ EXPECTED
325
+ shapeMode CENTER
326
+ shape createShape(RECT, 0, 0, 200, 400), 500, 600
327
+ ACTUAL
328
+
329
+ assert_equal_draw header, <<~EXPECTED, <<~ACTUAL
330
+ rect 400, 400, 200, 400
331
+ EXPECTED
332
+ shapeMode CENTER
333
+ shape createShape(RECT, 0, 0, 700, 800), 500, 600, 200, 400
334
+ ACTUAL
335
+ end
336
+
337
+ def test_shape_with_groups()
338
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
339
+ rect 100, 100, 300, 200
340
+ rect 200, 200, 300, 200
341
+ EXPECTED
342
+ group = createShape GROUP
343
+ group.addChild createShape(RECT, 100, 100, 300, 200)
344
+ group.addChild createShape(RECT, 200, 200, 300, 200)
345
+ shape group
346
+ ACTUAL
347
+
348
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
349
+ rect 100, 100, 300, 200
350
+ rect 200, 200, 300, 200
351
+ EXPECTED
352
+ group1 = createShape GROUP
353
+ group2 = createShape GROUP
354
+ group1.addChild createShape(RECT, 100, 100, 300, 200)
355
+ group1.addChild group2
356
+ group2.addChild createShape(RECT, 200, 200, 300, 200)
357
+ shape group1
358
+ ACTUAL
359
+ end
360
+
361
+ def test_shape_with_non_groups()
362
+ assert_equal_draw '', <<~ACTUAL
363
+ s = createShape
364
+ s.addChild createShape(RECT, 100, 100, 300, 200)
365
+ s.addChild createShape(RECT, 200, 200, 300, 200)
366
+ shape s
367
+ ACTUAL
368
+ end
369
+
370
+ def test_beginShape_points()
371
+ src = <<~END
372
+ strokeWeight 200
373
+ beginShape POINTS
374
+ vertex 200, 300
375
+ vertex 500, 600
376
+ END
377
+ assert_p5_fill src, 'endShape'
378
+ assert_p5_stroke src, 'endShape', threshold: THRESHOLD_TO_BE_FIXED
379
+ assert_p5_fill_stroke src, 'endShape', threshold: THRESHOLD_TO_BE_FIXED
380
+ end
381
+
382
+ def test_beginShape_lines()
383
+ src = <<~END
384
+ strokeWeight 200
385
+ beginShape LINES
386
+ vertex 100, 200
387
+ vertex 300, 400
388
+ vertex 500, 600
389
+ vertex 700, 800
390
+ END
391
+ assert_p5_fill src, 'endShape'
392
+ assert_p5_stroke src, 'endShape'
393
+ assert_p5_fill_stroke src, 'endShape'
394
+ assert_p5_fill src, 'endShape CLOSE'
395
+ assert_p5_stroke src, 'endShape CLOSE'
396
+ assert_p5_fill_stroke src, 'endShape CLOSE'
397
+ end
398
+
399
+ def test_beginShape_triangles()
400
+ src = <<~END
401
+ beginShape TRIANGLES
402
+ vertex 100, 100
403
+ vertex 100, 500
404
+ vertex 400, 200
405
+ vertex 500, 100
406
+ vertex 500, 500
407
+ vertex 900, 200
408
+ END
409
+ assert_p5_fill src, 'endShape'
410
+ assert_p5_stroke src, 'endShape'
411
+ assert_p5_fill_stroke src, 'endShape'
412
+ assert_p5_fill src, 'endShape CLOSE'
413
+ assert_p5_stroke src, 'endShape CLOSE'
414
+ assert_p5_fill_stroke src, 'endShape CLOSE'
415
+ end
416
+
417
+ def test_beginShape_triangle_fan()
418
+ src = <<~END
419
+ beginShape TRIANGLE_FAN
420
+ vertex 100, 100
421
+ vertex 100, 500
422
+ vertex 200, 600
423
+ vertex 300, 500
424
+ vertex 400, 600
425
+ vertex 500, 200
426
+ vertex 400, 100
427
+ END
428
+ assert_p5_fill src, 'endShape'
429
+ assert_p5_stroke src, 'endShape', threshold: 0.98
430
+ assert_p5_fill_stroke src, 'endShape', threshold: 0.98
431
+ assert_p5_fill src, 'endShape CLOSE'
432
+ assert_p5_stroke src, 'endShape CLOSE', threshold: 0.98
433
+ assert_p5_fill_stroke src, 'endShape CLOSE', threshold: 0.98
434
+ end
435
+
436
+ def test_beginShape_triangle_strip()
437
+ src = <<~END
438
+ beginShape TRIANGLE_STRIP
439
+ vertex 100, 100
440
+ vertex 100, 900
441
+ vertex 500, 200
442
+ vertex 500, 800
443
+ vertex 900, 100
444
+ vertex 900, 900
445
+ END
446
+ assert_p5_fill src, 'endShape'
447
+ assert_p5_stroke src, 'endShape'
448
+ assert_p5_fill_stroke src, 'endShape'
449
+ assert_p5_fill src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
450
+ assert_p5_stroke src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
451
+ assert_p5_fill_stroke src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
452
+ end
453
+
454
+ def test_beginShape_quads()
455
+ src = <<~END
456
+ beginShape QUADS
457
+ vertex 100, 100
458
+ vertex 200, 500
459
+ vertex 300, 400
460
+ vertex 400, 200
461
+ vertex 500, 100
462
+ vertex 600, 500
463
+ vertex 700, 400
464
+ vertex 800, 200
465
+ END
466
+ assert_p5_fill src, 'endShape'
467
+ assert_p5_stroke src, 'endShape'
468
+ assert_p5_fill_stroke src, 'endShape'
469
+ assert_p5_fill src, 'endShape CLOSE'
470
+ assert_p5_stroke src, 'endShape CLOSE'
471
+ assert_p5_fill_stroke src, 'endShape CLOSE'
472
+ end
473
+
474
+ def test_beginShape_quad_strip()
475
+ src = <<~END
476
+ beginShape QUAD_STRIP
477
+ vertex 100, 100
478
+ vertex 100, 500
479
+ vertex 500, 200
480
+ vertex 500, 400
481
+ vertex 900, 100
482
+ vertex 900, 500
483
+ END
484
+ assert_p5_fill src, 'endShape'
485
+ assert_p5_stroke src, 'endShape'
486
+ assert_p5_fill_stroke src, 'endShape'
487
+ assert_p5_fill src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
488
+ assert_p5_stroke src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
489
+ assert_p5_fill_stroke src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
490
+ end
491
+
492
+ def test_beginShape_tess()
493
+ src = <<~END
494
+ beginShape TESS
495
+ vertex 100, 100
496
+ vertex 100, 500
497
+ vertex 500, 500
498
+ vertex 500, 400
499
+ vertex 300, 400
500
+ vertex 300, 300
501
+ vertex 500, 300
502
+ vertex 500, 100
503
+ END
504
+ assert_p5_fill src, 'endShape'
505
+ assert_p5_stroke src, 'endShape'
506
+ assert_p5_fill_stroke src, 'endShape'
507
+ assert_p5_fill src, 'endShape CLOSE'
508
+ assert_p5_stroke src, 'endShape CLOSE'
509
+ assert_p5_fill_stroke src, 'endShape CLOSE'
510
+ end
511
+
512
+ def test_beginShape_polygon()
513
+ src = <<~END
514
+ beginShape
515
+ vertex 100, 100
516
+ vertex 100, 500
517
+ vertex 500, 500
518
+ vertex 500, 400
519
+ vertex 300, 400
520
+ vertex 300, 300
521
+ vertex 500, 300
522
+ vertex 500, 100
523
+ END
524
+ assert_p5_fill src, 'endShape'
525
+ assert_p5_stroke src, 'endShape'
526
+ assert_p5_fill_stroke src, 'endShape'
527
+ assert_p5_fill src, 'endShape CLOSE'
528
+ assert_p5_stroke src, 'endShape CLOSE'
529
+ assert_p5_fill_stroke src, 'endShape CLOSE'
530
+ end
531
+
532
+ def test_beginShape_with_fill()
533
+ assert_equal_draw <<~HEADER, <<~EXPECTED, <<~ACTUAL
534
+ noStroke
535
+ HEADER
536
+ fill 0, 255, 0
537
+ rect 100, 100, 500, 400
538
+ EXPECTED
539
+ beginShape
540
+ fill 0, 255, 0
541
+ vertex 100, 100
542
+ vertex 600, 100
543
+ vertex 600, 500
544
+ vertex 100, 500
545
+ endShape
546
+ ACTUAL
547
+ end
548
+
549
+ def test_curveVertex()
550
+ src = <<~END
551
+ beginShape
552
+ curveVertex 100, 100
553
+ curveVertex 800, 100
554
+ curveVertex 800, 800
555
+ curveVertex 100, 800
556
+ END
557
+ assert_p5_fill src, 'endShape'
558
+ assert_p5_stroke src, 'endShape'
559
+ assert_p5_fill_stroke src, 'endShape'
560
+ assert_p5_fill src, 'endShape CLOSE'
561
+ assert_p5_stroke src, 'endShape CLOSE'
562
+ assert_p5_fill_stroke src, 'endShape CLOSE'
563
+
564
+ src = <<~END
565
+ beginShape
566
+ curveVertex 200, 200
567
+ curveVertex 200, 200
568
+ curveVertex 800, 200
569
+ curveVertex 800, 400
570
+ curveVertex 200, 400
571
+ curveVertex 200, 800
572
+ curveVertex 800, 800
573
+ curveVertex 800, 700
574
+ curveVertex 800, 700
575
+ END
576
+ assert_p5_fill src, 'endShape', threshold: THRESHOLD_TO_BE_FIXED
577
+ assert_p5_stroke src, 'endShape'
578
+ assert_p5_fill_stroke src, 'endShape', threshold: THRESHOLD_TO_BE_FIXED
579
+ assert_p5_fill src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
580
+ assert_p5_stroke src, 'endShape CLOSE'
581
+ assert_p5_fill_stroke src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
582
+ end
583
+
584
+ def test_bezierVertex()
585
+ src = <<~END
586
+ beginShape
587
+ vertex 100, 100
588
+ bezierVertex 900, 100, 900, 900, 200, 500
589
+ END
590
+ assert_p5_fill src, 'endShape'
591
+ assert_p5_stroke src, 'endShape'
592
+ assert_p5_fill_stroke src, 'endShape'
593
+ assert_p5_fill src, 'endShape CLOSE'
594
+ assert_p5_stroke src, 'endShape CLOSE'
595
+ assert_p5_fill_stroke src, 'endShape CLOSE'
596
+
597
+ src = <<~END
598
+ beginShape
599
+ vertex 100, 100
600
+ bezierVertex 900, 100, 900, 500, 300, 500
601
+ bezierVertex 100, 900, 900, 900, 900, 600
602
+ END
603
+ assert_p5_fill src, 'endShape', threshold: THRESHOLD_TO_BE_FIXED
604
+ assert_p5_stroke src, 'endShape'
605
+ assert_p5_fill_stroke src, 'endShape', threshold: THRESHOLD_TO_BE_FIXED
606
+ assert_p5_fill src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
607
+ assert_p5_stroke src, 'endShape CLOSE'
608
+ assert_p5_fill_stroke src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
609
+ end
610
+
611
+ def test_quadraticVertex()
612
+ src = <<~END
613
+ beginShape
614
+ vertex 100, 100
615
+ quadraticVertex 800, 500, 200, 800
616
+ END
617
+ assert_p5_fill src, 'endShape'
618
+ assert_p5_stroke src, 'endShape'
619
+ assert_p5_fill_stroke src, 'endShape'
620
+ assert_p5_fill src, 'endShape CLOSE'
621
+ assert_p5_stroke src, 'endShape CLOSE'
622
+ assert_p5_fill_stroke src, 'endShape CLOSE'
623
+
624
+ src = <<~END
625
+ beginShape
626
+ vertex 100, 100
627
+ quadraticVertex 800, 100, 500, 500
628
+ quadraticVertex 100, 800, 800, 800
629
+ END
630
+ assert_p5_fill src, 'endShape', threshold: THRESHOLD_TO_BE_FIXED
631
+ assert_p5_stroke src, 'endShape'
632
+ assert_p5_fill_stroke src, 'endShape', threshold: THRESHOLD_TO_BE_FIXED
633
+ assert_p5_fill src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
634
+ assert_p5_stroke src, 'endShape CLOSE'
635
+ assert_p5_fill_stroke src, 'endShape CLOSE', threshold: THRESHOLD_TO_BE_FIXED
636
+ end
637
+
638
+ def test_contour()
639
+ src = <<~END
640
+ beginShape
641
+ vertex 100, 100
642
+ vertex 100, 900
643
+ vertex 900, 900
644
+ vertex 900, 100
645
+ beginContour
646
+ vertex 200, 200
647
+ vertex 800, 200
648
+ vertex 700, 700
649
+ vertex 200, 800
650
+ endContour
651
+ END
652
+ assert_p5_fill src, 'endShape'
653
+ assert_p5_stroke src, 'endShape'
654
+ assert_p5_fill_stroke src, 'endShape'
655
+ assert_p5_fill src, 'endShape CLOSE'
656
+ assert_p5_stroke src, 'endShape CLOSE'
657
+ assert_p5_fill_stroke src, 'endShape CLOSE'
658
+ end
659
+
660
+ def test_pixels()
661
+ g = graphics 2, 2
662
+
663
+ g.loadPixels
664
+ assert_equal [0] * 4, g.pixels
665
+ assert_equal [0] * 4, g.getInternal__.pixels
666
+
667
+ g.pixels.replace [0xffff0000, 0xff00ff00, 0xff0000ff, 0xff000000]
668
+ assert_equal [0xffff0000, 0xff00ff00, 0xff0000ff, 0xff000000], g.pixels
669
+ assert_equal [0] * 4, g.getInternal__.pixels
670
+
671
+ g.updatePixels
672
+ assert_nil g.pixels
673
+ assert_equal [0xffff0000, 0xff00ff00, 0xff0000ff, 0xff000000], g.getInternal__.pixels
674
+ assert_nothing_raised {g.updatePixels}
675
+
676
+ g.loadPixels
677
+ g.pixels.replace [0xff000000]
678
+ assert_raise(ArgumentError) {g.updatePixels}
679
+ end
680
+
73
681
  def test_lerp()
74
682
  g = graphics
75
683
 
@@ -93,4 +701,62 @@ class TestGraphicsContext < Test::Unit::TestCase
93
701
  assert_equal c[ 70, 80, 90], g.lerpColor(c[10, 20, 30], c[50, 60, 70], 1.5)
94
702
  end
95
703
 
96
- end# TestGraphics
704
+ def test_createFont()
705
+ g = graphics
706
+
707
+ assert_not_nil g.createFont(nil, nil).getInternal__.name
708
+ assert_equal 'Arial', g.createFont('Arial', nil).getInternal__.name
709
+
710
+ assert_equal 12, g.createFont(nil, nil).getInternal__.size
711
+ assert_equal 10, g.createFont(nil, 10) .getInternal__.size
712
+ end
713
+
714
+ def test_createShape_line()
715
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
716
+ line 100, 200, 800, 900
717
+ EXPECTED
718
+ shape createShape(LINE, 100, 200, 800, 900)
719
+ ACTUAL
720
+ end
721
+
722
+ def test_createShape_rect()
723
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
724
+ rect 100, 200, 500, 600
725
+ EXPECTED
726
+ shape createShape(RECT, 100, 200, 500, 600)
727
+ ACTUAL
728
+ end
729
+
730
+ def test_createShape_ellipse()
731
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
732
+ ellipse 500, 600, 300, 400
733
+ EXPECTED
734
+ shape createShape(ELLIPSE, 500, 600, 300, 400)
735
+ ACTUAL
736
+ end
737
+
738
+ def test_createShape_arc()
739
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
740
+ arc 500, 600, 300, 400, 0, PI / 2
741
+ EXPECTED
742
+ shape createShape(ARC, 500, 600, 300, 400, 0, PI / 2)
743
+ ACTUAL
744
+ end
745
+
746
+ def test_createShape_triangle()
747
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
748
+ triangle 100,100, 100,500, 400,200
749
+ EXPECTED
750
+ shape createShape(TRIANGLE, 100,100, 100,500, 400,200)
751
+ ACTUAL
752
+ end
753
+
754
+ def test_createShape_quad()
755
+ assert_equal_draw <<~EXPECTED, <<~ACTUAL
756
+ quad 100,100, 100,500, 500,500, 600,100
757
+ EXPECTED
758
+ shape createShape(QUAD, 100,100, 100,500, 500,500, 600,100)
759
+ ACTUAL
760
+ end
761
+
762
+ end# TestGraphicsContext