text stringlengths 0 2.2M |
|---|
x.getStatistics(&usedUnits, &unusedUnits);
|
ASSERT(0 == usedUnits);
|
ASSERT(0 == unusedUnits);
|
}
|
// C-2
|
if (verbose) cout << endl
|
<< "Testing: statistics calculation"
|
<< endl;
|
{
|
const Uint64 P_RATE = 100000;
|
const Ti P_WND = Ti(0.01);
|
struct {
|
int d_line;
|
Uint64 d_sustRate;
|
Ti d_sustWnd;
|
Uint64 d_units;
|
Ti d_creationTime;
|
Ti d_updateInterval;
|
int d_NumOfUpdates;
|
Uint64 d_expectedUsed;
|
Uint64 d_expectedUnused;
|
} DATA[] = {
|
// LINE S_RT S_WND UNITS TCREATE UPDATE_INT N_UPD USED_U UNUSED_U
|
// ---- ----- ----- ------ ------- ---------- ----- ------ --------
|
{L_, 1000, Ti(1), 1000, Ti( 0), Ti( 0.01), 10, 10000, 0},
|
{L_, 1000, Ti(1), 100, Ti( 0), Ti( 0.5), 5, 500, 2000},
|
{L_, 100, Ti(1), 0, Ti(10), Ti( 0.1), 20, 0, 200}
|
};
|
const int NUM_DATA = sizeof(DATA)/sizeof(*DATA);
|
for (int ti = 0; ti < NUM_DATA; ++ti) {
|
const int LINE = DATA[ti].d_line;
|
const Uint64 S_RATE = DATA[ti].d_sustRate;
|
const Ti S_WND = DATA[ti].d_sustWnd;
|
const Uint64 UNITS = DATA[ti].d_units;
|
const Ti CREATION_TIME = DATA[ti].d_creationTime;
|
const Ti UPDATE_INTERVAL = DATA[ti].d_updateInterval;
|
const int NUM_OF_UPDATES = DATA[ti].d_NumOfUpdates;
|
const Uint64 EXPECTED_USED = DATA[ti].d_expectedUsed;
|
const Uint64 EXPECTED_UNUSED = DATA[ti].d_expectedUnused;
|
Obj x(S_RATE, S_WND, P_RATE, P_WND, CREATION_TIME);
|
Ti currentTime(CREATION_TIME);
|
for(int i = 0; i < NUM_OF_UPDATES; ++i) {
|
currentTime += UPDATE_INTERVAL;
|
x.submit(UNITS);
|
x.updateState(currentTime);
|
}
|
x.getStatistics(&usedUnits, &unusedUnits);
|
LOOP_ASSERT(LINE, EXPECTED_USED == usedUnits);
|
LOOP_ASSERT(LINE, EXPECTED_UNUSED == unusedUnits);
|
}
|
}
|
// C-3
|
if (verbose) cout << endl << "Negative testing" << endl;
|
{
|
bsls::AssertTestHandlerGuard hG;
|
Obj x(1, Ti(10), 1, Ti(10), Ti(0));
|
ASSERT_SAFE_FAIL(x.getStatistics(0,&unusedUnits));
|
ASSERT_SAFE_FAIL(x.getStatistics(&usedUnits,0));
|
ASSERT_SAFE_FAIL(x.getStatistics(0,0));
|
}
|
// C-4
|
if (verbose) cout << endl
|
<< "Testing statistics collection interval"
|
<< endl;
|
{
|
Obj x(1000, Ti(1), 10000, Ti(0.01), Ti(0));
|
x.submit(1000);
|
x.getStatistics(&usedUnits, &unusedUnits);
|
ASSERT(0 == usedUnits);
|
ASSERT(0 == unusedUnits);
|
x.updateState(Ti(0.1));
|
x.getStatistics(&usedUnits, &unusedUnits);
|
ASSERT(1000 == usedUnits);
|
ASSERT(0 == unusedUnits);
|
x.updateState(Ti(10));
|
x.getStatistics(&usedUnits, &unusedUnits);
|
ASSERT(1000 == usedUnits);
|
ASSERT(9000 == unusedUnits);
|
x.resetStatistics();
|
x.updateState(Ti(15));
|
x.getStatistics(&usedUnits, &unusedUnits);
|
ASSERT(0 == usedUnits);
|
ASSERT(5000 == unusedUnits);
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.