Skip to content

Commit b4f953f

Browse files
HanSur94claude
andcommitted
test: cover shaded-region patch length-parity fix (codecov patch coverage)
Add two regression tests to TestAddShaded exercising all three code paths the shading fix changed: - testShadedPatchEqualLengthCacheBranch: n>20000 hits render()'s cache branch, then a zoom exercises updateShadings(). - testShadedPatchEqualLengthMidBranch: 5000<n<=20000 hits render()'s mid-size branch. A monotonic upper curve + constant fill baseline deterministically makes the two boundaries downsample to different lengths (minmax tail-anchor), so each test would have thrown "Vectors must be the same length." on the pre-fix code and now asserts equal-length patch XData/YData. Covers the 15 lines flagged by codecov/patch. Lives in TestAddShaded (A-D shard) to stay clear of the flaky TestTagPerfRegression perf gate in the Q-Z shard. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 20516d3 commit b4f953f

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

tests/suite/TestAddShaded.m

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,55 @@ function testAddFillRendered(testCase)
101101
ud = get(fp.Shadings(1).hPatch, 'UserData');
102102
testCase.verifyEqual(ud.FastSense.Type, 'shaded', 'testAddFillRendered: type is shaded');
103103
end
104+
105+
function testShadedPatchEqualLengthCacheBranch(testCase)
106+
% Regression (260512-c5x): with > 2*shadingCacheSize (20000) points
107+
% and a constant fill baseline, the upper (varying) and lower
108+
% (constant) boundaries downsample to DIFFERENT lengths via the
109+
% minmax tail-anchor. render()'s cache branch must still emit an
110+
% equal-length patch polygon — previously patch() threw "Vectors
111+
% must be the same length." (e.g. example_dock's Power Systems
112+
% tile). The subsequent zoom exercises the same fix in
113+
% updateShadings(). A monotonic upper curve guarantees divergence:
114+
% its last sample IS its last bucket extreme (no tail-anchor) while
115+
% the constant baseline DOES anchor.
116+
n = 25000;
117+
x = linspace(0, 100, n);
118+
y = linspace(0, 10, n);
119+
fp = FastSense();
120+
fp.addLine(x, y, 'DisplayName', 'ramp');
121+
fp.addFill(x, y, 'Baseline', 0, 'FaceColor', [0 0.5 1]);
122+
fp.render();
123+
testCase.addTeardown(@close, fp.hFigure);
124+
125+
hP = fp.Shadings(1).hPatch;
126+
testCase.verifyEqual(numel(get(hP, 'XData')), numel(get(hP, 'YData')), ...
127+
'cache branch: shading patch XData/YData length mismatch after render');
128+
129+
% Zoom to a sub-range that stays above MinPointsForDownsample so
130+
% updateShadings re-downsamples (the live zoom/pan path).
131+
set(fp.hAxes, 'XLim', [20 60]);
132+
drawnow; pause(0.2);
133+
testCase.verifyEqual(numel(get(hP, 'XData')), numel(get(hP, 'YData')), ...
134+
'updateShadings: shading patch XData/YData length mismatch after zoom');
135+
end
136+
137+
function testShadedPatchEqualLengthMidBranch(testCase)
138+
% MinPointsForDownsample (5000) < n <= 2*shadingCacheSize (20000)
139+
% exercises render()'s mid-size (elseif) downsample branch with the
140+
% same varying-vs-constant boundary divergence.
141+
n = 10000;
142+
x = linspace(0, 100, n);
143+
y = linspace(0, 5, n);
144+
fp = FastSense();
145+
fp.addLine(x, y);
146+
fp.addFill(x, y, 'Baseline', 0);
147+
fp.render();
148+
testCase.addTeardown(@close, fp.hFigure);
149+
150+
hP = fp.Shadings(1).hPatch;
151+
testCase.verifyEqual(numel(get(hP, 'XData')), numel(get(hP, 'YData')), ...
152+
'mid branch: shading patch XData/YData length mismatch after render');
153+
end
104154
end
105155
end

0 commit comments

Comments
 (0)