-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTestReadImages.m
117 lines (101 loc) · 3.76 KB
/
TestReadImages.m
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
112
113
114
115
function [mark] = TestReadImages(mode,specifiedFunctionName)
% Tests the ReadImages function either with test or marking data
% note that no marks are awarded if the function returns values of the
% wrong type.
%
% It has two optional arguments, mode and specifiedFunctionName,
% mode specifies whether to use test or marking data
% (marking data is only provided after the deadline is passed)
% specifiedFunctionName can be used to specify a different filename for
% the function in the event that the author has mispelt their function name
%
% Example calls
%
% >> TestReadImages
% This will test a function called ReadImages, using the test data
%
% >> TestReadImages('mark')
% This will use the marking data rather than test data
% Remember marking data isn't released until after the deadline
% It will be similar to (but not identical to) the test data
%
% >> TestReadImages('test','ReadImages')
% This will test the function called ReadImages
%
% >> TestReadImages('mark','ReadImages')
% This will test the function called ReadImages using the marking data
% rather than the test data.
%
% Remember ReadImages takes two inputs in the following order:
% 1) A string containing the name of the directory the images are contained in
% 2) A 1xn 1D cell array containing n strings where each element is a
% filename of an image to read
%
% It returns one output
% A 1xn 1D cell array containing n images, where each element is an RGB
% image (recall RGB images stored as 3D arrays of uint8 values ranging from
% 0 to 255). The first image will correspond to the first filename from
% the list of filenames
%
% author: Peter Bier
% default the mode and function name, if no optional args specified
if nargin == 0
mode = 'test'; % default to using test data
functionName = 'ReadImages';
elseif nargin == 1
% one input argument, mode will have been specified, no need to default
% default functionName to that expected
functionName = 'ReadImages';
else
% two inputs, mode and specified function name both passed in
% no need to default mode but set functionName
functionName = specifiedFunctionName;
end
pwd
% set up data with inputs and expected outputs
% can use test data or marking data
% marking data only supplied after the due date
if strcmp(mode,'test')
load TestDataReadImages;
else
try
load MarkingDataReadImages;
catch ex
disp('Error loading marking data');
%disp(ex);
disp('Marking data is not released until after the due date')
disp('Once released you need to put in in the TestScripts directory')
return
end
end
input1 = ReadImagesInput1;
input2 = ReadImagesInput2;
% set up the base directory to be the one containing
% TestReadImages.m
% this directory will also contain a number of subfolders and images
basedir = which('TestReadImages');
basedir = basedir(1:(length(basedir)-length('TestReadImages.m')));
expectedOutput1 = ReadImagesExpectedOutput;
purpose = ReadImagesTestPurpose;
totalPassed = 0;
numTests = length(input1);
% run all tests, comparing expected output against actual output
for i = 1:numTests
m = sprintf('%s Test %i\n\tPurpose:\t%s \n\tResult:\t\t', functionName, i, purpose{i});
try
output1{i} = feval(functionName,[basedir input1{i}],input2{i});
% check if result returned closely matches the expected result
if isequal(expectedOutput1{i},output1{i})
totalPassed = totalPassed + 1;
disp([m 'Passed test']);
else
disp([m 'FAILED test']);
end
catch ex
disp([m 'FAILED test']);
ProcessMarkingException(ex, functionName)
end
end
% display marks summary
allocatedMarks = 3;
mark = ProcessMarksSummary(functionName,totalPassed,numTests,allocatedMarks);