diff testing/utp_1.1/generic_utps/utp_genericAnyShape.m @ 44:409a22968d5e default

Add unit tests
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Tue, 06 Dec 2011 18:42:11 +0100
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/testing/utp_1.1/generic_utps/utp_genericAnyShape.m	Tue Dec 06 18:42:11 2011 +0100
@@ -0,0 +1,71 @@
+% <TestDescription>
+%
+% Tests that the <METHOD> method works with any shape of objects as input.
+%
+% </TestDescription>
+function result = utp_genericAnyShape(method, objs, args, algo)
+  
+  % <SyntaxDescription>
+  %
+  % Test that the <METHOD> method works for any shape of objects as input.
+  %
+  % </SyntaxDescription>
+  
+  try
+    % <SyntaxCode>
+    if isempty(args)
+      out = feval(method, objs);
+    else
+      if iscell(args)
+        out = feval(method, objs, args{:});
+      else
+        out = feval(method, objs, args);
+      end
+    end
+    % </SyntaxCode>
+    stest = true;
+  catch err
+    disp(err.message)
+    stest = false;
+  end
+  
+  % <AlgoDescription>
+  %
+  % 1) Check that the number of elements in 'out' is the same as in 'objs'
+  % 2) Check that each output object contains the correct data.
+  % 3) Rebuild the object
+  %
+  % </AlgoDescription>
+  
+  atest = true;
+  if stest
+    % <AlgoCode>
+    % 1. Check we have the correct number of outputs
+    if ~isequal(size(out), size(objs)), atest = false; end
+    
+    % 2. Check each output against the correct value
+    for kk=1:numel(out)
+      atest = algo(objs, out, kk, args);
+      if ~atest
+        break;
+      end
+    end
+    
+    % 3. Check that we can rebuild the data
+    r = out.rebuild();
+    for ii = 1:numel(out)
+      if ~eq(r(ii),out(ii), 'UUID', 'proctime', 'methodInvars'), atest = false; end
+    end
+    
+    % </AlgoCode>
+  else
+    atest = false;
+  end
+  
+  % Return a result structure
+  stack = dbstack;
+  if numel(objs) > 1
+    stack(1).name = sprintf('%s %dx%d', stack(1).name, size(objs));
+  end
+  result = utp_prepare_result(atest, stest, stack, ['utp_' class(objs) '_' method]);
+end