11classdef TestEventConfig < matlab .unittest .TestCase
2+ % TESTEVENTCONFIG EventConfig surface tests.
3+ %
4+ % All legacy-pipeline methods (cfg.addTag + cfg.runDetection +
5+ % Threshold class) were deleted in Phase 1014 Plan 05: the
6+ % Sensor/Threshold/StateChannel pipeline was removed in Phase 1011
7+ % and EventConfig.addSensor now throws 'EventConfig:legacyRemoved'.
8+ %
9+ % Live-path event detection lives on MonitorTag + EventStore,
10+ % covered by TestMonitorTag* and TestEventStoreRw.
11+
212 methods (TestClassSetup )
313 function addPaths(testCase )
414 addpath(fullfile(fileparts(mfilename(' fullpath' )), ' ..' , ' ..' ));
@@ -17,22 +27,6 @@ function testConstructorDefaults(testCase)
1727 testCase .verifyEqual(cfg .AutoOpenViewer , false , ' defaults: AutoOpenViewer' );
1828 end
1929
20- function testAddTag(testCase )
21- cfg = EventConfig();
22- s = SensorTag(' temp' , ' Name' , ' Temperature' );
23- s .updateData(1 : 10 , [5 5 12 14 11 13 5 5 5 5 ]);
24- [s_x_ , s_y_ ] = s .getXY();
25- t_warn = Threshold(' warn' , ' Name' , ' warn' , ' Direction' , ' upper' );
26- t_warn .addCondition(struct(), 10 );
27- s .addThreshold(t_warn );
28- cfg .addTag(s );
29- testCase .verifyEqual(numel(cfg .Sensors ), 1 , ' addSensor: count' );
30- testCase .verifyEqual(numel(cfg .SensorData ), 1 , ' addSensor: data count' );
31- testCase .verifyEqual(cfg .SensorData(1 ).name, ' Temperature' , ' addSensor: data name' );
32- testCase .verifyEqual(cfg .SensorData(1 ).t, s_x_ , ' addSensor: data t' );
33- testCase .verifyEqual(cfg .SensorData(1 ).y, s_y_ , ' addSensor: data y' );
34- end
35-
3630 function testSetColor(testCase )
3731 cfg = EventConfig();
3832 cfg .setColor(' warn' , [1 0 0 ]);
@@ -50,99 +44,5 @@ function testBuildDetector(testCase)
5044 testCase .verifyEqual(det .MaxCallsPerEvent , 3 , ' buildDetector: MaxCallsPerEvent' );
5145 testCase .verifyNotEmpty(det .OnEventStart , ' buildDetector: OnEventStart' );
5246 end
53-
54- function testRunDetection(testCase )
55- cfg = EventConfig();
56- s = SensorTag(' temp' , ' Name' , ' Temperature' );
57- s .updateData(1 : 10 , [5 5 12 14 11 13 5 5 5 5 ]);
58- t_warn = Threshold(' warn' , ' Name' , ' warn' , ' Direction' , ' upper' );
59- t_warn .addCondition(struct(), 10 );
60- s .addThreshold(t_warn );
61- cfg .addTag(s );
62- events = cfg .runDetection();
63- testCase .verifyGreaterThanOrEqual(numel(events ), 1 , ' runDetection: found events' );
64- testCase .verifyEqual(events(1 ).SensorName, ' Temperature' , ' runDetection: sensor name' );
65- end
66-
67- function testEscalateSeverity(testCase )
68- cfg = EventConfig();
69- s = SensorTag(' temp' , ' Name' , ' Temperature' );
70- s .updateData(1 : 10 , [5 5 86 96 88 87 5 5 5 5 ]);
71- t_warn = Threshold(' warn' , ' Name' , ' warn' , ' Direction' , ' upper' );
72- t_warn .addCondition(struct(), 85 );
73- s .addThreshold(t_warn );
74- t_critical = Threshold(' critical' , ' Name' , ' critical' , ' Direction' , ' upper' );
75- t_critical .addCondition(struct(), 95 );
76- s .addThreshold(t_critical );
77- cfg .addTag(s );
78- events = cfg .runDetection();
79- critEvents = events(arrayfun(@(e ) strcmp(e .ThresholdLabel , ' critical' ), events ));
80- testCase .verifyGreaterThanOrEqual(numel(critEvents ), 1 , ' escalate: critical event exists' );
81- testCase .verifyGreaterThanOrEqual(critEvents(1 ).PeakValue, 95 , ' escalate: peak above critical threshold' );
82- end
83-
84- function testEscalateDisabled(testCase )
85- cfg2 = EventConfig();
86- cfg2.EscalateSeverity = false ;
87- s2 = SensorTag(' temp' , ' Name' , ' Temperature' );
88- s2 .updateData(1 : 10 , [5 5 86 96 88 87 5 5 5 5 ]);
89- t_warn = Threshold(' warn' , ' Name' , ' warn' , ' Direction' , ' upper' );
90- t_warn .addCondition(struct(), 85 );
91- s2 .addThreshold(t_warn );
92- t_critical = Threshold(' critical' , ' Name' , ' critical' , ' Direction' , ' upper' );
93- t_critical .addCondition(struct(), 95 );
94- s2 .addThreshold(t_critical );
95- cfg2 .addTag(s2 );
96- events2 = cfg2 .runDetection();
97- warnEvents2 = events2(arrayfun(@(e ) strcmp(e .ThresholdLabel , ' warn' ), events2 ));
98- testCase .verifyGreaterThanOrEqual(numel(warnEvents2 ), 1 , ' escalate disabled: warn event preserved' );
99- end
100-
101- function testEscalateLowDirection(testCase )
102- cfg3 = EventConfig();
103- s3 = SensorTag(' pres' , ' Name' , ' Pressure' );
104- s3 .updateData(1 : 10 , [6 6 3.5 1.5 3.8 3.9 6 6 6 6 ]);
105- t_low = Threshold(' low' , ' Name' , ' low' , ' Direction' , ' lower' );
106- t_low .addCondition(struct(), 4 );
107- s3 .addThreshold(t_low );
108- t_crit_low = Threshold(' critical_low' , ' Name' , ' critical low' , ' Direction' , ' lower' );
109- t_crit_low .addCondition(struct(), 2 );
110- s3 .addThreshold(t_crit_low );
111- cfg3 .addTag(s3 );
112- events3 = cfg3 .runDetection();
113- critLow = events3(arrayfun(@(e ) strcmp(e .ThresholdLabel , ' critical low' ), events3 ));
114- testCase .verifyGreaterThanOrEqual(numel(critLow ), 1 , ' escalate low: critical low event exists' );
115- testCase .verifyLessThanOrEqual(critLow(1 ).PeakValue, 2 , ' escalate low: peak below critical threshold' );
116- end
117-
118- function testSaveViaEventStore(testCase )
119- tmpFile = fullfile(tempdir , ' test_cfg_store_save.mat' );
120- if exist(tmpFile , ' file' ); delete(tmpFile ); end
121- testCase .addTeardown(@() TestEventConfig .deleteIfExists(tmpFile ));
122- cfg = EventConfig();
123- cfg.EventFile = tmpFile ;
124- cfg.MaxBackups = 0 ;
125- s = SensorTag(' temp' , ' Name' , ' Temperature' );
126- s .updateData(1 : 10 , [5 5 12 14 11 13 5 5 5 5 ]);
127- t_warn = Threshold(' warn' , ' Name' , ' warn' , ' Direction' , ' upper' );
128- t_warn .addCondition(struct(), 10 );
129- s .addThreshold(t_warn );
130- cfg .setColor(' warn' , [1 0 0 ]);
131- cfg .addTag(s );
132- events = cfg .runDetection();
133- testCase .verifyEqual(exist(tmpFile , ' file' ), 2 , ' save: file exists' );
134- data = load(tmpFile );
135- testCase .verifyTrue(isfield(data , ' events' ), ' save: has events' );
136- testCase .verifyTrue(isfield(data , ' sensorData' ), ' save: has sensorData' );
137- testCase .verifyTrue(isfield(data , ' thresholdColors' ), ' save: has thresholdColors' );
138- testCase .verifyTrue(isfield(data , ' timestamp' ), ' save: has timestamp' );
139- testCase .verifyEqual(numel(data .events ), numel(events ), ' save: event count matches' );
140- end
141- end
142-
143- methods (Static , Access = private )
144- function deleteIfExists(f )
145- if exist(f , ' file' ); delete(f ); end
146- end
14747 end
14848end
0 commit comments