comparison testing/utp_1.1/utps/time/utp_time_datenum.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_DOUBLE
2 %
3 % <MethodDescription>
4 %
5 % Test the 'datenum' method of the time class.
6 %
7 % </MethodDescription>
8 %
9 % NOTE: in this test we manipulate user preferences thus we should make
10 % sure we restore the original user preferences at the end of the testing
11 %
12 % $Id: utp_time_datenum.m,v 1.3 2011/04/28 07:06:27 hewitson Exp $
13
14 function results = utp_time_datenum(varargin)
15
16 % check inputs
17 if nargin == 0
18
19 % some keywords
20 class = 'time';
21 mthd = 'datenum';
22
23 results = [];
24 disp('******************************************************');
25 disp(['**** Running UTPs for ' class '/' mthd]);
26 disp('******************************************************');
27
28 % get preferences
29 prefs = getappdata(0, 'LTPDApreferences');
30 oldTimezone = char(prefs.getTimePrefs.getTimeTimezone);
31
32 try
33 results = [results utp_901];
34 results = [results utp_901];
35 results = [results utp_902];
36 results = [results utp_903];
37 catch ex
38 % restore preferences
39
40 rethrow(ex);
41 end
42
43 % restore preferences
44 prefs.getTimePrefs.setTimeTimezone(oldTimezone);
45
46 disp('Done.');
47 disp('******************************************************');
48
49 elseif nargin == 1
50 % check for UTP functions
51 if strcmp(varargin{1}, 'isutp')
52 results = 1;
53 else
54 results = 0;
55 end
56 else
57 error('### Incorrect inputs')
58 end
59
60 %% UTP_901
61
62 % <TestDescription>
63 %
64 % Tests the 'datenum' method.
65 %
66 % </TestDescription>
67 function result = utp_901
68
69 % <SyntaxDescription>
70 % Create a time object and use datenum to produce a serial date number.
71 % </SyntaxDescription>
72
73 stest = false;
74 try
75 % <SyntaxCode>
76 % construct a well known time object
77 t1 = time('1982-08-31 01:02:03 UTC');
78 n1 = datenum(t1);
79 % </SyntaxCode>
80 stest = true;
81 end
82
83 atest = true;
84 try
85 % do not run algorithm tests if sintax tests failed
86 assert(stest);
87
88 % <AlgoDescription>
89 % Check that the returned value is the same as the one you get when
90 % using time/format with the same format string when converted using
91 % MATLAB's datestr() function.
92 % </AlgoDescription>
93
94 % <AlgoCode>
95 assert(strcmp(datestr(n1), t1.format('dd-mmm-yyyy HH:MM:SS')))
96 % </AlgoCode>
97 catch
98 atest = false;
99 end
100
101 % return a result structure
102 result = utp_prepare_result(atest, stest, dbstack, mfilename);
103 end
104
105 %% UTP_902
106
107 % <TestDescription>
108 %
109 % Tests the 'datenum' method.
110 %
111 % </TestDescription>
112 function result = utp_902
113
114 % <SyntaxDescription>
115 % Set the time-zone to UTC and create a time object and use datenum to
116 % produce a serial date number.
117 % </SyntaxDescription>
118 stest = false;
119 try
120 % <SyntaxCode>
121 % set time zone to UTC
122 prefs.getTimePrefs.setTimeTimezone('UTC');
123 % construct a well known time object
124 t1 = time('1982-08-31 01:02:03 UTC');
125 n1 = datenum(t1);
126 % </SyntaxCode>
127 stest = true;
128 end
129
130 atest = true;
131 try
132 % do not run algorithm tests if sintax tests failed
133 assert(stest);
134 % <AlgoDescription>
135 % Check that the returned value is the same as the one you get when
136 % using time/format with the same format string when converted using
137 % MATLAB's datestr() function.
138 % </AlgoDescription>
139 % <AlgoCode>
140 assert(strcmp(datestr(n1), t1.format('dd-mmm-yyyy HH:MM:SS')))
141 % </AlgoCode>
142
143 catch
144 atest = false;
145 end
146
147 % return a result structure
148 result = utp_prepare_result(atest, stest, dbstack, mfilename);
149 end
150
151 %% UTP_903
152
153 % <TestDescription>
154 %
155 % Tests 'double' method.
156 %
157 % </TestDescription>
158 function result = utp_903
159
160 % <SyntaxDescription>
161 % Set the time-zone to PST and create a time object and use datenum to
162 % produce a serial date number.
163 % </SyntaxDescription>
164 stest = false;
165 try
166 % <SyntaxCode>
167 % set time zone to PST
168 prefs.getTimePrefs.setTimeTimezone('PST');
169 % construct a well known time object
170 t1 = time('1982-08-31 01:02:03 UTC');
171 n1 = datenum(t1);
172 % </SyntaxCode>
173 stest = true;
174 end
175
176 atest = true;
177 try
178 % do not run algorithm tests if sintax tests failed
179 assert(stest);
180
181 % <AlgoDescription>
182 % Check that the returned value is the same as the one you get when
183 % using time/format with the same format string when converted using
184 % MATLAB's datestr() function.
185 % </AlgoDescription>
186 % <AlgoCode>
187 assert(strcmp(datestr(n1), t1.format('dd-mmm-yyyy HH:MM:SS')))
188 % </AlgoCode>
189 catch
190 atest = false;
191 end
192
193 % return a result structure
194 result = utp_prepare_result(atest, stest, dbstack, mfilename);
195 end
196
197 end