Mercurial > hg > ltpda
diff testing/utp_1.1/utps/time/utp_time_double.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_double.m Tue Dec 06 18:42:11 2011 +0100 @@ -0,0 +1,92 @@ +% UTP_TIME_DOUBLE +% +% <MethodDescription> +% +% Test the 'double' method of the time class. +% +% </MethodDescription> +% +% $Id: utp_time_double.m,v 1.2 2011/04/28 07:06:27 hewitson Exp $ + +function results = utp_time_double(varargin) + + % check inputs + if nargin == 0 + + % some keywords + class = 'time'; + mthd = 'double'; + + results = []; + disp('******************************************************'); + disp(['**** Running UTPs for ' class '/' mthd]); + disp('******************************************************'); + + results = [results utp_901]; + + 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_901 + + % <TestDescription> + % + % Tests 'double' method. + % + % </TestDescription> + function result = utp_901 + + % <SyntaxDescription> + % Use the double() method on single time objects and vectors of time + % objects. + % </SyntaxDescription> + stest = false; + try + % <SyntaxCode> + % construct a well known time object + t1 = time('1970-01-01 00:00:12.345 UTC'); + d1 = double(t1); + t2 = [t1 t1]; + d2 = double(t2); + t3 = [t2; t2]; + d3 = double(t3); + % </SyntaxCode> + stest = true; + end + + atest = true; + try + % do not run algorithm tests if sintax tests failed + assert(stest); + + % <AlgoDescription> + % Check that double returns the expected numerical values for each + % case. + % </AlgoDescription> + % <AlgoCode> + assert(d1 == 12.345); + assert(all(d2 == 12.345)); + assert(all(size(d2) == size(t2))); + assert(all(all(d3 == 12.345))); + assert(all(size(d3) == size(t3))); + % </AlgoCode> + catch + atest = false; + end + + % return a result structure + result = utp_prepare_result(atest, stest, dbstack, mfilename); + end + +end