Skip to content

Commit

Permalink
Add isequal unit tests for arrow.buffer.Buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
sgilmore10 committed Oct 4, 2023
1 parent d7fcafd commit 29edeb1
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion matlab/src/matlab/+arrow/+buffer/Buffer.m
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
tf = false;

bufferProxyIDs = zeros([1 numel(varargin)], "uint64");
for ii = 2:numel(varargin)
for ii = 1:numel(varargin)
maybeBuffer = varargin{ii};
if ~isa(maybeBuffer, "arrow.buffer.Buffer")
% If maybeBuffer is not an instance of
Expand Down
47 changes: 47 additions & 0 deletions matlab/test/arrow/buffer/tBuffer.m
Original file line number Diff line number Diff line change
Expand Up @@ -137,5 +137,52 @@ function NumBytesNoSetter(testCase)
fcn = @() setfield(buffer, "NumBytes", int64(1));
testCase.verifyError(fcn, "MATLAB:class:SetProhibited");
end

function IsEqualTrue(testCase)
% Verifies two buffers are considered equal if
% 1. They have the same size (NumBytes)
% 2. They contain the same bytes

import arrow.buffer.Buffer

% Compare two non-empty buffers
buffer1 = Buffer.fromMATLAB([1 2 3]);
buffer2 = Buffer.fromMATLAB([1 2 3]);
testCase.verifyTrue(isequal(buffer1, buffer2));

% Compare two buffers, one of which was created from a double
% array and the other created from a uint8 array. However, both
% arrays have the same bit pattern.
data = zeros([1 24], "uint8");
data([7 8 16 23 24]) = [240 63 64 8 64];
buffer3 = Buffer.fromMATLAB(data);
testCase.verifyTrue(isequal(buffer1, buffer3));

% Compare two empty buffers
buffer4 = Buffer.fromMATLAB([]);
buffer5 = Buffer.fromMATLAB([]);
testCase.verifyTrue(isequal(buffer4, buffer5));

% Compare more than two buffers
testCase.verifyTrue(isequal(buffer1, buffer2, buffer3));
end

function IsEqualFalse(testCase)
% Verifies two buffers are considered equal if
% 1. They have the same size (NumBytes)
% 2. They contain the same bytes

import arrow.buffer.Buffer

buffer1 = Buffer.fromMATLAB([1 2 3]);
buffer2 = Buffer.fromMATLAB([1 3 2]);
buffer3 = Buffer.fromMATLAB([1 2 3 4]);
testCase.verifyFalse(isequal(buffer1, buffer2));
testCase.verifyFalse(isequal(buffer1, buffer3));
testCase.verifyFalse(isequal(buffer1, buffer2, buffer3));

% Compare a buffer to a string
testCase.verifyFalse(isequal(buffer1, "A"));
end
end
end

0 comments on commit 29edeb1

Please sign in to comment.