From b8bfd78f9acb33adad36fdf9ad2d5d91e6038d2d Mon Sep 17 00:00:00 2001 From: Christopher Creutzig Date: Tue, 10 Dec 2024 13:52:29 +0100 Subject: [PATCH] improve coverage for errorMessageCatalog --- +llms/+utils/errorMessageCatalog.m | 9 +++++++++ tests/terrorMessageCatalog.m | 27 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 tests/terrorMessageCatalog.m diff --git a/+llms/+utils/errorMessageCatalog.m b/+llms/+utils/errorMessageCatalog.m index 9a2ed54..967254e 100644 --- a/+llms/+utils/errorMessageCatalog.m +++ b/+llms/+utils/errorMessageCatalog.m @@ -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 diff --git a/tests/terrorMessageCatalog.m b/tests/terrorMessageCatalog.m new file mode 100644 index 0000000..7c63baa --- /dev/null +++ b/tests/terrorMessageCatalog.m @@ -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