Skip to content

Commit

Permalink
GH-37253: [MATLAB] Add test cases which verify that the NumFields, …
Browse files Browse the repository at this point in the history
…`BitWidth`, and `ID` properties can not be modified to `hFixedWidth` test class (#37316)

### Rationale for this change

As @ sgilmore10 pointed out in #37250 (comment), it makes sense to move the tests which verify that the `NumFields`, `BitWidth`, and `ID` properties cannot be set into the `hFixedWidthType` superclass, rather than having these tests implemented in `tTime32Type` and `tTime64Type`, since they are common to all fixed width types.

### What changes are included in this PR?

1. Moved tests which verify that the `BitWidth`, `NumFields`, and `ID` properties cannot be set out of the `tTime32Type` and `tTime64Type` classes and into the superclass `hFixedWidthType`.
2. Fixed typo in `tTime32Type` and `tTime64Type`. Changed variable name `schema` to `type`.

### Are these changes tested?

Yes.

1. Moved tests which verify that the `BitWidth`, `NumFields`, and `ID` properties cannot be set out of the `tTime32Type` and `tTime64Type` classes and into the superclass `hFixedWidthType`.

### Are there any user-facing changes?

No.

This pull request only modifies tests.
* Closes: #37253

Authored-by: Kevin Gurney <kgurney@mathworks.com>
Signed-off-by: Kevin Gurney <kgurney@mathworks.com>
  • Loading branch information
kevingurney committed Aug 22, 2023
1 parent d062c89 commit faa4652
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 51 deletions.
33 changes: 28 additions & 5 deletions matlab/test/arrow/type/hFixedWidthType.m
Original file line number Diff line number Diff line change
Expand Up @@ -26,27 +26,50 @@

methods(Test)
function TestClass(testCase)
% Verify ArrowType is an object of the expected class type.
% Verify ArrowType is an object of the expected class type.
name = string(class(testCase.ArrowType));
testCase.verifyEqual(name, testCase.ClassName);
end

function TestTypeID(testCase)
% Verify ID is set to the appropriate arrow.type.ID value.
% Verify ID is set to the appropriate arrow.type.ID value.
arrowType = testCase.ArrowType;
testCase.verifyEqual(arrowType.ID, testCase.TypeID);
end

function TestBitWidth(testCase)
% Verify the BitWidth value.
% Verify the BitWidth value.
arrowType = testCase.ArrowType;
testCase.verifyEqual(arrowType.BitWidth, testCase.BitWidth);
end

function TestNumFields(testCase)
% Verify NumFields is set to 0 for primitive types.
% Verify NumFields is set to 0 for primitive types.
arrowType = testCase.ArrowType;
testCase.verifyEqual(arrowType.NumFields, int32(0));
end

function TestBitWidthNoSetter(testCase)
% Verify that an error is thrown when trying to set the value
% of the BitWidth property.
arrowType = testCase.ArrowType;
testCase.verifyError(@() setfield(arrowType, "BitWidth", 64), "MATLAB:class:SetProhibited");
end

function TestIDNoSetter(testCase)
% Verify that an error is thrown when trying to set the value
% of the ID property.
arrowType = testCase.ArrowType;
testCase.verifyError(@() setfield(arrowType, "ID", 15), "MATLAB:class:SetProhibited");
end

function TestNumFieldsNoSetter(testCase)
% Verify that an error is thrown when trying to set the value
% of the NumFields property.
arrowType = testCase.ArrowType;
testCase.verifyError(@() setfield(arrowType, "NumFields", 2), "MATLAB:class:SetProhibited");
end

end
end

end
25 changes: 2 additions & 23 deletions matlab/test/arrow/type/tTime32Type.m
Original file line number Diff line number Diff line change
Expand Up @@ -107,29 +107,8 @@ function Display(testCase)
function TimeUnitNoSetter(testCase)
% Verify that an error is thrown when trying to set the value
% of the TimeUnit property.
schema = arrow.time32(TimeUnit="Millisecond");
testCase.verifyError(@() setfield(schema, "TimeUnit", "Second"), "MATLAB:class:SetProhibited");
end

function BitWidthNoSetter(testCase)
% Verify that an error is thrown when trying to set the value
% of the BitWidth property.
schema = arrow.time32(TimeUnit="Millisecond");
testCase.verifyError(@() setfield(schema, "BitWidth", 64), "MATLAB:class:SetProhibited");
end

function IDNoSetter(testCase)
% Verify that an error is thrown when trying to set the value
% of the ID property.
schema = arrow.time32(TimeUnit="Millisecond");
testCase.verifyError(@() setfield(schema, "ID", 15), "MATLAB:class:SetProhibited");
end

function NumFieldsNoSetter(testCase)
% Verify that an error is thrown when trying to set the value
% of the NumFields property.
schema = arrow.time32(TimeUnit="Millisecond");
testCase.verifyError(@() setfield(schema, "NumFields", 2), "MATLAB:class:SetProhibited");
type = arrow.time32(TimeUnit="Millisecond");
testCase.verifyError(@() setfield(type, "TimeUnit", "Second"), "MATLAB:class:SetProhibited");
end

function InvalidProxy(testCase)
Expand Down
25 changes: 2 additions & 23 deletions matlab/test/arrow/type/tTime64Type.m
Original file line number Diff line number Diff line change
Expand Up @@ -108,29 +108,8 @@ function Display(testCase)
function TimeUnitNoSetter(testCase)
% Verify that an error is thrown when trying to set the value
% of the TimeUnit property.
schema = arrow.time64(TimeUnit="Nanosecond");
testCase.verifyError(@() setfield(schema, "TimeUnit", "Microsecond"), "MATLAB:class:SetProhibited");
end

function BitWidthNoSetter(testCase)
% Verify that an error is thrown when trying to set the value
% of the BitWidth property.
schema = arrow.time64(TimeUnit="Nanosecond");
testCase.verifyError(@() setfield(schema, "BitWidth", 32), "MATLAB:class:SetProhibited");
end

function IDNoSetter(testCase)
% Verify that an error is thrown when trying to set the value
% of the ID property.
schema = arrow.time64(TimeUnit="Nanosecond");
testCase.verifyError(@() setfield(schema, "ID", 15), "MATLAB:class:SetProhibited");
end

function NumFieldsNoSetter(testCase)
% Verify that an error is thrown when trying to set the value
% of the NumFields property.
schema = arrow.time64(TimeUnit="Nanosecond");
testCase.verifyError(@() setfield(schema, "NumFields", 2), "MATLAB:class:SetProhibited");
type = arrow.time64(TimeUnit="Nanosecond");
testCase.verifyError(@() setfield(type, "TimeUnit", "Microsecond"), "MATLAB:class:SetProhibited");
end

function InvalidProxy(testCase)
Expand Down

0 comments on commit faa4652

Please sign in to comment.