sclass Test_CompressToInterpolatedDoubleArray { settable int maxPillars = 5; settable int minX =-10, maxX = 10; settable int maxRunlength = 10; settable int nTests = oneMillion(); run { zerosTest(); repeat nTests { actualVectorTest(); } } 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); } }