File: tTimestampType.m

package info (click to toggle)
apache-arrow 23.0.1-1
  • links: PTS
  • area: main
  • in suites: sid
  • size: 76,220 kB
  • sloc: cpp: 654,608; python: 70,522; ruby: 45,964; ansic: 18,742; sh: 7,365; makefile: 669; javascript: 125; xml: 41
file content (179 lines) | stat: -rw-r--r-- 8,053 bytes parent folder | download | duplicates (6)
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
% 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 tTimestampType < hFixedWidthType
% Test class for arrow.type.TimestampType

    properties
        ArrowType = arrow.timestamp
        TypeID = arrow.type.ID.Timestamp
        BitWidth = int32(64)
        ClassName = "arrow.type.TimestampType"
    end

    properties(TestParameter)
        % Test against both "Zoned" (i.e. non-empty TimeZone value) 
        % and "Unzoned" (i.e. empty TimeZone value).
        TimeZone={'America/Anchorage', ''}
    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 Microsecond
            type = arrow.timestamp;
            actualUnit = type.TimeUnit;
            expectedUnit = arrow.type.TimeUnit.Microsecond; 
            testCase.verifyEqual(actualUnit, expectedUnit);
        end

        function DefaultTimeZone(testCase)
        % Verify the default TimeZone is ""
            type = arrow.timestamp;
            actualTimezone = type.TimeZone;
            expectedTimezone = "";
            testCase.verifyEqual(actualTimezone, expectedTimezone);
        end

        function SupplyTimeUnitEnum(testCase)
        % Supply TimeUnit as an enum value.
            import arrow.type.*
            expectedUnit = [TimeUnit.Second, TimeUnit.Millisecond ...
                            TimeUnit.Microsecond, TimeUnit.Nanosecond];

            for unit = expectedUnit
                type = arrow.timestamp(TimeUnit=unit);
                testCase.verifyEqual(type.TimeUnit, unit);
            end
        end

        function SupplyTimeUnitString(testCase)
        % Supply TimeUnit as an string value. Verify TimeUnit is set to
        % the appropriate TimeUnit enum value.
            import arrow.type.*
            unitString = ["second", "millisecond", "microsecond", "nanosecond"];
            expectedUnit = [TimeUnit.Second, TimeUnit.Millisecond ...
                            TimeUnit.Microsecond, TimeUnit.Nanosecond];
            
            for ii = 1:numel(unitString)
                type = arrow.timestamp(TimeUnit=unitString(ii));
                testCase.verifyEqual(type.TimeUnit, expectedUnit(ii));
            end
        end

        function SupplyTimeZone(testCase)
        % Supply the TimeZone. 
            type = arrow.timestamp(TimeZone="America/New_York");
            testCase.verifyEqual(type.TimeZone, "America/New_York");
        end

        function ErrorIfMissingStringTimeZone(testCase)
            fcn = @() arrow.timestamp(TimeZone=string(missing));
            testCase.verifyError(fcn, "MATLAB:validators:mustBeNonmissing");
        end

        function ErrorIfTimeZoneIsNonScalar(testCase)
            fcn = @() arrow.timestamp(TimeZone=["a", "b"]);
            testCase.verifyError(fcn, "MATLAB:validation:IncompatibleSize");

            fcn = @() arrow.timestamp(TimeZone=strings(0, 0));
            testCase.verifyError(fcn, "MATLAB:validation:IncompatibleSize");
        end

        function ErrorIfAmbiguousTimeUnit(testCase)
            fcn = @() arrow.timestamp(TimeUnit="mi");
            testCase.verifyError(fcn, "MATLAB:validation:UnableToConvert");
        end

        function ErrorIfTimeUnitIsNonScalar(testCase)
            units = [arrow.type.TimeUnit.Second; arrow.type.TimeUnit.Millisecond];
            fcn = @() arrow.timestamp(TimeUnit=units);
            testCase.verifyError(fcn, "MATLAB:validation:IncompatibleSize");

            units = ["second" "millisecond"];
            fcn = @() arrow.timestamp(TimeUnit=units);
            testCase.verifyError(fcn, "MATLAB:validation:IncompatibleSize");
        end

        function IsEqualTrue(testCase, TimeZone)
            % Verifies isequal method of arrow.type.TimestampType returns 
            % true if these conditions are met:
            %
            % 1. All input arguments have a class type arrow.type.TimestampType
            % 2. All inputs have the same size
            % 3. The TimeUnit values of elements at corresponding positions in the arrays are equal
            % 4. The TimeZone values of elements at corresponding positions in the arrays are equal

            % Scalar TimestampType arrays
            timestampType1 = arrow.timestamp(TimeUnit="Second", TimeZone=TimeZone);
            timestampType2 = arrow.timestamp(TimeUnit="Second", TimeZone=TimeZone);

            timestampType3 = arrow.timestamp(TimeUnit="Millisecond", TimeZone=TimeZone);
            time64Type4 = arrow.timestamp(TimeUnit="Millisecond", TimeZone=TimeZone);

            timestampType5 = arrow.timestamp(TimeUnit="Microsecond", TimeZone=TimeZone);
            timestampType6 = arrow.timestamp(TimeUnit="Microsecond", TimeZone=TimeZone);

            timestampType7 = arrow.timestamp(TimeUnit="Nanosecond", TimeZone=TimeZone);
            timestampType8 = arrow.timestamp(TimeUnit="Nanosecond", TimeZone=TimeZone);

            % Scalar TimestampType arrays
            testCase.verifyTrue(isequal(timestampType1, timestampType2));
            testCase.verifyTrue(isequal(timestampType3, time64Type4));
            testCase.verifyTrue(isequal(timestampType5, timestampType6));
            testCase.verifyTrue(isequal(timestampType7, timestampType8));

            % Non-scalar TimestampType arrays
            typeArray1 = [timestampType1 timestampType3 timestampType5 timestampType7];
            typeArray2 = [timestampType2 time64Type4 timestampType6 timestampType8];
            testCase.verifyTrue(isequal(typeArray1, typeArray2));
        end

        function IsEqualFalse(testCase)
            % Verify isequal returns false when expected.

            timestampType1 = arrow.timestamp(TimeUnit="Second");
            timestampType2 = arrow.timestamp(TimeUnit="Millisecond");
            timestampType3 = arrow.timestamp(TimeUnit="Second", TimeZone="America/New_York");
            timestampType4 = arrow.timestamp(TimeUnit="Second", TimeZone="Pacific/Fiji");
            timestampType5 = arrow.timestamp(TimeUnit="Millisecond", TimeZone="America/New_York");

            % TimeUnit values differ
            testCase.verifyFalse(isequal(timestampType1, timestampType2));
            testCase.verifyFalse(isequal(timestampType4, timestampType5));

            % One TimestampType is zoned, while the other is unzoned.
            testCase.verifyFalse(isequal(timestampType1, timestampType3));

            % Both TimestampTypes are zoned, but have different values.
            testCase.verifyFalse(isequal(timestampType3, timestampType4));

            % Different dimensions
            typeArray1 = [timestampType1 timestampType2 timestampType3];
            typeArray2 = [timestampType1 timestampType2 timestampType3]';
            testCase.verifyFalse(isequal(typeArray1, typeArray2));

            % Different TimestampType values at corresponding elements
            typeArray3 = [timestampType1 timestampType3 timestampType4];
            typeArray4 = [timestampType1 timestampType2 timestampType4];
            testCase.verifyFalse(isequal(typeArray3, typeArray4));
        end
    end
end