Skip to content

Commit

Permalink
Add tests for getRowString for Table Proxy class
Browse files Browse the repository at this point in the history
  • Loading branch information
sgilmore10 committed Oct 24, 2023
1 parent 7413110 commit fab0a14
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions matlab/test/arrow/tabular/tTabularInternal.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
%TTABULARINTERNAL Unit tests for internal tabular functionality.

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

properties(TestParameter)
TabularObjectWithAllTypes

TabularObjectWithOneColumn

TabularObjectWithThreeRows
end

methods (TestParameterDefinition, Static)
function TabularObjectWithAllTypes = initializeTabularObjectWithAllTypes()
arrays = arrow.internal.test.tabular.createAllSupportedArrayTypes(NumRows=1);
TabularObjectWithAllTypes = {arrow.tabular.Table.fromArrays(arrays{:})};
end

function TabularObjectWithOneColumn = initializeTabularObjectWithOneColumn()
TabularObjectWithOneColumn = {arrow.table(table((1:3)'))};
end

function TabularObjectWithThreeRows = initializeTabularObjectWithThreeRows()
TabularObjectWithThreeRows = {arrow.table(table((1:3)', ["A"; "B"; "C"]))};
end
end

methods (Test)
function RowWithAllTypes(testCase, TabularObjectWithAllTypes)
proxy = TabularObjectWithAllTypes.Proxy;
columnStrs = ["false", "2024-02-23", "2023-08-24", "78", "38", ...
"24", "48", "89", "102", "<List>", """107""", "<Struct>", ...
"00:03:44", "00:00:07.000000", "2024-02-10 00:00:00.000000", ...
"107", "143", "36", "51"];
expectedString = strjoin(columnStrs, " | ");
actualString = proxy.getRowString(struct(Index=int64(1)));
testCase.verifyEqual(actualString, expectedString);
end

function RowWithOneField(testCase, TabularObjectWithOneColumn)
proxy = TabularObjectWithOneColumn.Proxy;
expectedString = "1";
actualString = proxy.getRowString(struct(Index=int64(1)));
testCase.verifyEqual(actualString, expectedString);
end

function RowIndex(testCase, TabularObjectWithThreeRows)
proxy = TabularObjectWithThreeRows.Proxy;

actualString = proxy.getRowString(struct(Index=int64(1)));
expectedString = "1 | ""A""";
testCase.verifyEqual(actualString, expectedString);

actualString = proxy.getRowString(struct(Index=int64(2)));
expectedString = "2 | ""B""";
testCase.verifyEqual(actualString, expectedString);

actualString = proxy.getRowString(struct(Index=int64(3)));
expectedString = "3 | ""C""";
testCase.verifyEqual(actualString, expectedString);
end

function TabularPrettyPrintRowFailed(testCase, TabularObjectWithThreeRows)
proxy = TabularObjectWithThreeRows.Proxy;
fcn = @() proxy.getRowString(struct(Index=int64(0)));
testCase.verifyError(fcn, "arrow:tabular:PrintRowFailed");

fcn = @() proxy.getRowString(struct(Index=int64(4)));
testCase.verifyError(fcn, "arrow:tabular:PrintRowFailed");
end

end

end

0 comments on commit fab0a14

Please sign in to comment.