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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
|
% Licensed to the Apache Software Foundation (ASF) under one or more
% contributor license agreements. See the NOTICE file distributed with
% this work for additional information regarding copyright ownership.
% The ASF licenses this file to you under the Apache License, Version
% 2.0 (the "License"); you may not use this file except in compliance
% with the License. You may obtain a copy of the License at
%
% http://www.apache.org/licenses/LICENSE-2.0
%
% Unless required by applicable law or agreed to in writing, software
% distributed under the License is distributed on an "AS IS" BASIS,
% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
% implied. See the License for the specific language governing
% permissions and limitations under the License.
classdef tTime32Type < hFixedWidthType
% Test class for arrow.type.Time32Type and arrow.time32
properties
ConstructionFcn = @arrow.time32
ArrowType = arrow.time32
TypeID = arrow.type.ID.Time32
BitWidth = int32(32)
ClassName = "arrow.type.Time32Type"
end
methods(Test)
function TestClass(testCase)
% Verify ArrowType is an object of the expected class type.
name = string(class(testCase.ArrowType));
testCase.verifyEqual(name, testCase.ClassName);
end
function DefaultTimeUnit(testCase)
% Verify the default TimeUnit is Second.
type = testCase.ArrowType;
actualUnit = type.TimeUnit;
expectedUnit = arrow.type.TimeUnit.Second;
testCase.verifyEqual(actualUnit, expectedUnit);
end
function SupplyTimeUnitEnum(testCase)
% Verify that TimeUnit can be specified as an enum value.
import arrow.type.*
expectedUnit = [TimeUnit.Second, TimeUnit.Millisecond];
for unit = expectedUnit
type = testCase.ConstructionFcn(TimeUnit=unit);
testCase.verifyEqual(type.TimeUnit, unit);
end
end
function SupplyTimeUnitString(testCase)
% Supply TimeUnit as a string value. Verify TimeUnit is set to
% the appropriate TimeUnit enum value.
import arrow.type.*
unitString = ["second", "millisecond"];
expectedUnit = [TimeUnit.Second, TimeUnit.Millisecond];
for ii = 1:numel(unitString)
type = testCase.ConstructionFcn(TimeUnit=unitString(ii));
testCase.verifyEqual(type.TimeUnit, expectedUnit(ii));
end
end
function ErrorIfAmbiguousTimeUnit(testCase)
% Verify that an error is thrown if an ambiguous value is
% provided for the TimeUnit name-value pair.
fcn = @() testCase.ConstructionFcn(TimeUnit="mi");
testCase.verifyError(fcn, "MATLAB:validation:UnableToConvert");
end
function ErrorIfTimeUnitIsNonScalar(testCase)
% Verify that an error is thrown if a nonscalar value is
% provided for the TimeUnit name-value pair.
units = [arrow.type.TimeUnit.Second; arrow.type.TimeUnit.Millisecond];
fcn = @() testCase.ConstructionFcn(TimeUnit=units);
testCase.verifyError(fcn, "MATLAB:validation:IncompatibleSize");
units = ["second" "millisecond"];
fcn = @() testCase.ConstructionFcn(TimeUnit=units);
testCase.verifyError(fcn, "MATLAB:validation:IncompatibleSize");
end
function TimeUnitNoSetter(testCase)
% Verify that an error is thrown when trying to set the value
% of the TimeUnit property.
type = arrow.time32(TimeUnit="Millisecond");
testCase.verifyError(@() setfield(type, "TimeUnit", "Second"), "MATLAB:class:SetProhibited");
end
function InvalidProxy(testCase)
% Verify that an error is thrown when a Proxy of an unexpected
% type is passed to the arrow.type.Time32Type constructor.
array = arrow.array([1, 2, 3]);
proxy = array.Proxy;
testCase.verifyError(@() arrow.type.Time32Type(proxy), "arrow:proxy:ProxyNameMismatch");
end
function IsEqualTrue(testCase)
% Verifies isequal method of arrow.type.Time32Type returns true if
% these conditions are met:
%
% 1. All input arguments have a class type arrow.type.Time32Type
% 2. All inputs have the same size
% 3. The TimeUnit values of elements at corresponding positions in the arrays are equal
% Scalar Time32Type arrays
time32Type1 = arrow.time32(TimeUnit="Second");
time32Type2 = arrow.time32(TimeUnit="Second");
time32Type3 = arrow.time32(TimeUnit="Millisecond");
time32Type4 = arrow.time32(TimeUnit="Millisecond");
testCase.verifyTrue(isequal(time32Type1, time32Type2));
testCase.verifyTrue(isequal(time32Type3, time32Type4));
% Non-scalar Time32Type arrays
typeArray1 = [time32Type1 time32Type3];
typeArray2 = [time32Type2 time32Type4];
testCase.verifyTrue(isequal(typeArray1, typeArray2));
end
function IsEqualFalse(testCase)
% Verify isequal returns false when expected.
time32Type1 = arrow.time32(TimeUnit="Second");
time32Type2 = arrow.time32(TimeUnit="Millisecond");
int32Type = arrow.int32();
testCase.verifyFalse(isequal(time32Type1, time32Type2));
testCase.verifyFalse(isequal(time32Type1, int32Type));
% Arrays have different dimensions
typeArray1 = [time32Type1 time32Type2];
typeArray2 = [time32Type1 time32Type2]';
testCase.verifyFalse(isequal(typeArray1, typeArray2));
% Corresponding elements have different TimeUnit values
typeArray3 = [time32Type2 time32Type1];
typeArray4 = [time32Type1 time32Type2]';
testCase.verifyFalse(isequal(typeArray3, typeArray4));
% Compare a nonscalar Time32Type array with a nonscalar
% Int32Type array.
typeArray5 = [int32Type int32Type];
testCase.verifyFalse(isequal(typeArray3, typeArray5));
end
end
end
|