diff testing/utp_1.1/utp_template.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/utp_template.m	Tue Dec 06 18:42:11 2011 +0100
@@ -0,0 +1,112 @@
+% UTP_TEMPLATE a set of unit tests for FOO.
+%
+% Joe Blogs 28-07-10
+%
+% $Id: utp_template.m,v 1.5 2010/07/28 04:11:07 hewitson Exp $
+%
+
+% <MethodDescription>
+%
+% The method FOO for the class Boing does bouncy things with data.
+%
+% </MethodDescription>
+
+function results = utp_template(varargin)
+  
+  % Check the inputs
+  if nargin == 0
+    
+    % Some keywords
+    class   = 'Boing';
+    model   = 'foo';
+    
+    results = [];
+    disp('******************************************************');
+    disp(['****  Running Unit Tests for ' class '/' model]);
+    disp('******************************************************');
+    
+    % Run the tests
+    results = [results utp_01()];  % check FOO does something useful
+    
+    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
+  
+  
+  % <TestDescription>
+  %
+  % Tests that the method <FOO> does something useful.
+  %
+  % </TestDescription>
+  %
+  % $Id: utp_template.m,v 1.5 2010/07/28 04:11:07 hewitson Exp $
+  %
+  
+  function result = utp_01(varargin)
+    
+    % <SyntaxDescription>
+    %
+    % Tests that the method <FOO> does something useful.
+    %
+    % </SyntaxDescription>
+    
+    try
+      
+      % <SyntaxCode>
+      
+      % Here we just check that a suitable call to the method can be made.
+      
+      % </SyntaxCode>
+      stest = true;
+    catch err
+      disp(err.message)
+      msg = [err.message ' - ' err.stack(1).name ' - line ' num2str(err.stack(1).line)];
+      stest = false;
+    end
+    
+    % <AlgoDescription>
+    %
+    % 1) Check that the object is pink when embarrassed
+    % 2) Check that the data are nice and shiny
+    %
+    % </AlgoDescription>
+    
+    atest = true;
+    if stest
+      msg = '';
+      % <AlgoCode>
+      
+      % Here we perform detailed checks on the content of the objects or
+      % outputs produced during the syntax check
+      
+      if somethingBad
+        atest = false;
+        msg = 'Oooh something bad happened here';
+      end
+      
+      if somethingElseBad
+        atest = false;
+        msg = 'Wow something else bad happened here';
+      end      
+      
+      % </AlgoCode>
+    else
+      atest = false;
+    end
+    
+    % Return a result structure
+    dd = dbstack;
+    mfilename = dd(2).file(1:end-2);
+    result = utp_prepare_result(atest, stest, dbstack, mfilename, msg);
+  end % END UTP_XX
+  
+end