diff testing/utp_1.1/utps/time/utp_time_plus.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_plus.m	Tue Dec 06 18:42:11 2011 +0100
@@ -0,0 +1,111 @@
+% UTP_TIME_TIME
+%
+% <MethodDescription>
+%
+% Tests time object plus operator.
+%
+% </MethodDescription>
+%
+% $Id: utp_time_plus.m,v 1.2 2011/04/28 07:06:27 hewitson Exp $
+
+function results = utp_time_plus(varargin)
+  
+  % check inputs
+  if nargin == 0
+    
+    % some keywords
+    class   = 'time';
+    mthd    = 'plus';
+    
+    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_101];
+    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 plus operator.
+  %
+  % </TestDescription>
+  function result = utp_101
+    
+    % <SyntaxDescription>
+    % Compute the sum of 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) == 4);
+      assert(double(t3) == 4);
+      assert(double(t4) == 4);
+      assert(double(t5) == 4);
+      assert(double(t6) == 4);
+      assert(all(double(t7) == 4));
+      assert(all(size(t7) == [1, 2]))
+      assert(all(double(t8) == 4));
+      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
\ No newline at end of file