18
18
public class CodeGenVisitorTest implements ImageResources {
19
19
20
20
static boolean doPrint = true ;
21
- static boolean doCreateFile = true ;
21
+ static boolean doCreateFile = false ;
22
22
23
23
static void show (Object s ) {
24
24
if (doPrint ) {
@@ -183,7 +183,37 @@ public void imageGenGreen() throws Exception{
183
183
ImageSupport .compareImages (imageRef , image );
184
184
keepFrame ();
185
185
}
186
-
186
+ @ Test
187
+ public void imagePreDef () throws Exception {
188
+ //args: <imageURL>\nimage g; \ng[[r,a]] = cart_x[r,a]; \ng -> SCREEN;\n"
189
+ String prog = "imagePreDef" ;
190
+ String input = prog + " \n "
191
+ +"image g;"
192
+ +"\n g[[r,a]] = cart_x[r,a];"
193
+ +"\n g -> SCREEN;\n "
194
+ ;
195
+ byte [] bytecode = genCode (input );
196
+ String [] commandLineArgs = {};
197
+ runCode (prog , bytecode , commandLineArgs );
198
+ BufferedImage refImage0 = ImageSupport .readFromFile (imageFile1 );
199
+ BufferedImage loggedImage0 = RuntimeLog .globalImageLog .get (0 );
200
+ for (int y = 0 ; y < 256 ; y ++) {
201
+ for (int x = 0 ; x < 256 ; x ++) {
202
+ int r = RuntimeFunctions .polar_r (x , y );
203
+ int a = RuntimeFunctions .polar_a (x , y );
204
+ int cartx = RuntimeFunctions .cart_x (r , a );
205
+ int pixelRef = cartx ;
206
+ //System.out.println(cartx);
207
+ // System.out.println("****");
208
+ int pixel = ImageSupport .getPixel (loggedImage0 , x ,y );
209
+ //System.out.println(pixel);
210
+ assertEquals (pixelRef , pixel );
211
+ }
212
+
213
+ }
214
+ //assertTrue(ImageSupport.compareImages(refImage0, loggedImage0 ));
215
+ keepFrame ();
216
+ }
187
217
188
218
189
219
@ Test
@@ -340,31 +370,7 @@ public void image2() throws Exception{
340
370
keepFrame ();
341
371
}
342
372
343
- @ Test
344
- public void image_whatsapp () throws Exception {
345
- devel = false ;
346
- grade = true ;
347
- String prog = "image5" ;
348
- String input = prog + "\n image[1024,1024] g;" + "\n image[1024,1024] h;" + "\n g <- @ 0;" + "\n g -> SCREEN;"
349
- + "\n h[[x,y]] = ! g[x,y];" + "\n h -> SCREEN;" ;
350
- byte [] bytecode = genCode (input );
351
- String [] commandLineArgs = { imageFile1 , imageFile2 };
352
- runCode (prog , bytecode , commandLineArgs );
353
373
354
- BufferedImage loggedImage0 = RuntimeLog .globalImageLog .get (0 );
355
- BufferedImage loggedImage1 = RuntimeLog .globalImageLog .get (1 );
356
- for (int y = 0 ; y < 1024 ; y ++) {
357
- for (int x = 0 ; x < 1024 ; x ++) {
358
- int pixel0 = 0x00FFFFFF ^ ImageSupport .getPixel (loggedImage0 , x , y );
359
- int pixel1 = ImageSupport .getPixel (loggedImage1 , x , y );
360
- assertEquals (pixel0 , pixel1 );
361
- }
362
- }
363
-
364
- keepFrame ();
365
- }
366
-
367
-
368
374
@ Test
369
375
370
376
public void image5 () throws Exception {
@@ -391,15 +397,16 @@ public void image5() throws Exception{
391
397
public void image6 () throws Exception {
392
398
String prog = "image6" ;
393
399
String input = prog
394
- +"\n image[1024,1024] g;"
395
- +"\n \n image[1024,1024] h;"
396
- +"\n g <- @ 0;"
397
- +"\n file f = @ 1;"
398
- +"\n g -> SCREEN;"
399
- +"\n h[[x,y]] = g[r,a];"
400
- +"h -> SCREEN;"
401
- +"\n h -> f;"
402
- ;
400
+ +"\n image[1024,1024] g; "
401
+ + "\n \n image[1024,1024] h;"
402
+ + "\n g <- @ 0;"
403
+ + "\n g -> SCREEN;"
404
+ + "\n h[[x,y]] = ! g[x,y];"
405
+ + "\n h -> SCREEN; "
406
+ + "\n image[1024,1024] average; "
407
+ + "\n average[[x,y]] = h[x,y]*3;"
408
+ + "\n average -> SCREEN;"
409
+ ;
403
410
byte [] bytecode = genCode (input );
404
411
String [] commandLineArgs = {imageFile1 };
405
412
runCode (prog , bytecode , commandLineArgs );
@@ -419,7 +426,7 @@ public void image7() throws Exception{
419
426
+ "\n g <- @ 0;"
420
427
+ "\n file f = @ 1; "
421
428
+ "\n g -> SCREEN;"
422
- + "\n h[[x,y ]] = g[r,a];"
429
+ + "\n h[[r,a ]] = g[r,a];"
423
430
+ "h -> SCREEN; "
424
431
+ "\n h -> f;"
425
432
;
@@ -428,13 +435,56 @@ public void image7() throws Exception{
428
435
runCode (prog , bytecode , commandLineArgs );
429
436
430
437
431
- // BufferedImage loggedImage0 = RuntimeLog.globalImageLog.get(0);
432
- // BufferedImage loggedImage1 = RuntimeLog.globalImageLog.get(1);
438
+ BufferedImage loggedImage0 = RuntimeLog .globalImageLog .get (0 );
439
+ BufferedImage loggedImage1 = RuntimeLog .globalImageLog .get (1 );
433
440
434
- // assertTrue(ImageSupport.compareImages(loggedImage1, loggedImage0 ));
441
+ assertTrue (ImageSupport .compareImages (loggedImage1 , loggedImage0 ));
435
442
keepFrame ();
436
443
}
437
444
445
+ @ Test
446
+ public void canvas1 () throws Exception {
447
+ devel = false ;
448
+ grade = true ;
449
+ String prog = "image5" ;
450
+
451
+ String input = prog
452
+ +"\n image[1024,1024] g;"
453
+ +"\n \n image[1024,1024] h;"
454
+ +"\n g <- @ 0;"
455
+ +"\n file f = @ 1;"
456
+ +"\n g -> SCREEN;"
457
+ +"\n h = g[r,a];"
458
+ +"h -> SCREEN;"
459
+ +"\n h -> f;"
460
+ ;
461
+
462
+ byte [] bytecode = genCode (input );
463
+ //String imageURL = "\"https://westernalaskalcc.org/SiteAssets/SitePages/Western%20Alaska%20LCC/360px-Caught_some_crabs.jpg\"";
464
+ String [] commandLineArgs = { imageFile1 , imageFile2 };
465
+ runCode (prog , bytecode , commandLineArgs );
466
+
467
+ BufferedImage loggedImage0 = RuntimeLog .globalImageLog .get (0 );
468
+ BufferedImage loggedImage1 = RuntimeLog .globalImageLog .get (1 );
469
+ // BufferedImage test = ImageSupport.makeImage(1024, 1024);
470
+
471
+
472
+ for (int y = 0 ; y < 1024 ; y ++) {
473
+ for (int x = 0 ; x < 1024 ; x ++) {
474
+ int r =RuntimeFunctions .polar_r (x , y );
475
+ int a =RuntimeFunctions .polar_a (x , y );
476
+ int pixelRef = ImageSupport .getPixel (loggedImage0 , x , y );
477
+ int pixel = ImageSupport .getPixel (loggedImage1 , r ,a );
478
+ System .out .println (pixelRef +" " +pixel );
479
+ assertEquals (pixelRef , pixel );
480
+ }
481
+ }
482
+ //assertTrue(ImageSupport.compareImages(loggedImage0,loggedImage1));
483
+ keepFrame ();
484
+ //keepFrame();
485
+
486
+ }
487
+
438
488
439
489
@ Test
440
490
public void image8 () throws Exception {
0 commit comments