44
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % UTP_TIME_TIME
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 % <MethodDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % Tests time object plus operator.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % </MethodDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 % $Id: utp_time_plus.m,v 1.2 2011/04/28 07:06:27 hewitson Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 function results = utp_time_plus(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 % check inputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 if nargin == 0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 % some keywords
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 class = 'time';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 mthd = 'plus';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 results = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 disp('******************************************************');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 disp(['**** Running UTPs for ' class '/' mthd]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 disp('******************************************************');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 % get preferences
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 prefs = getappdata(0, 'LTPDApreferences');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 timezone = char(prefs.getTimePrefs.getTimeTimezone);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 % set timezone to UTC to simplify testing
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 prefs.getTimePrefs.setTimeTimezone('UTC');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 % get preferences
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 results = [results utp_101];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 catch ex
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 % restore preferences
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 prefs.getTimePrefs.setTimeTimezone(timezone);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 rethrow(ex);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 % restore preferences
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 prefs.getTimePrefs.setTimeTimezone(timezone);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 disp('Done.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 disp('******************************************************');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 elseif nargin == 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 % check for UTP functions
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 if strcmp(varargin{1}, 'isutp')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 results = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 results = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 error('### Incorrect inputs')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 %% UTP_01
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 % Tests time object plus operator.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 function result = utp_101
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 % Compute the sum of time objects and doubles.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 t1 = time(2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 t2 = t1 + time(2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 t3 = t1 + 2;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 t4 = t1 + '00:00:02';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 t5 = 2 + t1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 t6 = '00:00:02' + t1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 t7 = t1 + [2 2];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 t8 = [2; 2] + t1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 % do not run algorithm tests if sintax tests failed
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 assert(stest);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 % Check the resulting time objects have the correct values.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 assert(double(t2) == 4);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 assert(double(t3) == 4);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 assert(double(t4) == 4);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 assert(double(t5) == 4);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 assert(double(t6) == 4);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 assert(all(double(t7) == 4));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 assert(all(size(t7) == [1, 2]))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 assert(all(double(t8) == 4));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 assert(all(size(t8) == [2, 1]))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 catch ex
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 % return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 end |