Skip to content

Commit

Permalink
Raises errors if attempt to use function or data backgrounds (#252)
Browse files Browse the repository at this point in the history
* Added errors if attempt to use function or data backgrounds

* added newline at end of file

* fixed tests

* fixed not implemented error

* fixed some tests unnecessarily commented out
  • Loading branch information
alexhroom authored Aug 6, 2024
1 parent 03f4b69 commit 1434829
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 12 deletions.
2 changes: 2 additions & 0 deletions API/projectClass/backgroundsClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
thisRow{3} = thisParam;

case allowedTypes.Function.value
throw(exceptions.notImplemented('Function backgrounds are not yet supported.'))
% Param 3 is assumed to be function name
% any other given parameters must be in paramNames
% list or numbers in range
Expand All @@ -112,6 +113,7 @@
thisRow{i} = thisParam;
end
case allowedTypes.Data.value
throw(exceptions.notImplemented('Data backgrounds are not yet supported.'))
% Background is assumed to be given by a 4th column
% of a data file. We don't have access to the
% data files at this point so this (i.e. that data is
Expand Down
28 changes: 16 additions & 12 deletions tests/testBackgroundsClass.m
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ function createBackgrounds(testCase)
testCase.backgrounds = {
'background 1', allowedTypes.Constant.value, 'background param 1', '', '', '', '';
'background 2', allowedTypes.Constant.value, 'background param 2', '', '', '', '';
'background 3', allowedTypes.Function.value, 'function_name', 'background param 1', 'background param 2', '', '';
'background 4', allowedTypes.Data.value, '', '', '', '', '';
'background 3', allowedTypes.Constant.value, 'background param 3', '', '', '', '';
'background 4', allowedTypes.Constant.value, 'background param 3', '', '', '', '';
% once data and function backgrounds are implemented, replace 3 and 4 with these
%'background 3', allowedTypes.Function.value, 'function_name', 'background param 1', 'background param 2', '', '';
%'background 4', allowedTypes.Data.value, '', '', '', '', '';
};
end
end
Expand Down Expand Up @@ -88,10 +91,10 @@ function testAddBackground(testCase)
testCase.background.addBackground(testCase.backgrounds{4, :});
testCase.verifyEqual(string(testCase.background.backgrounds.varTable{end, :}),...
string(testCase.backgrounds(4, :)), 'addBackground method not working');
testCase.background.addBackground('background 5', allowedTypes.Function, 'function_name', 1, 3);
testCase.verifyEqual(string(testCase.background.backgrounds.varTable{end, :}),...
["background 5", string(allowedTypes.Function.value), "function_name", "background param 1", "background param 3", "", ""], ...
'addBackground method not working');
%testCase.background.addBackground('background 5', allowedTypes.Function, 'function_name', 1, 3);
%testCase.verifyEqual(string(testCase.background.backgrounds.varTable{end, :}),...
% ["background 5", string(allowedTypes.Function.value), "function_name", "background param 1", "background param 3", "", ""], ...
% 'addBackground method not working');
testCase.verifyError(@() testCase.background.addBackground('New', 'fixed'), exceptions.invalidOption.errorID);
testCase.verifyError(@() testCase.background.addBackground('New', allowedTypes.Constant), exceptions.invalidNumberOfInputs.errorID);
testCase.verifyError(@() testCase.background.addBackground('New', allowedTypes.Constant.value, 6), exceptions.indexOutOfRange.errorID);
Expand Down Expand Up @@ -132,12 +135,12 @@ function testSetBackground(testCase)

testCase.background.setBackground(1, 'type', allowedTypes.Constant.value);
testCase.verifyEqual(testCase.background.backgrounds.varTable{1, 2}, string(allowedTypes.Constant.value), 'setBackground method not working');
testCase.background.setBackground('Background 1', 'type', allowedTypes.Function);
testCase.verifyEqual(testCase.background.backgrounds.varTable{1, 2}, string(allowedTypes.Function.value), 'setBackground method not working');
%testCase.background.setBackground('Background 1', 'type', allowedTypes.Function);
%testCase.verifyEqual(testCase.background.backgrounds.varTable{1, 2}, string(allowedTypes.Function.value), 'setBackground method not working');
testCase.verifyError(@() testCase.background.setBackground(2, 'type', 'random'), exceptions.invalidOption.errorID);

testCase.background.setBackground(3, 'Value1', 'random');
testCase.verifyEqual(testCase.background.backgrounds.varTable{3, 3}, "random", 'setBackground method not working');
%testCase.background.setBackground(3, 'Value1', 'random');
%testCase.verifyEqual(testCase.background.backgrounds.varTable{3, 3}, "random", 'setBackground method not working');
testCase.background.setBackground('Background 3', 'Value1', 'Background param 1');
testCase.verifyEqual(testCase.background.backgrounds.varTable{3, 3}, "Background param 1", 'setBackground method not working');

Expand Down Expand Up @@ -228,9 +231,10 @@ function testToStruct(testCase)
{'background param 3', priorTypes.Uniform.value, 0, Inf}};
expected.backgroundNames = ["background 1"; "background 2"; "background 3"];
expected.backgroundTypes = [string(allowedTypes.Constant.value); string(allowedTypes.Constant.value);
string(allowedTypes.Function.value)];
string(allowedTypes.Constant.value)]; % FIXME: change to function when function backgrounds added
expected.backgroundValues = {"background param 1", "", "", "", ""; "background param 2", "", "", "", "";...
"function_name", "background param 1", "background param 2", "", ""};
"background param 3", "", "", "", ""};
% "function_name", "background param 1", "background param 2", "", ""}; FIXME - replace prev line with this when function backs added
testCase.verifyEqual(testCase.background.toStruct(), expected, 'toStruct method not working');
end
end
Expand Down
13 changes: 13 additions & 0 deletions utilities/+exceptions/notImplemented.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
classdef notImplemented < MException
properties (Constant, Hidden)
errorID = 'RAT:notImplemented';
end
methods
function obj = notImplemented(message)
arguments
message {mustBeTextScalar} = 'This functionality is not yet supported'
end
obj = obj@MException(exceptions.notImplemented.errorID, message);
end
end
end

0 comments on commit 1434829

Please sign in to comment.