Warning: session_start(): open(/var/lib/php/sessions/sess_5dcsmcc1249apr5qdp998vrkef, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
sclass Test_CompressToInterpolatedDoubleArray {
settable int maxPillars = 5;
settable int minX =-10, maxX = 10;
settable int maxRunlength = 10;
void zerosTest {
// just compress 10 zeros (should result in 2 pillars)
var data = new int[10];
testCompression(data, 2);
}
void testCompression(int[] data, int maxPillarsAllowed)
var compressed = CompressToInterpolatedDoubleArray(data)!;
printStruct(compressed);
var reconstructed = compressed!;
var reconstructed2 = iroundDoubleArray(reconstructed);
// Test reconstructed array
assertIntArraysEqual(data, reconstructed2);
// Test that we have achieved sufficient compression
assertLessThanOrEqualTo(maxPillarsAllowed, compressed.nPillars());
}
int randomX() { ret random_incl(minX, maxX); }
void actualVectorTest() {
int nPillars = random_incl(2, maxPillars);
new IntBuffer values;
// first pillar
values.add(randomX());
repeat nPillars {
int value = randomX();
int runlength = random_incl(1, maxRunlength);
if (runlength > 1) {
int lastValue = last(values);
double slope = (value-lastValue)/(double) runlength;
double x = lastValue;
for (int i = 1; i < runLength; i++)
values.add(iround(x += slope));
}
values.add(value);
}
int[] data = values.toArrayNonNull();
testCompression(data, nPillars);
}
}