File: tValidateArray.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 (101 lines) | stat: -rw-r--r-- 4,591 bytes parent folder | download | duplicates (2)
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
%TVALIDATEARRAY Test class for the arrow.array.Array/validate() method.

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

    methods (Test)

        function InvalidModeInput(test)
            % Verify arrow.array.Array/validate() throws an exception if
            % provided an invalid value for the Mode name-value 
            % pair.
            array = arrow.array.Float64Array.fromMATLAB(1:5);

            % Cannot convert "abc" to a ValidationMode value
            fcn = @() array.validate(Mode="abc");
            test.verifyError(fcn, "MATLAB:validation:UnableToConvert");

            % Mode must be scalar
            modes = [arrow.array.ValidationMode.Full arrow.array.ValidationMode.Minimal];
            fcn = @() array.validate(Mode=modes);
            test.verifyError(fcn, "MATLAB:validation:IncompatibleSize");

            % ValidationMode.None is not supported
            mode = arrow.array.ValidationMode.None;
            fcn = @() array.validate(Mode=mode);
            test.verifyError(fcn, "arrow:array:InvalidValidationMode");
        end

        function ValidationModeMinimalFails(test)
            % Verify arrow.array.Array/validate() throws an exception 
            % with the ID arrow:array:ValidateMinimalFailed if
            % Mode="Minimal" and the array fails the "Minimal"
            % validation checks.
            offsets = arrow.array(int32([0 1 3 4 5]));
            values = arrow.array([1 2 3]);
            array = arrow.array.ListArray.fromArrays(offsets, values, ValidationMode="None");
            fcn = @() array.validate(Mode="Minimal");
            test.verifyError(fcn, "arrow:array:ValidateMinimalFailed")
        end

        function ValidationModeMinimalPasses(test)
            % Verify arrow.array.Array/validate() does not throw an
            % exception if Mode="Minimal" and the array passes the
            % "Minimal" validation checks.
            offsets = arrow.array(int32([0 1 0]));
            values = arrow.array([1 2 3]);
            % NOTE: the array is actually invalid, but it passes the
            % "Minimal" validation checks.
            array = arrow.array.ListArray.fromArrays(offsets, values);
            fcn = @() array.validate(Mode="Minimal");
            test.verifyWarningFree(fcn, "arrow:array:ValidateMinimalFailed")
        end

        function ValidationModeFullFails(test)
            % Verify arrow.array.Array/validate() throws an exception 
            % with the ID arrow:array:ValidateFullFailed if
            % Mode="Full" and the array fails the "Full"
            % validation checks.
            offsets = arrow.array(int32([0 1 0]));
            values = arrow.array([1 2 3]);
            array = arrow.array.ListArray.fromArrays(offsets, values);
            fcn = @() array.validate(Mode="Full");
            test.verifyError(fcn, "arrow:array:ValidateFullFailed")
        end

        function ValidationModeFullPasses(test)
            % Verify arrow.array.Array/validate() does not throw an
            % exception if Mode="Full" and the array passes
            % the "full" validation checks.
            offsets = arrow.array(int32([0 1 3]));
            values = arrow.array([1 2 3]);
            array = arrow.array.ListArray.fromArrays(offsets, values);
            fcn = @() array.validate(Mode="Full");
            test.verifyWarningFree(fcn);
        end

        function DefaultValidationModeIsMimimal(test)
            % Verify the default Mode value is "Minimal".
            offsets = arrow.array(int32([0 1 2 3]));
            values = arrow.array([1 2 3]);
            array = arrow.array.ListArray.fromArrays(offsets, values);
            fcn = @() array.validate();
            test.verifyWarningFree(fcn, "arrow:array:ValidateMinimalFailed")
        end
    end

end