-
Notifications
You must be signed in to change notification settings - Fork 0
/
tFillBetweenAreaCurve.m
149 lines (119 loc) · 5.07 KB
/
tFillBetweenAreaCurve.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
classdef tFillBetweenAreaCurve < matlab.unittest.TestCase
properties
TestFigure
end
properties(TestParameter)
testSyntaxesData = createTestSyntaxesData;
testErrorData = createTestErrorData;
testInterpolateData = createTestInterpolateData;
testFigureOrderData = createTestFigureOrderData;
testEmptyData = createTestEmptyData;
end
methods(TestClassSetup)
function createFigure(testCase)
testCase.TestFigure = figure;
testCase.addTeardown(@() delete(testCase.TestFigure));
end
end
methods(Test)
function testSyntaxes(testCase, testSyntaxesData)
args = testSyntaxesData.Args;
h = hTestFillAreaBetweenCurve(args{:});
h.callUpdate();
expectedXData = testSyntaxesData.XData;
expectedY1Data = testSyntaxesData.Y1Data;
expectedY2Data = testSyntaxesData.Y2Data;
expectedFaceColorData = testSyntaxesData.FaceColor;
testCase.verifyEqual(h.XData, expectedXData);
testCase.verifyEqual(h.Y1Data, expectedY1Data);
testCase.verifyEqual(h.Y2Data, expectedY2Data);
testCase.verifyEqual(h.FaceColor, expectedFaceColorData);
end
function testEmptyDataDoesntBreakChart(testCase, testEmptyData)
args = testEmptyData.Args;
h = hTestFillAreaBetweenCurve(args{:});
h.callUpdate();
h.XData = [];
h.Y1Data = [];
h.Y2Data = [];
h.callUpdate();
end
function testFigureOrder(testCase, testFigureOrderData)
args = testFigureOrderData.Args;
h = hTestFillAreaBetweenCurve(args{:});
figObjects = h.getTestAxes().Children;
testCase.verifyEqual(numel(figObjects), 4);
testCase.verifyEqual(class(figObjects(1)), 'matlab.graphics.chart.primitive.Line');
testCase.verifyEqual(class(figObjects(2)), 'matlab.graphics.chart.primitive.Line');
testCase.verifyEqual(class(figObjects(3)), 'matlab.graphics.primitive.Patch');
testCase.verifyEqual(class(figObjects(4)), 'matlab.graphics.primitive.Patch');
end
function testErrors(testCase, testErrorData)
args = testErrorData.Args;
errorIdentifier = testErrorData.id;
errorMsg = testErrorData.errorMsg;
%
% h = hTestFillAreaBetweenCurve(args{:});
testCase.verifyError(@()hTestFillAreaBetweenCurve(args{:}), errorIdentifier, errorMsg);
end
end
end
function testSyntaxesData = createTestSyntaxesData
XData = linspace(0, 4 * pi, 100);
Y1Data = sin(XData);
Y2Data = cos(XData);
faceColor = [0.4 0.2 0.3];
args1 = {XData Y1Data Y2Data};
args2 = {XData Y1Data Y2Data faceColor};
testSyntaxesData = struct( ...
'SetXY1Y2DataSyntax', struct('Args', {args1}, 'XData', {XData}, ...
'Y1Data', Y1Data, 'Y2Data', Y2Data, 'FaceColor', 'g') , ...
'SetXY1Y2ColorDataSyntax', struct('Args', {args2}, 'XData', {XData}, ...
'Y1Data', Y1Data, 'Y2Data', Y2Data, 'FaceColor', faceColor));
end
function testInterpolateData = createTestInterpolateData
XData = linspace(0, 4 * pi, 100);
Y1Data = sin(XData);
Y2Data = cos(XData);
[xi, yi] = polyxpoly(XData, Y1Data, XData, Y2Data);
inter_XData = [XData, xi.'];
inter_Y1Data = [Y1Data, yi.'];
inter_Y2Data = [Y2Data, yi.'];
[inter_XData, idx] = sort(inter_XData);
inter_Y1Data = inter_Y1Data(idx);
inter_Y2Data = inter_Y2Data(idx);
args = {XData Y1Data Y2Data "Interpolate" true};
testInterpolateData = struct( ...
'SetInterpolateTrue', struct('Args', {args}, 'XData', inter_XData, ...
'Y1Data', inter_Y1Data, 'Y2Data', inter_Y2Data));
end
function testErrorData = createTestErrorData
XData = 1:10;
Case1_Y1Data = 1:11;
Case1_Y2Data = 1:10;
Case1_args = {XData Case1_Y1Data Case1_Y2Data};
Case1_Y1Data = 1:10;
Case2_Y2Data = 1:11;
Case2_args = {XData Case1_Y1Data Case2_Y2Data};
testErrorData = struct( ...
'XNotEqualToY1', struct('Args', {Case1_args}, 'id', 'invalid1:InputsAreInvalid', 'errorMsg', 'Length of x is not equal to length of y1'), ...
'XNotEqualToY2', struct('Args', {Case2_args}, 'id', 'invalid2:InputsAreInvalid', 'errorMsg', 'Length of x is not equal to length of y2'));
end
function testFigureOrderData = createTestFigureOrderData
XData = linspace(0, 4 * pi, 100);
Y1Data = sin(XData);
Y2Data = cos(XData);
args = {XData Y1Data Y2Data};
testFigureOrderData = struct( ...
'TestFigureOrder', struct('Args', {args}));
end
function testEmptyData = createTestEmptyData
Empty_XData = [];
Empty_Y1Data = [];
Empty_Y2Data = [];
emptyargs = {Empty_XData Empty_Y1Data Empty_Y2Data};
testEmptyData = struct( ...
'SetXY1Y2Empty', struct('Args', {emptyargs}, 'XData', {Empty_XData}, ...
'Y1Data', {Empty_Y1Data}, 'Y2Data', {Empty_Y2Data}, 'FaceColor', 'g') ...
);
end