Skip to content

Commit

Permalink
Make TrafficGraphDataTests more general (#1943)
Browse files Browse the repository at this point in the history
  • Loading branch information
UdjinM6 authored Feb 21, 2018
1 parent 43671a3 commit e23f618
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/qt/test/trafficgraphdatatests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,33 +176,38 @@ void TrafficGraphDataTests::clearTests()
void TrafficGraphDataTests::averageBandwidthTest()
{
TrafficGraphData trafficGraphData(TrafficGraphData::Range_5m);
int step = 384;
int step = 123; // in bytes
float rate = step * TrafficGraphData::DESIRED_DATA_SAMPLES / (TrafficGraphData::RangeMinutes[TrafficGraphData::Range_5m] * 60.0f) / 1024.0f; // in KB/s
quint64 totalBytesRecv = 0;
quint64 totalBytesSent = 0;
for (int i = 1; i <= TrafficGraphData::DESIRED_DATA_SAMPLES; i++){
totalBytesRecv += step;
totalBytesSent += step;
trafficGraphData.update(totalBytesRecv, totalBytesSent);
}

// check rate at initial range
QCOMPARE(trafficGraphData.getCurrentRangeQueueWithAverageBandwidth().size(), TrafficGraphData::DESIRED_DATA_SAMPLES);
for (const auto& sample : trafficGraphData.getCurrentRangeQueueWithAverageBandwidth()){
QCOMPARE(sample.in, 1.0f);
QCOMPARE(sample.out, 1.0f);
QCOMPARE(sample.in, rate);
QCOMPARE(sample.out, rate);
}

// rate should be the same regardless of the current range
trafficGraphData.switchRange(TrafficGraphData::Range_10m);

QCOMPARE(trafficGraphData.getCurrentRangeQueueWithAverageBandwidth().size(), TrafficGraphData::DESIRED_DATA_SAMPLES / 2);
for (const auto& sample : trafficGraphData.getCurrentRangeQueueWithAverageBandwidth()){
QCOMPARE(sample.in, 1.0f);
QCOMPARE(sample.out, 1.0f);
QCOMPARE(sample.in, rate);
QCOMPARE(sample.out, rate);
}
}

void TrafficGraphDataTests::averageBandwidthEvery2EmptyTest()
{
TrafficGraphData trafficGraphData(TrafficGraphData::Range_5m);
int step = 384;
int step = 123; // in bytes
float rate = step * TrafficGraphData::DESIRED_DATA_SAMPLES / (TrafficGraphData::RangeMinutes[TrafficGraphData::Range_5m] * 60.0f) / 1024.0f / 2.0f; // in KB/s
quint64 totalBytesRecv = 0;
quint64 totalBytesSent = 0;
for (int i = 1; i <= TrafficGraphData::DESIRED_DATA_SAMPLES; i++){
Expand All @@ -213,11 +218,12 @@ void TrafficGraphDataTests::averageBandwidthEvery2EmptyTest()
trafficGraphData.update(totalBytesRecv, totalBytesSent);
}

// rate should average out at larger range
trafficGraphData.switchRange(TrafficGraphData::Range_10m);

QCOMPARE(trafficGraphData.getCurrentRangeQueueWithAverageBandwidth().size(), TrafficGraphData::DESIRED_DATA_SAMPLES / 2);
for (const auto& sample : trafficGraphData.getCurrentRangeQueueWithAverageBandwidth()){
QCOMPARE(sample.in, 0.5f);
QCOMPARE(sample.out, 0.5f);
QCOMPARE(sample.in, rate);
QCOMPARE(sample.out, rate);
}
}

0 comments on commit e23f618

Please sign in to comment.