File: tTypeDisplay.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 (298 lines) | stat: -rw-r--r-- 13,220 bytes parent folder | download | duplicates (5)
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
%TTYPEDISPLAY Unit tests verifying the display of all classes within the
%arrow.type.Type class hierarchy.

% 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 tTypeDisplay < matlab.unittest.TestCase

    properties(TestParameter)
        TypeDisplaysOnlyID = {arrow.boolean(), ...
                              arrow.uint8(), ...
                              arrow.uint16(), ...
                              arrow.uint32(), ...
                              arrow.uint64(), ...
                              arrow.int8(), ...
                              arrow.int16(), ...
                              arrow.int32(), ...
                              arrow.int64(), ...
                              arrow.float32(), ...
                              arrow.float64(), ...
                              arrow.float64(), ...
                              arrow.string()}

        TimeType = {arrow.time32(TimeUnit="Second"), ...
                   arrow.time64(TimeUnit="Nanosecond")};

        DateType = {arrow.date32(), ...
                    arrow.date64()};
    end

    methods (Test)
        function EmptyTypeDisplay(testCase)
            % Verify the display of an empty arrow.type.Type instance.
            %
            % Example:
            %
            %  0x1 Type array with properties:
            %
            %    ID

            import arrow.internal.test.display.verify
            import arrow.internal.test.display.makeLinkString
            import arrow.internal.test.display.makeDimensionString

            type = arrow.type.Type.empty(0, 1);
            typeLink = makeLinkString(FullClassName="arrow.type.Type", ClassName="Type", BoldFont=true);
            dimensionString = makeDimensionString(size(type));
            header = "  " + dimensionString + " " + typeLink + " array with properties:" + newline;
            body = strjust(pad("ID"));
            body = "    " + body;
            footer = string(newline);
            expectedDisplay = char(strjoin([header body' footer], newline));
            actualDisplay = evalc('disp(type)');
            verify(testCase, actualDisplay, expectedDisplay);
        end

        function NonScalarArrayDifferentTypes(testCase)
            % Verify the display of a nonscalar, heterogeneous arrow.type.Type array:
            % 
            % Example:
            %
            %  1×2 heterogeneous FixedWidthType (Float32Type, TimestampType) array with properties:
            %
            %    ID

            import arrow.internal.test.display.verify
            import arrow.internal.test.display.makeLinkString
            import arrow.internal.test.display.makeDimensionString

            float32Type = arrow.float32();
            timestampType = arrow.timestamp();
            typeArray = [float32Type timestampType];

            heterogeneousLink =  makeLinkString(FullClassName="matlab.mixin.Heterogeneous", ClassName="heterogeneous",  BoldFont=false);
            fixedWidthLink    =  makeLinkString(FullClassName="arrow.type.FixedWidthType",  ClassName="FixedWidthType", BoldFont=true);
            timestampLink     = makeLinkString(FullClassName="arrow.type.TimestampType",   ClassName="TimestampType",   BoldFont=false);
            float32Link       = makeLinkString(FullClassName="arrow.type.Float32Type",     ClassName="Float32Type",     BoldFont=false);

            dimensionString = makeDimensionString(size(typeArray));
            
            header = "  " + dimensionString + " " + heterogeneousLink + " " + fixedWidthLink + ...
                " (" +  float32Link + ", " + timestampLink + ") array with properties:" + newline;
            body = "    " + "ID";
            footer = string(newline);
            expectedDisplay = char(strjoin([header body' footer], newline));
            actualDisplay = evalc('disp(typeArray)');
            verify(testCase, actualDisplay, expectedDisplay);
        end

        function NonScalarArraySameTypes(testCase)
            % Verify the display of a scalar, homogeneous arrow.type.Type array:
            % 
            % Example:
            %
            %  1×2 TimestampType array with properties:
            %
            %    ID
            %    TimeUnit
            %    TimeZone 

            import arrow.internal.test.display.verify
            import arrow.internal.test.display.makeLinkString
            import arrow.internal.test.display.makeDimensionString

            timestampType1 = arrow.timestamp(TimeZone="Pacific/Fiji");
            timestampType2 = arrow.timestamp(TimeUnit="Second");
            typeArray = [timestampType1 timestampType2];

            timestampLink = makeLinkString(FullClassName="arrow.type.TimestampType", ClassName="TimestampType", BoldFont=true);
            dimensionString = makeDimensionString(size(typeArray));
            header = "  " + dimensionString + " " + timestampLink + " array with properties:" + newline;
            body = strjust(["ID"; "TimeUnit"; "TimeZone"], "left");
            body = "    " + body;
            footer = string(newline);
            expectedDisplay = char(strjoin([header body' footer], newline));
            actualDisplay = evalc('disp(typeArray)');
            verify(testCase, actualDisplay, expectedDisplay);
        end

        function TestTypeDisplaysOnlyID(testCase, TypeDisplaysOnlyID)
            % Verify the display of arrow.type.Type subclasses that only
            % display the ID property.
            %
            % Example:
            %
            %  BooleanType with properties:
            %
            %          ID: Boolean

            import arrow.internal.test.display.verify
            import arrow.internal.test.display.makeLinkString

            type = TypeDisplaysOnlyID;
            fullClassName = string(class(type));
            className = reverse(extractBefore(reverse(fullClassName), "."));
            typeLink = makeLinkString(FullClassName=fullClassName, ClassName=className, BoldFont=true);
            header = "  " + typeLink + " with properties:" + newline;
            body = "    ID: " + string(type.ID);
            footer = string(newline);
            expectedDisplay = char(strjoin([header body' footer], newline));
            actualDisplay = evalc('disp(type)');
            verify(testCase, actualDisplay, expectedDisplay);
        end

        function TestTimeType(testCase, TimeType)
            % Verify the display of TimeType objects.
            %
            % Example:
            %
            %  Time32Type with properties:
            %
            %          ID: Time32
            %    TimeUnit: Second

            import arrow.internal.test.display.verify
            import arrow.internal.test.display.makeLinkString

            type = TimeType;
            fullClassName = string(class(type));
            className = reverse(extractBefore(reverse(fullClassName), "."));
            typeLink = makeLinkString(FullClassName=fullClassName, ClassName=className, BoldFont=true);

            header = "  " + typeLink + " with properties:" + newline;
            body = strjust(pad(["ID:"; "TimeUnit:"]));
            body = body + " " + [string(type.ID); string(type.TimeUnit)];
            body = "    " + body;
            footer = string(newline);
            expectedDisplay = char(strjoin([header body' footer], newline));
            actualDisplay = evalc('disp(type)');
            verify(testCase, actualDisplay, expectedDisplay);
        end

        function TestDateType(testCase, DateType)
            % Verify the display of DateType objects.
            %
            % Example:
            %
            %  Date32Type with properties:
            %
            %          ID: Date32
            %    DateUnit: Day

            import arrow.internal.test.display.verify
            import arrow.internal.test.display.makeLinkString

            type = DateType;
            fullClassName = string(class(type));
            className = reverse(extractBefore(reverse(fullClassName), "."));
            typeLink = makeLinkString(FullClassName=fullClassName, ClassName=className, BoldFont=true);

            header = "  " + typeLink + " with properties:" + newline;
            body = strjust(pad(["ID:"; "DateUnit:"]));
            body = body + " " + [string(type.ID); string(type.DateUnit)];
            body = "    " + body;
            footer = string(newline);
            expectedDisplay = char(strjoin([header body' footer], newline));
            actualDisplay = evalc('disp(type)');
            verify(testCase, actualDisplay, expectedDisplay);
        end

        function TimestampTypeDisplay(testCase)
            % Verify the display of TimestampType objects.
            %
            % Example:
            %
            %  TimestampType with properties:
            %
            %          ID: Timestamp
            %    TimeUnit: Second
            %    TimeZone: "America/Anchorage"

            import arrow.internal.test.display.verify
            import arrow.internal.test.display.makeLinkString

            type = arrow.timestamp(TimeUnit="Second", TimeZone="America/Anchorage"); %#ok<NASGU>
            classnameLink = makeLinkString(FullClassName="arrow.type.TimestampType", ClassName="TimestampType", BoldFont=true);
            header = "  " + classnameLink + " with properties:" + newline;
            body = strjust(pad(["ID:"; "TimeUnit:"; "TimeZone:"]));
            body = body + " " + ["Timestamp"; "Second"; """America/Anchorage"""];
            body = "    " + body;
            footer = string(newline);
            expectedDisplay = char(strjoin([header body' footer], newline));
            actualDisplay = evalc('disp(type)');
            verify(testCase, actualDisplay, expectedDisplay);
        end

        function StructTypeDisplay(testCase)
            % Verify the display of StructType objects.
            %
            % Example:
            %
            %  StructType with properties:
            %
            %          ID: Struct
            %      Fields: [1x2 arrow.type.Field]

            import arrow.internal.test.display.verify
            import arrow.internal.test.display.makeLinkString
            import arrow.internal.test.display.makeDimensionString

            fieldA = arrow.field("A", arrow.int32());
            fieldB = arrow.field("B", arrow.timestamp(TimeZone="America/Anchorage"));
            type = arrow.struct(fieldA, fieldB); %#ok<NASGU>
            classnameLink = makeLinkString(FullClassName="arrow.type.StructType", ClassName="StructType", BoldFont=true);
            header = "  " + classnameLink + " with properties:" + newline;
            body = strjust(pad(["ID:"; "Fields:"]));
            dimensionString = makeDimensionString([1 2]);
            fieldString = compose("[%s %s]", dimensionString, "arrow.type.Field");
            body = body + " " + ["Struct"; fieldString];
            body = "    " + body;
            footer = string(newline);
            expectedDisplay = char(strjoin([header body' footer], newline));
            actualDisplay = evalc('disp(type)');
            verify(testCase, actualDisplay, expectedDisplay);
        end

        function ListTypeDisplay(testCase)
            % Verify the display of ListType objects.
            %
            % Example:
            %
            %  ListType with properties:
            %
            %          ID: Struct
            %   ValueType: [1x1 arrow.type.StringType]

            import arrow.internal.test.display.verify
            import arrow.internal.test.display.makeLinkString
            import arrow.internal.test.display.makeDimensionString

            valueType = arrow.string();
            type = arrow.list(valueType); %#ok<NASGU>
            classnameLink = makeLinkString(FullClassName="arrow.type.ListType", ClassName="ListType", BoldFont=true);
            header = "  " + classnameLink + " with properties:" + newline;
            body = strjust(pad(["ID:"; "ValueType:"]));
            dimensionString = makeDimensionString([1 1]);
            typeString = compose("[%s %s]", dimensionString, string(class(valueType)));
            body = body + " " + ["List"; typeString];
            body = "    " + body;
            footer = string(newline);
            expectedDisplay = char(strjoin([header body' footer], newline));
            actualDisplay = evalc('disp(type)');
            verify(testCase, actualDisplay, expectedDisplay);
        end
    end
end