package com.peterhi.obsolete;
import static org.junit.Assert.*;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import org.junit.Test;
import com.peterhi.latest.Length;
public class LengthTest {
@Test
public void testToByteArrayAndFromByteArray() throws Exception {
long[] values = new long[] {
0,
1,
Byte.MAX_VALUE - 1,
Byte.MAX_VALUE,
Byte.MAX_VALUE + 1,
Short.MAX_VALUE - 1,
Short.MAX_VALUE,
Short.MAX_VALUE + 1,
Integer.MAX_VALUE - 1,
Integer.MAX_VALUE,
(long )Integer.MAX_VALUE + 1,
(long )Math.pow(2, 62) - 1,
};
for (long value : values) {
Length a = new Length(value);
int[] length = new int[1];
Length b = Length.fromByteArray(a.toByteArray(), 0, length);
assertEquals(a, b);
ByteArrayOutputStream out = new ByteArrayOutputStream();
a.toStream(out);
ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
Length c = Length.fromStream(in, length);
assertEquals(a, c);
}
}
}