diff testing/utp_1.1/generic_utps/check_aop_units.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_units.m	Tue Dec 06 18:42:11 2011 +0100
@@ -0,0 +1,28 @@
+%
+% DESCRIPTION: Generic check for a arithmetic operator unit test which
+%              checks the y-units for a single inputs.
+%
+% CALL:        atest = check_aop_units(fcn, in1, in2, out);
+%
+% VERSION:     $Id: check_aop_units.m,v 1.3 2010/09/23 18:19:21 ingo Exp $
+%
+
+function atest = check_aop_units(fcn, in1, in2, out)
+  if utils.helper.ismember(func2str(fcn), {'plus', 'minus'})
+    % return the first non-empty
+    if ~isempty(in1.data.yunits.strs)
+      uo = in1.data.yunits;
+    else
+      uo = in2.data.yunits;
+    end
+  elseif utils.helper.ismember(func2str(fcn), {'or', 'and', 'xor'})
+    uo = unit();
+  else
+    % For other operators we need to apply the operator
+    uo = fcn(in1.data.yunits, in2.data.yunits);
+  end
+  
+  atest = eq(uo, out.yunits);
+  
+end
+