-
Notifications
You must be signed in to change notification settings - Fork 165
Expand file tree
/
Copy pathPlotlyTestCaseAnyInteger.m
More file actions
68 lines (58 loc) · 2.24 KB
/
PlotlyTestCaseAnyInteger.m
File metadata and controls
68 lines (58 loc) · 2.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
classdef PlotlyTestCaseAnyInteger < PlotlyTestCaseAny
% PlotlyTestCaseAnyInteger Matcher for integer values
%
% This class validates that a value is an integer (whole number).
% Optionally can enforce positive integers only.
%
% Do not instantiate this class directly. Use PlotlyTestCase.AnyInteger() instead.
%
% Example:
% expected.width = PlotlyTestCase.AnyInteger();
% testCase.verifyEqualStructs(actual, expected);
properties
PositiveOnly = false % If true, only accept positive integers
end
methods
function obj = PlotlyTestCaseAnyInteger(positiveOnly)
% Constructor
%
% Syntax:
% obj = PlotlyTestCaseAnyInteger()
% obj = PlotlyTestCaseAnyInteger(positiveOnly)
%
% Input:
% positiveOnly - (Optional) If true, only accept positive integers
if nargin > 0
obj.PositiveOnly = positiveOnly;
end
end
function result = match(obj, actualValue)
% match Check if value is a valid integer
%
% Validates that actualValue is a numeric integer value.
% If PositiveOnly is true, also checks that value > 0.
result = struct('passed', false, 'diagnostic', '');
% Check if it's numeric
if ~isnumeric(actualValue)
result.diagnostic = sprintf('Expected integer, got %s', class(actualValue));
return;
end
% Check if it's scalar
if ~isscalar(actualValue)
result.diagnostic = sprintf('Expected scalar integer, got %s array', mat2str(size(actualValue)));
return;
end
% Check if it's a whole number
if actualValue ~= floor(actualValue)
result.diagnostic = sprintf('Expected integer, got %g', actualValue);
return;
end
% Check if positive (if required)
if obj.PositiveOnly && actualValue <= 0
result.diagnostic = sprintf('Expected positive integer, got %d', actualValue);
return;
end
result.passed = true;
end
end
end