1
1
classdef SeriesTest < matlab .unittest .TestCase
2
2
3
3
properties (Access = private )
4
- Time , Temperature , Humidity , WindDirection , RainDrops , Raining ;
4
+ Time , Temperature , Humidity , WindDirection , RainDrops , Raining
5
5
end
6
6
7
7
methods (TestMethodSetup )
@@ -17,25 +17,52 @@ function setup(test)
17
17
end
18
18
19
19
methods (Test )
20
- function fails_when_time_is_not_set(test )
20
+ function fails_when_empty_name(test )
21
+ f = @() Series(' ' ).fields(' temperature' , 24.3 ).toLine();
22
+ test .verifyError(f , ' toLine:emptyName' );
23
+ end
24
+
25
+ function fails_when_empty_time(test )
21
26
s = Series(' weather' ) ...
22
27
.fields(' temperature' , test .Temperature );
23
28
test .verifyError(@() s .toLine(), ' toLine:emptyTime' );
24
29
end
25
30
26
- function fails_when_fields_are_not_set (test )
31
+ function allow_empty_time_for_single_samples (test )
27
32
s = Series(' weather' ) ...
28
- .time(test .Time );
29
- test .verifyError(@() s .toLine(), ' toLine:emptyFields' );
33
+ .fields(' temperature' , 24.3 );
34
+ exp = ' weather temperature=24.3' ;
35
+ test .verifyEqual(s .toLine(), exp );
30
36
end
31
37
32
- function field_with_empty_value_fails(test )
33
- f = @() Series(' weather' ) ...
34
- .fields(' temperature' , []);
35
- test .verifyError(f , ' field:emptyValue' );
38
+ function when_empty_fields_return_empty(test )
39
+ s = Series(' weather' );
40
+ test .verifyEqual(s .toLine(), ' ' );
41
+ end
42
+
43
+ function empty_fields_are_ignored(test )
44
+ p = Series(' weather' ) ...
45
+ .fields(' temperature' , [], ' humidity' , 60.7 );
46
+ exp = ' weather humidity=60.7' ;
47
+ test .verifyEqual(p .toLine(), exp );
48
+ end
49
+
50
+ function empty_char_fields_are_not_ignored(test )
51
+ p = Series(' weather' ) ...
52
+ .fields(' temperature' , 24.3 , ' wind_dir' , ' ' );
53
+ exp = ' weather temperature=24.3,wind_dir=""' ;
54
+ test .verifyEqual(p .toLine(), exp );
36
55
end
37
56
38
57
function single_field(test )
58
+ p = Series(' weather' ) ...
59
+ .fields(' temperature' , 24.3 ) ...
60
+ .time(test .Time(1 ));
61
+ exp = ' weather temperature=24.3 1529933525520' ;
62
+ test .verifyEqual(p .toLine(), exp );
63
+ end
64
+
65
+ function single_field_array(test )
39
66
s = Series(' weather' ) ...
40
67
.time(test .Time ) ...
41
68
.fields(' temperature' , test .Temperature );
@@ -55,7 +82,15 @@ function supports_fields_with_integer_values(test)
55
82
test .verifyEqual(p .toLine(), exp );
56
83
end
57
84
58
- function supports_fields_with_string_values(test )
85
+ function supports_fields_with_single_string_value(test )
86
+ p = Series(' weather' ) ...
87
+ .fields(' wind_direction' , ' north-west' ) ...
88
+ .time(test .Time(1 ));
89
+ exp = ' weather wind_direction="north-west" 1529933525520' ;
90
+ test .verifyEqual(p .toLine(), exp );
91
+ end
92
+
93
+ function supports_fields_with_cell_string_values(test )
59
94
p = Series(' weather' ) ...
60
95
.time(test .Time ) ...
61
96
.fields(' wind_direction' , test .WindDirection );
@@ -171,6 +206,15 @@ function fails_when_field_sizes_do_not_match(test)
171
206
end
172
207
173
208
function every_property_is_used(test )
209
+ s = Series(' weather' ) ...
210
+ .time(test .Time(1 )) ...
211
+ .tags(' city' , ' barcelona' ) ...
212
+ .fields(' temperature' , 24.3 );
213
+ exp = ' weather,city=barcelona temperature=24.3 1529933525520' ;
214
+ test .verifyEqual(s .toLine(), exp );
215
+ end
216
+
217
+ function every_property_is_used_with_multiple_samples(test )
174
218
s = Series(' weather' ) ...
175
219
.time(test .Time ) ...
176
220
.tags(' city' , ' barcelona' ) ...
@@ -201,6 +245,14 @@ function skips_nonfinite_samples(test)
201
245
test .verifyEqual(s .toLine(), exp );
202
246
end
203
247
248
+ function returns_empty_when_all_values_are_nonfinite(test )
249
+ s = Series(' weather' ) ...
250
+ .time(test .Time ) ...
251
+ .fields(' temperature' , [NaN ; Inf ]) ...
252
+ .fields(' humidity' , [-Inf ; NaN ]);
253
+ test .verifyEqual(s .toLine(), ' ' );
254
+ end
255
+
204
256
function time_is_added_in_millis_by_default(test )
205
257
millis = 1529933525520 ;
206
258
time = datetime(millis / 1000 , ' ConvertFrom' , ' posixtime' );
0 commit comments