83 lines
3.3 KiB
Matlab
83 lines
3.3 KiB
Matlab
classdef Informationsignal_test < IMDDTestCase
|
|
methods (Test, TestTags = {'unit', 'fast', 'signals', 'informationsignal'})
|
|
function constructorWithoutOptionsUsesSignalDefaults(testCase)
|
|
info = Informationsignal([0; 1; 1; 0]);
|
|
|
|
testCase.verifyClass(info, 'Informationsignal');
|
|
testCase.verifyEqual(info.signal, [0; 1; 1; 0]);
|
|
testCase.verifyEmpty(info.fs);
|
|
testCase.verifyEmpty(info.logbook);
|
|
end
|
|
|
|
function constructorWithOptionsCopiesFsAndLogbook(testCase)
|
|
seed = Signal(5, "fs", 2);
|
|
seed = seed.logbookentry("seed entry", seed);
|
|
|
|
info = Informationsignal([1; 0; 1], "fs", 32e9, "logbook", seed.logbook);
|
|
|
|
testCase.verifyEqual(info.signal, [1; 0; 1]);
|
|
testCase.verifyEqual(info.fs, 32e9);
|
|
testCase.verifyEqual(info.logbook, seed.logbook);
|
|
end
|
|
|
|
function inheritedArithmeticKeepsInformationsignalTypeAndMetadata(testCase)
|
|
lhs = Informationsignal([1; 2; 3], "fs", 64e9, "logbook", table());
|
|
rhs = Informationsignal([4; 5; 6], "fs", 1, "logbook", table());
|
|
|
|
sumSig = lhs + rhs;
|
|
|
|
testCase.verifyClass(sumSig, 'Informationsignal');
|
|
testCase.verifyEqual(sumSig.signal, [5; 7; 9]);
|
|
testCase.verifyEqual(sumSig.fs, lhs.fs);
|
|
testCase.verifyEqual(sumSig.logbook, lhs.logbook);
|
|
end
|
|
|
|
function electricalsignalCastUsesRequestedFsAndLogbook(testCase)
|
|
seed = Signal(1, "fs", 4);
|
|
seed = seed.logbookentry("cast logbook", seed);
|
|
info = Informationsignal([0; 1; 0; 1]);
|
|
|
|
elec = info.Electricalsignal("fs", 128e9, "logbook", seed.logbook);
|
|
|
|
testCase.verifyClass(elec, 'Electricalsignal');
|
|
testCase.verifyEqual(elec.signal, info.signal);
|
|
testCase.verifyEqual(elec.fs, 128e9);
|
|
testCase.verifyEqual(elec.logbook, seed.logbook);
|
|
end
|
|
|
|
function opticalsignalCastFailsForInformationsignal(testCase)
|
|
info = Informationsignal([0; 1; 0; 1]);
|
|
|
|
didError = false;
|
|
try
|
|
info.Opticalsignal( ...
|
|
"fs", 64e9, ...
|
|
"logbook", info.logbook, ...
|
|
"lambda", 1310e-9, ...
|
|
"nase", 0, ...
|
|
"polrot", 0);
|
|
catch ME
|
|
didError = true;
|
|
testCase.verifySubstring(ME.message, ...
|
|
"Cannot convert from information- to opticalsignal.");
|
|
end
|
|
|
|
testCase.verifyTrue(didError, ...
|
|
"Informationsignal -> Opticalsignal should reject direct conversion.");
|
|
end
|
|
|
|
function electricalToInformationCastPreservesSignalAndMetadata(testCase)
|
|
seed = Signal(2, "fs", 8);
|
|
seed = seed.logbookentry("from electrical", seed);
|
|
elec = Electricalsignal([3; 1; 4], "fs", 96e9, "logbook", seed.logbook);
|
|
|
|
info = elec.Informationsignal("fs", elec.fs, "logbook", elec.logbook);
|
|
|
|
testCase.verifyClass(info, 'Informationsignal');
|
|
testCase.verifyEqual(info.signal, elec.signal);
|
|
testCase.verifyEqual(info.fs, elec.fs);
|
|
testCase.verifyEqual(info.logbook, elec.logbook);
|
|
end
|
|
end
|
|
end
|