'How to test multiple different type return value in unit test?
My code and test code are as follows:
return two value, one is vector, and is boolean. Using command to test is ok. But in unit test it is in error.
command test as follows:
nLine = 1./[10,100000; 100000,10; -10,1000000; 100000,-10]';
mm = [0,0];
[nPoint,isConverge] = get_line_intersect(nLine,mm)
unit test call return error
---------
Error ID:
---------
'MATLAB:catenate:dimensionMismatch'
--------------
Error Details:
--------------
Error using horzcat
Dimensions of arrays being concatenated are not consistent.
Error in get_line_intersectTest>testRect (line 13)
expSolution = [nPointData,true];
my code:
function [nPoint,isConverge] = get_line_intersect(nLine,mm)
switch length(nLine)
case 4
L1 = nLine(:,1);
L2 = nLine(:,2);
L3 = nLine(:,3);
L4 = nLine(:,4);
x12=[L1';L2']\ones(2,1)+mm';
x23=[L2';L3']\ones(2,1)+mm';
x34=[L3';L4']\ones(2,1)+mm';
x41=[L4';L1']\ones(2,1)+mm';
nPoint = round([x12 x23 x34 x41]),
isConverge = ~any(nPoint(:)> 10^4);
case 3
L1 = nLine(:,1);
L2 = nLine(:,2);
L3 = nLine(:,3);
x12=[L1';L2']\ones(2,1)+mm';
x23=[L2';L3']\ones(2,1)+mm';
x31=[L3';L1']\ones(2,1)+mm';
nPoint = round([x12 x23 x31]);
isConverge = ~any(nPoint(:)> 10^4);
end
end
test code
function tests = get_line_intersectTest
tests = functiontests(localfunctions);
end
%% 4 line test
function testRect(testCase)
nLine = 1./[10,100000; 100000,10; -10,1000000; 100000,-10]';
mm = [0,0];
actSolution = get_line_intersect(nLine,mm);
nPointData = ...%[10,10;-10,10;-10,-10;10,-10]';
[10 -10 -10 10;...
10 10 -10 -10];
expSolution = [nPointData,true];
verifyEqual(testCase,actSolution,expSolution)
end
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|