Skip to content

Commit ac156a0

Browse files
committed
all testcases passed
1 parent 9a0bcf0 commit ac156a0

File tree

1 file changed

+89
-39
lines changed

1 file changed

+89
-39
lines changed

src/cop5556fa17/CodeGenVisitorTest.java

Lines changed: 89 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
public class CodeGenVisitorTest implements ImageResources{
1919

2020
static boolean doPrint = true;
21-
static boolean doCreateFile = true;
21+
static boolean doCreateFile = false;
2222

2323
static void show(Object s) {
2424
if (doPrint) {
@@ -183,7 +183,37 @@ public void imageGenGreen() throws Exception{
183183
ImageSupport.compareImages(imageRef, image);
184184
keepFrame();
185185
}
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+
+"\ng[[r,a]] = cart_x[r,a];"
193+
+"\ng -> 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+
}
187217

188218

189219
@Test
@@ -340,31 +370,7 @@ public void image2() throws Exception{
340370
keepFrame();
341371
}
342372

343-
@Test
344-
public void image_whatsapp() throws Exception {
345-
devel = false;
346-
grade = true;
347-
String prog = "image5";
348-
String input = prog + "\nimage[1024,1024] g;" + "\nimage[1024,1024] h;" + "\ng <- @ 0;" + "\ng -> SCREEN;"
349-
+ "\nh[[x,y]] = ! g[x,y];" + "\nh -> SCREEN;";
350-
byte[] bytecode = genCode(input);
351-
String[] commandLineArgs = { imageFile1, imageFile2 };
352-
runCode(prog, bytecode, commandLineArgs);
353373

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-
368374
@Test
369375

370376
public void image5() throws Exception{
@@ -391,15 +397,16 @@ public void image5() throws Exception{
391397
public void image6() throws Exception{
392398
String prog = "image6";
393399
String input = prog
394-
+"\nimage[1024,1024] g;"
395-
+"\n\nimage[1024,1024] h;"
396-
+"\ng <- @ 0;"
397-
+"\n file f = @ 1;"
398-
+"\ng -> SCREEN;"
399-
+"\nh[[x,y]] = g[r,a];"
400-
+"h -> SCREEN;"
401-
+"\nh -> f;"
402-
;
400+
+"\nimage[1024,1024] g; "
401+
+ "\n\nimage[1024,1024] h;"
402+
+ "\ng <- @ 0;"
403+
+ "\ng -> SCREEN;"
404+
+ "\nh[[x,y]] = ! g[x,y];"
405+
+ "\nh -> SCREEN; "
406+
+ "\nimage[1024,1024] average; "
407+
+ "\naverage[[x,y]] = h[x,y]*3;"
408+
+ "\naverage -> SCREEN;"
409+
;
403410
byte[] bytecode = genCode(input);
404411
String[] commandLineArgs = {imageFile1};
405412
runCode(prog, bytecode, commandLineArgs);
@@ -419,7 +426,7 @@ public void image7() throws Exception{
419426
+ "\ng <- @ 0;"
420427
+ "\n file f = @ 1; "
421428
+ "\ng -> SCREEN;"
422-
+ "\nh[[x,y]] = g[r,a];"
429+
+ "\nh[[r,a]] = g[r,a];"
423430
+ "h -> SCREEN; "
424431
+ "\nh -> f;"
425432
;
@@ -428,13 +435,56 @@ public void image7() throws Exception{
428435
runCode(prog, bytecode, commandLineArgs);
429436

430437

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);
433440

434-
// assertTrue(ImageSupport.compareImages(loggedImage1, loggedImage0 ));
441+
assertTrue(ImageSupport.compareImages(loggedImage1, loggedImage0 ));
435442
keepFrame();
436443
}
437444

445+
@Test
446+
public void canvas1() throws Exception{
447+
devel = false;
448+
grade = true;
449+
String prog = "image5";
450+
451+
String input = prog
452+
+"\nimage[1024,1024] g;"
453+
+"\n\nimage[1024,1024] h;"
454+
+"\ng <- @ 0;"
455+
+"\n file f = @ 1;"
456+
+"\ng -> SCREEN;"
457+
+"\nh = g[r,a];"
458+
+"h -> SCREEN;"
459+
+"\nh -> 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+
438488

439489
@Test
440490
public void image8() throws Exception{

0 commit comments

Comments
 (0)