Revision: 2064
Author: swige.ide
Date: Wed Jun 19 08:16:28 2013
Log: issue #72
BugFix: added checking for normOpFun in absreldiff and the test. Removed
code repetition in SuiteEllTube test (testRelativeComparison).
http://code.google.com/p/ellipsoids/source/detail?r=2064
Modified:
/branches/issue_72_yadmiralsky/products/+gras/+ellapx/+smartdb/+test/+mlunit/SuiteEllTube.m
/branches/issue_72_yadmiralsky/products/+gras/+gen/+test/+mlunit/SuiteBasic.m
/branches/issue_72_yadmiralsky/products/+gras/+gen/absreldiff.m
=======================================
---
/branches/issue_72_yadmiralsky/products/+gras/+ellapx/+smartdb/+test/+mlunit/SuiteEllTube.m
Thu Jun 13 10:46:09 2013
+++
/branches/issue_72_yadmiralsky/products/+gras/+ellapx/+smartdb/+test/+mlunit/SuiteEllTube.m
Wed Jun 19 08:16:28 2013
@@ -313,9 +313,6 @@
end
end
%
-
-
-
function testPlotTouch(self)
[relStatProj,relDynProj]=checkMaster(1);
[rel2StatProj,rel2DynProj]=checkMaster(10);
@@ -618,49 +615,55 @@
end
end
function self = testRelativeComparison(self)
- import gras.ellapx.smartdb.rels.EllTube.fromQArrays;
nPoints=5;
- calcPrecision=0.001;
relTolerance=0.01;
- approxSchemaDescr=char.empty(1,0);
- approxSchemaName=char.empty(1,0);
- nDims=3;
- nTubes=1;
lsGoodDirVec=[1;0;1];
- aMat=zeros(nDims,nPoints);
timeVec=1:nPoints;
sTime=nPoints;
- approxType=gras.ellapx.enums.EApproxType.Internal;
+ fCheckFun = @(x, y) x.isEqual(y, 'MaxRelativeTolerance', ...
+ relTolerance);
%
- qArrayListBase=repmat({repmat(diag([1 2 3]),[1,1,nPoints])},...
- 1,nTubes);
- ltGoodDirArray=repmat(lsGoodDirVec,[1,nTubes,nPoints]);
+ qArrayListBase = repmat({repmat(diag([1 2 3]), [1, 1, ...
+ nPoints])}, 1, 1);
+ firstEllTube = createSimpleRel(lsGoodDirVec, ...
+ qArrayListBase, timeVec, sTime);
%
- firstEllTube=gras.ellapx.smartdb.rels.EllTube.fromQArrays(...
- qArrayListBase, aMat, timeVec,...
- ltGoodDirArray, sTime, approxType, approxSchemaName,...
- approxSchemaDescr, calcPrecision);
qArrayList = {qArrayListBase{:} .* (1 - 0.5 * relTolerance)};
- secondEllTube=gras.ellapx.smartdb.rels.EllTube.fromQArrays(...
- qArrayList, aMat, timeVec,...
- ltGoodDirArray, sTime, approxType, approxSchemaName,...
- approxSchemaDescr, calcPrecision);
- %
- [isEqual,reportStr]=...
- firstEllTube.isEqual(secondEllTube, ...
- 'MaxRelativeTolerance', relTolerance);
+ secondEllTube = createSimpleRel(lsGoodDirVec, ...
+ qArrayList, timeVec, sTime);
+ [isEqual,reportStr] = fCheckFun(firstEllTube, secondEllTube);
mlunitext.assert(isEqual,reportStr);
%
qArrayList = {qArrayListBase{:} .* (1 + 2 * relTolerance)};
- secondEllTube=gras.ellapx.smartdb.rels.EllTube.fromQArrays(...
- qArrayList, aMat, timeVec,...
+ secondEllTube = createSimpleRel(lsGoodDirVec, ...
+ qArrayList, timeVec, sTime);
+ [isEqual,~] = fCheckFun(firstEllTube, secondEllTube);
+ mlunitext.assert(~isEqual, ['Ellipsoids relative', ...
+ ' difference must be greater than tolerance']);
+ %
+ function rel = createSimpleRel(lsGoodDirVec, qArrayList, ...
+ timeVec, sTime)
+ import gras.ellapx.smartdb.rels.EllTube;
+ %
+ calcPrecision = 0.001;
+ nTubes = size(qArrayList, 2);
+ approxSchemaDescr = char.empty(1,0);
+ approxSchemaName = char.empty(1,0);
+ approxType = gras.ellapx.enums.EApproxType.Internal;
+ nTimePoints = timeVec(end);
+ if ~isempty(qArrayList)
+ nDims = size(qArrayList{1}, 1);
+ else
+ rel = [];
+ return;
+ end
+ aMat = zeros(nDims,nTimePoints);
+ ltGoodDirArray =
repmat(lsGoodDirVec,[1,nTubes,nTimePoints]);
+ %
+ rel = EllTube.fromQArrays(qArrayList, aMat, timeVec,...
ltGoodDirArray, sTime, approxType, approxSchemaName,...
approxSchemaDescr, calcPrecision);
- [isEqual,~]=...
- firstEllTube.isEqual(secondEllTube, ...
- 'MaxRelativeTolerance', relTolerance);
- mlunitext.assert(~isEqual,...
- 'Ellipsoids relative difference is greater than
tolerance');
+ end
end
end
end
=======================================
---
/branches/issue_72_yadmiralsky/products/+gras/+gen/+test/+mlunit/SuiteBasic.m
Wed Jun 19 07:04:16 2013
+++
/branches/issue_72_yadmiralsky/products/+gras/+gen/+test/+mlunit/SuiteBasic.m
Wed Jun 19 08:16:28 2013
@@ -160,6 +160,10 @@
self.runAndCheckError(...
'gras.gen.absreldiff([1 1], [1 1], [0.1, -0.1], @abs)', ...
'wrongInput:wrongAbsTol');
+ % normOpFun error
+ self.runAndCheckError(...
+ 'gras.gen.absreldiff([1 1], [1 1], 0.1, 100)', ...
+ 'wrongInput:wrongnormOpFun');
% result tests
xVec = [1 2]; yVec = [2 4];
[zVec, isRelComp] = absreldiff(xVec, yVec, 0.5, @abs);
=======================================
--- /branches/issue_72_yadmiralsky/products/+gras/+gen/absreldiff.m Mon Jun
17 08:57:39 2013
+++ /branches/issue_72_yadmiralsky/products/+gras/+gen/absreldiff.m Wed Jun
19 08:16:28 2013
@@ -40,16 +40,20 @@
% $Copyright: Moscow State University,
% Faculty of Computational Mathematics and Computer Science,
% System Analysis Department 2013 $
+
import modgen.common.checkvar;
import modgen.common.checkmultvar;
%
-checkmultvar('isequal(size(x1),size(x2))&&isnumeric(x1)&&isnumeric(x2)',
2, ...
- arg1Arr, arg2Arr, 'ErrorTag', 'wrongInput:wrongArgs', ...
+checkmultvar('isequal(size(x1),size(x2))&&isnumeric(x1)&&isnumeric(x2)',...
+ 2, arg1Arr, arg2Arr, 'ErrorTag', 'wrongInput:wrongArgs', ...
'ErrorMessage', ['arg1Mat and arg2Mat must be numeric arrays with', ...
' the same size']);
-checkvar(absTol, 'isnumeric(x)&&isscalar(x)&&(x>0)', 'errorTag', ...
+checkvar(absTol, 'isnumeric(x)&&isscalar(x)&&(x>=0)', 'errorTag', ...
'wrongInput:wrongAbsTol', 'ErrorMessage', ['absTol must be a', ...
- ' positive scalar']);
+ ' nonnegative scalar']);
+checkvar(normOpFun, 'isfunction(x)', 'errorTag', ...
+ 'wrongInput:wrongnormOpFun', 'ErrorMessage', ['normOpFun must be ', ...
+ 'a function handle']);
%
compMat = normOpFun(arg1Arr - arg2Arr);
isRelComparison = compMat > absTol;