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