/**
 * 
 */
package anoncard;

import static org.junit.Assert.*;

import org.junit.Test;

/**
 * @author christoph
 * 
 */
public class ANONShortTest {

	/**
	 * Test method for {@link anoncard.ANONShort#toBytes(short)} and
	 * {@link ANONShort#toShort(byte[])}.
	 */
	@Test
	public void testToBytes() {
		// 1019 is prime
		for (short i = Short.MIN_VALUE; i < Short.MAX_VALUE - 1019; i += 1019) {
			assertEquals(i, ANONShort.toShort(ANONShort.toBytes(i)));
		}
		// 5 too
		for (byte i = Byte.MIN_VALUE; i < 0; i += 5) {
			assertArrayEquals(new byte[] { -1, i }, ANONShort.toBytes(i));
		}
		for (byte i = 0; i < Byte.MAX_VALUE - 5; i += 5) {
			assertArrayEquals(i + "->" + ANONShort.toBytes(i)[0] + " " + ANONShort.toBytes(i)[1], new byte[] { 0, i }, ANONShort.toBytes(i));
		}
	}
}
