diff testing/utp_1.1/utps/time/utp_time_minus.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/utps/time/utp_time_minus.m	Tue Dec 06 18:42:11 2011 +0100
@@ -0,0 +1,114 @@
+% UTP_TIME_TIME
+%
+% <MethodDescription>
+%
+% Tests time object minus operator.
+%
+% </MethodDescription>
+%
+% $Id: utp_time_minus.m,v 1.2 2011/04/28 07:06:27 hewitson Exp $
+
+function results = utp_time_minus(varargin)
+  
+  global DEBUG
+  DEBUG = false;
+  
+  % check inputs
+  if nargin == 0
+    
+    % some keywords
+    class   = 'time';
+    mthd    = 'minus';
+    
+    results = [];
+    disp('******************************************************');
+    disp(['****  Running UTPs for ' class '/' mthd]);
+    disp('******************************************************');
+    
+    % get preferences
+    prefs = getappdata(0, 'LTPDApreferences');
+    timezone = char(prefs.getTimePrefs.getTimeTimezone);
+    
+    % set timezone to UTC to simplify testing
+    prefs.getTimePrefs.setTimeTimezone('UTC');
+    
+    % get preferences
+    try
+      results = [results utp_01];
+    catch ex
+      % restore preferences
+      prefs.getTimePrefs.setTimeTimezone(timezone);
+      rethrow(ex);
+    end
+    
+    % restore preferences
+    prefs.getTimePrefs.setTimeTimezone(timezone);
+    
+    disp('Done.');
+    disp('******************************************************');
+    
+  elseif nargin == 1
+    % check for UTP functions
+    if strcmp(varargin{1}, 'isutp')
+      results = 1;
+    else
+      results = 0;
+    end
+  else
+    error('### Incorrect inputs')
+  end
+  
+  %% UTP_01
+  
+  % <TestDescription>
+  %
+  % Tests time object minus operator.
+  %
+  % </TestDescription>
+  function result = utp_01
+    
+    % <SyntaxDescription>
+    % Compute the difference between time objects and doubles.
+    % </SyntaxDescription>
+    stest = false;
+    try
+      % <SyntaxCode>
+      t1 = time(2);
+      t2 = t1 - time(2);
+      t3 = t1 - 2;
+      t4 = t1 - '00:00:02';
+      t5 = 2 - t1;
+      t6 = '00:00:02' - t1;
+      t7 = t1 - [2 2];
+      t8 = [2; 2] - t1;
+      % </SyntaxCode>      
+      stest = true;
+    end
+    
+    atest = true;
+    try
+      % do not run algorithm tests if sintax tests failed
+      assert(stest);
+      
+      % <AlgoDescription>
+      % Check the resulting time objects have the correct values.
+      % </AlgoDescription>
+      % <AlgoCode>
+      assert(double(t2) == 0);
+      assert(double(t3) == 0);
+      assert(double(t4) == 0);
+      assert(double(t5) == 0);
+      assert(double(t6) == 0);
+      assert(all(double(t7) == 0));
+      assert(all(size(t7) == [1, 2]))
+      assert(all(double(t8) == 0));
+      assert(all(size(t8) == [2, 1]))
+      % </AlgoCode>
+    catch ex
+      atest = false;
+    end
+    
+    % return a result structure
+    result = utp_prepare_result(atest, stest, dbstack, mfilename);
+  end
+end