comparison testing/utp_1.1/utps/time/utp_time_string.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
comparison
equal deleted inserted replaced
43:bc767aaa99a8 44:409a22968d5e
1 % UTP_TIME_STRING
2 %
3 % <MethodDescription>
4 %
5 % Test the 'string' method of the time class.
6 %
7 % </MethodDescription>
8 %
9 % $Id: utp_time_string.m,v 1.2 2011/04/28 07:06:27 hewitson Exp $
10
11 function results = utp_time_string(varargin)
12
13 % check inputs
14 if nargin == 0
15
16 % some keywords
17 class = 'time';
18 mthd = 'string';
19
20 results = [];
21 disp('******************************************************');
22 disp(['**** Running UTPs for ' class '/' mthd]);
23 disp('******************************************************');
24
25 % get preferences
26 results = [results utp_901];
27
28 disp('Done.');
29 disp('******************************************************');
30
31 elseif nargin == 1
32 % check for UTP functions
33 if strcmp(varargin{1}, 'isutp')
34 results = 1;
35 else
36 results = 0;
37 end
38 else
39 error('### Incorrect inputs')
40 end
41
42 %% UTP_901
43
44 % <TestDescription>
45 %
46 % Tests that the output of the 'string' method can be used to recreate the time object.
47 %
48 % </TestDescription>
49 function result = utp_901
50
51 % <SyntaxDescription>
52 % Use string to convert a time object to a string. Use eval on the
53 % result to recreate a time object.
54 % </SyntaxDescription>
55 stest = false;
56 try
57 % <SyntaxCode>
58 % create a time object
59 t1 = time();
60 % obtain its string representation
61 str = t1.string();
62 % recreate the object from the string
63 t2 = eval(str);
64 % </SyntaxCode>
65 stest = true;
66 end
67
68 atest = true;
69 try
70 % do not run algorithm tests if sintax tests failed
71 assert(stest);
72
73 % test that the original and the recreated object are the same
74 % <AlgoDescription>
75 % Check the recreated time object matches the original.
76 % </AlgoDescription>
77 % <AlgoCode>
78 assert(t1.utc_epoch_milli == t2.utc_epoch_milli);
79 % </AlgoCode>
80 catch
81 atest = false;
82 end
83
84 % return a result structure
85 result = utp_prepare_result(atest, stest, dbstack, mfilename);
86 end
87
88 end