-
Notifications
You must be signed in to change notification settings - Fork 3
/
PictureAutograder.java
111 lines (102 loc) · 4.04 KB
/
PictureAutograder.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import java.io.File;
import java.awt.Color;
import jh61b.grader.TestResult;
/**
Example child class of the Autograder.
Has an additional test for comparing the
output of pictures.
@see Autograder
@author Brandon Lax
*/
public class PictureAutograder extends Autograder {
/**
The constructor of a picture Autograder.
*/
public PictureAutograder() {
super();
}
/**
Runs a picture diff tests for a specific file.
This currently is designed to work with the
pictures created for project 3 in Gateway
Computing Spring 2019. Each picture
was named prefix_i_j.png.
@param p the program to do diff tests on
@param prefix the initial part of the name
@param cold the cold value of the grid
@param hot the hot value of the grid
*/
public void pictureDiffTest(String p,
String prefix,
double cold,
double hot) {
String sampleName = prefix + "sample" + "_"+cold+"_"+hot+".txt.x10.jpg";
String resultName = prefix + "_"+cold+"_"+hot+".txt.x10.jpg";
TestResult trDiff = new TestResult(p +
" Picture Diff Test for map "+prefix
+ " with cold temp: " + cold +
" and Hot Temp " + hot,
"" + super.diffNum,
super.maxScore, super.visibility);
super.diffNum++;
int faliure = 0;
File fSample = new File(sampleName);
File fUser = new File(resultName);
if (fSample.exists() && fUser.exists()) {
Picture sample = new Picture(sampleName);
Picture result = new Picture(resultName);
int[] comp = sample.compare(result, 5);
if (comp[0] != -1) {
trDiff.setScore(0);
trDiff.addOutput("Falied on index: "
+ comp[0] + ", " +
comp[1] + " Due to a difference with ");
switch(comp[2]) {
case 0:
trDiff.addOutput("The Red value of the pixel");
break;
case 1:
trDiff.addOutput("The Green value of the pixel");
break;
case 2:
trDiff.addOutput("The Blue value of the pixel");
break;
case 3:
trDiff.addOutput("The Red & Green values of the pixel");
break;
case 4:
trDiff.addOutput("The Blue & Green values of the pixel");
break;
case 5:
trDiff.addOutput("The Red & Blue values of the pixel");
break;
case 6:
trDiff.addOutput("The Red, Green & Blue values of the pixel");
break;
}
Color sampleColor = sample.get(comp[0], comp[1]);
Color resultColor = result.get(comp[0], comp[1]);
trDiff.addOutput("\n Sample Pixel Value: R = "
+ sampleColor.getRed() +
", G = " + sampleColor.getGreen()
+ ", B = " + sampleColor.getBlue());
trDiff.addOutput("\n Result Pixel Value: R = "
+ resultColor.getRed() + ", G = "
+ resultColor.getGreen() + ", B = "
+ resultColor.getBlue());
faliure = 1;
}
}
if (fSample.exists() && !fUser.exists()) {
trDiff.setScore(0);
trDiff.addOutput(resultName + " is missing.");
} else if (!fSample.exists() && fUser.exists()) {
trDiff.setScore(0);
trDiff.addOutput("The sample code broke");
} else if (faliure == 0) {
trDiff.setScore(super.maxScore);
trDiff.addOutput(sampleName + " & " + resultName + " Match.");
}
super.addTestResult(trDiff);
}
}