You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
80 lines
2.7 KiB
80 lines
2.7 KiB
package com.jotuntech.sketcher.tests;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.DataOutputStream;
|
|
import java.io.IOException;
|
|
|
|
import com.jotuntech.sketcher.client.PackBitsOutputStream;
|
|
|
|
|
|
public class PackBitsTest {
|
|
public static void main(String[] args) {
|
|
int x = 120;
|
|
x &= 0x1FF;
|
|
byte a = (byte) (x >>> 8);
|
|
byte b = (byte) x;
|
|
int y = ((a & 0xFF) << 8) | (b & 0xFF);
|
|
|
|
System.out.println(y);
|
|
|
|
byte[] testData = new byte[] {
|
|
1, 2, 3, 4, 5, 5, 5, 5, 6, 5, 5, 5, 6, 7, 8, 9,
|
|
1, 2, 3, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 7, 8, 9,
|
|
1, 2, 3, 4, 5, 5, 4, 3, 2, 5, 6, 5, 6, 7, 8, 9,
|
|
1, 2, 3, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 7, 8, 9,
|
|
1, 2, 3, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 7, 8, 9,
|
|
1, 2, 3, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 7, 8, 9,
|
|
1, 2, 3, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 7, 8, 9,
|
|
1, 2, 3, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 7, 8, 9,
|
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
|
9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
|
|
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
|
|
};
|
|
|
|
byte[] expectedOutput = new byte[] {
|
|
3, 1, 2, 3, 4, -3, 5, 0, 6, -2, 5, 7, 6, 7, 8, 9, 1,
|
|
2, 3, 4, -3, 5, 11, 6, 5, 6, 5, 6, 7, 8, 9, 1, 2,
|
|
3, 4, 1, 5, 5, 13, 4, 3, 2, 5, 6, 5, 6, 7, 8, 9,
|
|
1, 2, 3, 4, -3, 5, 11, 6, 5, 6, 5, 6, 7, 8, 9, 1,
|
|
2, 3, 4, -3, 5, 11, 6, 5, 6, 5, 6, 7, 8, 9, 1, 2,
|
|
3, 4, -3, 5, 11, 6, 5, 6, 5, 6, 7, 8, 9, 1, 2, 3,
|
|
4, -3, 5, 11, 6, 5, 6, 5, 6, 7, 8, 9, 1, 2, 3, 4,
|
|
-3, 5, 6, 6, 5, 6, 5, 6, 7, 8, -127, 9, 16, 9, 1, 2,
|
|
3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16
|
|
};
|
|
|
|
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
DataOutputStream dos = new DataOutputStream(baos);
|
|
PackBitsOutputStream pbos = new PackBitsOutputStream(dos);
|
|
try {
|
|
pbos.write(testData);
|
|
pbos.close();
|
|
byte[] output = baos.toByteArray();
|
|
if(output.length != expectedOutput.length) {
|
|
System.err.println("Length of output " + output.length + " does not match expected " + expectedOutput.length + "!");
|
|
return;
|
|
}
|
|
for(int i = 0; i < output.length; i++) {
|
|
System.err.print(output[i] + " ");
|
|
if(output[i] != expectedOutput[i]) {
|
|
System.err.println();
|
|
System.err.println("Output error at index " + i + ": Expected " + expectedOutput[i] + " but got " + output[i] + "!");
|
|
return;
|
|
}
|
|
if(i % 16 == 0 && i > 0) {
|
|
System.err.println();
|
|
}
|
|
}
|
|
System.err.println();
|
|
System.err.println("Test successful!");
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
}
|
|
|