@@ -176,33 +176,38 @@ void TrafficGraphDataTests::clearTests()
176176void TrafficGraphDataTests::averageBandwidthTest ()
177177{
178178 TrafficGraphData trafficGraphData (TrafficGraphData::Range_5m);
179- int step = 384 ;
179+ int step = 123 ; // in bytes
180+ float rate = step * TrafficGraphData::DESIRED_DATA_SAMPLES / (TrafficGraphData::RangeMinutes[TrafficGraphData::Range_5m] * 60 .0f ) / 1024 .0f ; // in KB/s
180181 quint64 totalBytesRecv = 0 ;
181182 quint64 totalBytesSent = 0 ;
182183 for (int i = 1 ; i <= TrafficGraphData::DESIRED_DATA_SAMPLES; i++){
183184 totalBytesRecv += step;
184185 totalBytesSent += step;
185186 trafficGraphData.update (totalBytesRecv, totalBytesSent);
186187 }
188+
189+ // check rate at initial range
187190 QCOMPARE (trafficGraphData.getCurrentRangeQueueWithAverageBandwidth ().size (), TrafficGraphData::DESIRED_DATA_SAMPLES);
188191 for (const auto & sample : trafficGraphData.getCurrentRangeQueueWithAverageBandwidth ()){
189- QCOMPARE (sample.in , 1 . 0f );
190- QCOMPARE (sample.out , 1 . 0f );
192+ QCOMPARE (sample.in , rate );
193+ QCOMPARE (sample.out , rate );
191194 }
192195
196+ // rate should be the same regardless of the current range
193197 trafficGraphData.switchRange (TrafficGraphData::Range_10m);
194198
195199 QCOMPARE (trafficGraphData.getCurrentRangeQueueWithAverageBandwidth ().size (), TrafficGraphData::DESIRED_DATA_SAMPLES / 2 );
196200 for (const auto & sample : trafficGraphData.getCurrentRangeQueueWithAverageBandwidth ()){
197- QCOMPARE (sample.in , 1 . 0f );
198- QCOMPARE (sample.out , 1 . 0f );
201+ QCOMPARE (sample.in , rate );
202+ QCOMPARE (sample.out , rate );
199203 }
200204}
201205
202206void TrafficGraphDataTests::averageBandwidthEvery2EmptyTest ()
203207{
204208 TrafficGraphData trafficGraphData (TrafficGraphData::Range_5m);
205- int step = 384 ;
209+ int step = 123 ; // in bytes
210+ float rate = step * TrafficGraphData::DESIRED_DATA_SAMPLES / (TrafficGraphData::RangeMinutes[TrafficGraphData::Range_5m] * 60 .0f ) / 1024 .0f / 2 .0f ; // in KB/s
206211 quint64 totalBytesRecv = 0 ;
207212 quint64 totalBytesSent = 0 ;
208213 for (int i = 1 ; i <= TrafficGraphData::DESIRED_DATA_SAMPLES; i++){
@@ -213,11 +218,12 @@ void TrafficGraphDataTests::averageBandwidthEvery2EmptyTest()
213218 trafficGraphData.update (totalBytesRecv, totalBytesSent);
214219 }
215220
221+ // rate should average out at larger range
216222 trafficGraphData.switchRange (TrafficGraphData::Range_10m);
217223
218224 QCOMPARE (trafficGraphData.getCurrentRangeQueueWithAverageBandwidth ().size (), TrafficGraphData::DESIRED_DATA_SAMPLES / 2 );
219225 for (const auto & sample : trafficGraphData.getCurrentRangeQueueWithAverageBandwidth ()){
220- QCOMPARE (sample.in , 0 . 5f );
221- QCOMPARE (sample.out , 0 . 5f );
226+ QCOMPARE (sample.in , rate );
227+ QCOMPARE (sample.out , rate );
222228 }
223229}
0 commit comments