diff testing/utp_1.1/generic_utps/check_aop_errors.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/check_aop_errors.m	Tue Dec 06 18:42:11 2011 +0100
@@ -0,0 +1,40 @@
+%
+% DESCRIPTION: Generic check for a arithmetic operator unit test which
+%              checks the y-errors for a single inputs.
+%
+% CALL:        atest = check_aop_errors(fcn, in1, in2, out);
+%
+% VERSION:     $Id: check_aop_errors.m,v 1.2 2010/09/21 16:50:14 ingo Exp $
+%
+
+function atest = check_aop_errors(fcn, in1, in2, out)
+  if ~isempty(in1.dy) || ~isempty(in2.dy)
+    
+    din1 = in1.dy;
+    din2 = in2.dy;
+    
+    if isempty(din1)
+      din1 = zeros(size(in1.y));
+    end
+    if isempty(din2)
+      din2 = zeros(size(in2.y));
+    end
+    
+    switch func2str(fcn)
+      case {'plus', 'minus'}
+        dy = sqrt(din1.^2 + din2.^2);
+      case {'times', 'mtimes'}
+        dy = sqrt( (din1./in1.y).^2 + (din2./in2.y).^2 ) .* abs(in1.y.*in2.y);
+      case {'rdivide', 'mrdivide'}
+        dy = sqrt( (din1./in1.y).^2 + (din2./in2.y).^2 ) .* abs(in1.y./in2.y);
+      otherwise
+        dy = [];
+    end
+    
+  else
+    dy = [];
+  end
+  
+  atest = isequal(out.dy, dy);
+  
+end