Skip to content

Commit

Permalink
improve coverage for errorMessageCatalog
Browse files Browse the repository at this point in the history
  • Loading branch information
ccreutzi committed Dec 13, 2024
1 parent 44a3679 commit b8bfd78
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
9 changes: 9 additions & 0 deletions +llms/+utils/errorMessageCatalog.m
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
end
end
end

function s = createCatalog()
%createCatalog will run the initialization code and return the catalog
% This is only meant to get more correct test coverage reports:
% The test coverage reports do not include the properties initialization
% for Catalog from above, so we have a test seam here to re-run it
% within the framework, where it is reported.
s = buildErrorMessageCatalog;
end
end
end

Expand Down
27 changes: 27 additions & 0 deletions tests/terrorMessageCatalog.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
classdef terrorMessageCatalog < matlab.unittest.TestCase
% Tests for errorMessageCatalog

% Copyright 2024 The MathWorks, Inc.

methods(Test)
function ensureCorrectCoverage(testCase)
testCase.verifyClass( ...
llms.utils.errorMessageCatalog.createCatalog,"dictionary");
end

function holeValuesAreUsed(testCase)
import matlab.unittest.constraints.IsEqualTo

% we do not check the whole string, because error message
% text *should* be able to change without test points changing.
% That is necessary to enable localization.
messageID = "llms:mustBeValidIndex";

message1 = llms.utils.errorMessageCatalog.getMessage(messageID, "input1");
message2 = llms.utils.errorMessageCatalog.getMessage(messageID, "input2");

testCase.verifyThat(message1, ~IsEqualTo(message2));
testCase.verifyThat(replace(message1, "input1", "input2"), IsEqualTo(message2));
end
end
end

0 comments on commit b8bfd78

Please sign in to comment.