Build out MATLAB test framework and core integration coverage
This commit is contained in:
@@ -1,11 +1,49 @@
|
||||
classdef Photodiode_test < matlab.unittest.TestCase
|
||||
% Test class for Photodiode
|
||||
classdef Photodiode_test < IMDDTestCase
|
||||
methods (Test, TestTags = {'unit', 'fast', 'receive', 'photodiode'})
|
||||
function processZeroNoiseBaselineMatchesAnalyticalExpectation(testCase)
|
||||
pd = Photodiode("fsimu", 0, "responsivity", 2.5, "dark_current", 0.75, "nep", 0, "randomkey", 1);
|
||||
xin = [1 + 1i, 2 - 1i; 0.5, 0.25i];
|
||||
|
||||
methods (Test)
|
||||
function testExample(testCase)
|
||||
% Example test case for Photodiode
|
||||
% Add your test code here
|
||||
testCase.verifyTrue(true);
|
||||
yout = pd.process_(xin);
|
||||
expected = 2.5 * sum(abs(xin).^2, 2) + 0.75;
|
||||
|
||||
testCase.verifyEqual(yout, expected, "AbsTol", 1e-12);
|
||||
end
|
||||
|
||||
function responsivityScalesDetectedPowerLinearly(testCase)
|
||||
xin = [1 + 2i, 0.5 - 0.5i; 0.25, 1i];
|
||||
|
||||
pd1 = Photodiode("fsimu", 0, "responsivity", 1, "dark_current", 0, "nep", 0, "randomkey", 1);
|
||||
pd2 = Photodiode("fsimu", 0, "responsivity", 3.5, "dark_current", 0, "nep", 0, "randomkey", 1);
|
||||
|
||||
y1 = pd1.process_(xin);
|
||||
y2 = pd2.process_(xin);
|
||||
|
||||
testCase.verifyEqual(y2, 3.5 * y1, "AbsTol", 1e-12);
|
||||
end
|
||||
|
||||
function darkCurrentAddsConstantOffset(testCase)
|
||||
xin = [1; 0; 2];
|
||||
|
||||
pdNoDc = Photodiode("fsimu", 0, "responsivity", 1.2, "dark_current", 0, "nep", 0, "randomkey", 1);
|
||||
pdWithDc = Photodiode("fsimu", 0, "responsivity", 1.2, "dark_current", 0.42, "nep", 0, "randomkey", 1);
|
||||
|
||||
yNoDc = pdNoDc.process_(xin);
|
||||
yWithDc = pdWithDc.process_(xin);
|
||||
|
||||
testCase.verifyEqual(yWithDc - yNoDc, 0.42 * ones(size(xin, 1), 1), "AbsTol", 1e-12);
|
||||
end
|
||||
|
||||
function identicalSeedsProduceIdenticalStochasticOutputs(testCase)
|
||||
xin = [1 + 1i; 0.5; 2];
|
||||
|
||||
pd1 = Photodiode("fsimu", 1, "responsivity", 0, "dark_current", 0, "nep", 1e-12, "randomkey", 7);
|
||||
pd2 = Photodiode("fsimu", 1, "responsivity", 0, "dark_current", 0, "nep", 1e-12, "randomkey", 7);
|
||||
|
||||
y1 = pd1.process_(xin);
|
||||
y2 = pd2.process_(xin);
|
||||
|
||||
testCase.verifyEqual(y1, y2);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,11 +1,49 @@
|
||||
classdef Scope_test < matlab.unittest.TestCase
|
||||
% Test class for Scope
|
||||
classdef Scope_test < IMDDTestCase
|
||||
methods (Test, TestTags = {'unit', 'fast', 'receive', 'scope'})
|
||||
function quantizeMapsRealSignalToExpectedGrid(testCase)
|
||||
scope = makeScope(10, 10, 2, 0, true);
|
||||
xin = (0:9).';
|
||||
|
||||
methods (Test)
|
||||
function testExample(testCase)
|
||||
% Example test case for Scope
|
||||
% Add your test code here
|
||||
testCase.verifyTrue(true);
|
||||
quantized = scope.quantize(xin);
|
||||
|
||||
expected = [0; 0; 8/3; 8/3; 16/3; 16/3; 16/3; 8; 8; 8];
|
||||
testCase.verifyEqual(quantized, expected, "AbsTol", 1e-12);
|
||||
end
|
||||
|
||||
function process_ResamplesQuantizesAndSubtractsDc(testCase)
|
||||
scope = makeScope(40, 20, 3, 0, true);
|
||||
xin = (1:40).';
|
||||
|
||||
yout = scope.process_(xin);
|
||||
|
||||
expected = scope.quantize(resample(xin, scope.fadc, scope.fsimu));
|
||||
expected = expected - mean(expected, 1);
|
||||
|
||||
testCase.verifyEqual(length(yout), 20);
|
||||
testCase.verifyEqual(yout, expected, "AbsTol", 1e-12);
|
||||
testCase.verifyEqual(mean(yout), 0, "AbsTol", 1e-12);
|
||||
end
|
||||
|
||||
function processWithoutDcBlockingPreservesQuantizedMean(testCase)
|
||||
scope = makeScope(40, 20, 3, 0, false);
|
||||
xin = (1:40).';
|
||||
|
||||
yout = scope.process_(xin);
|
||||
|
||||
expected = scope.quantize(resample(xin, scope.fadc, scope.fsimu));
|
||||
|
||||
testCase.verifyEqual(yout, expected, "AbsTol", 1e-12);
|
||||
testCase.verifyGreaterThan(abs(mean(yout)), 1e-12);
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function scope = makeScope(fsimu, fadc, adcresolution, quantbuffer, block_dc)
|
||||
scope = Scope( ...
|
||||
"fsimu", fsimu, ...
|
||||
"fadc", fadc, ...
|
||||
"adcresolution", adcresolution, ...
|
||||
"quantbuffer", quantbuffer, ...
|
||||
"block_dc", block_dc, ...
|
||||
"H_lpf", struct('fs', fadc));
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user