Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions API/projectClass/contrastsClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,25 @@

inputArray = cellstr(input);

% Check the input is as expected - modelNames tells us what the
% model type is
if all(size(allowedNames.modelNames) == size(allowedNames.customFileNames)) && all(cellfun(@strcmp, allowedNames.modelNames, allowedNames.customFileNames))
% Check the input is as expected - layerNames is only present in standard layers
if ~isfield(allowedNames, 'layerNames')
if isempty(allowedNames.customFileNames)
throw(exceptions.invalidValue('At least one custom file must be added to the contrast model in a standard layers project. Did you forget to add the custom file?'));
end

if length(inputArray) > 1
throw(exceptions.invalidValue('Only one model value is allowed for custom models'));
throw(exceptions.invalidValue('One custom file is required as the contrast model in a custom layers or xy project'));
end
else
if isempty(allowedNames.layerNames) && ~isempty(allowedNames.customFileNames) && any(cellfun(@(x) any(strcmp(x, allowedNames.customFileNames)), inputArray))
throw(exceptions.invalidValue('Custom files cannot be used in a standard layers model. Did you forget to change the model type?'));
end

if isempty(allowedNames.layerNames)
throw(exceptions.invalidValue('At least one layer must be added to the contrast model in a standard layers project. Did you forget to add the layers?'));
end
elseif obj.domainsCalc && all(size(allowedNames.modelNames) == size(allowedNames.domainContrastNames)) && all(cellfun(@strcmp, allowedNames.modelNames, allowedNames.domainContrastNames))
if length(inputArray) ~= 2
if obj.domainsCalc && length(inputArray) ~= 2
throw(exceptions.invalidValue('Exactly two model values are required for ''standard layers'' with domains'));
end
end
Expand All @@ -260,7 +271,7 @@
for i = 1:modelSize
found = strcmpi(inputArray{i}, modelNames);
if ~any(found)
throw(exceptions.nameNotRecognised(sprintf('Model component name "%s" is not recognised. The allowed names are: "%s".', inputArray{i}, strjoin(allowedNames.modelNames, '", "'))));
throw(exceptions.nameNotRecognised(sprintf('Model component name "%s" is not recognised. The allowed names are: "%s".', inputArray{i}, strjoin(modelNames, '", "'))));
end
model{i} = modelNames{find(found, 1)};
end
Expand Down
9 changes: 9 additions & 0 deletions tests/testContrastsClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,18 @@ function testSetContrastModelStandardLayers(testCase)

noDomainsClass.setContrastModel(1, testCase.allowedNames, testModel);
testCase.verifyEqual(noDomainsClass.contrasts{1}.model, testModel, 'setContrastModel does not work correctly');

testCase.allowedNames.layerNames = {};
testCase.verifyError(@() testCase.exampleClass.setContrastModel(1, testCase.allowedNames, {'Oxide Layer'}), exceptions.invalidValue.errorID);
testCase.verifyError(@() testCase.exampleClass.setContrastModel(1, testCase.allowedNames, {'DPPC Model'}), exceptions.invalidValue.errorID);

end

function testSetContrastModelCustomLayers(testCase)
% Test setting a model for a contrast from the contrasts class
% for a "custom XY" model type
noDomainsClass = contrastsClass();
testCase.allowedNames = rmfield(testCase.allowedNames, 'layerNames');
noDomainsClass.addContrast(testCase.allowedNames);

testModel = {'DPPC Model'};
Expand All @@ -350,6 +356,9 @@ function testSetContrastModelCustomLayers(testCase)

% only one model value is allowed
testCase.verifyError(@() testCase.exampleClass.setContrastModel(1, testCase.allowedNames, {'DPPC Model', 'DSPC Model'}), exceptions.invalidValue.errorID);

testCase.allowedNames.customFileNames = {};
testCase.verifyError(@() testCase.exampleClass.setContrastModel(1, testCase.allowedNames, {'DPPC Model'}), exceptions.invalidValue.errorID);
end

function testSetContrastModelInvalid(testCase)
Expand Down