Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make TrafficGraphDataTests more general #1943

Merged
merged 1 commit into from
Feb 21, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}