package quiz; import org.junit.Assert; import org.junit.Test; /** * Test case for the Byte class. * * @author Franck van Breugel */ public class ByteTest { /** * Tests the constant MAX_VALUE. */ @Test public void testMaxValue() { Assert.assertEquals(127, Byte.MAX_VALUE); } /** * Tests the constant MIN_VALUE. */ @Test public void testMinValue() { Assert.assertEquals(-128, Byte.MIN_VALUE); } /** * Tests equals method. */ @Test public void testEquals() { for (int b = Byte.MIN_VALUE; b <= Byte.MAX_VALUE; b++) { Byte object = new Byte((byte) b); for (int c = Byte.MIN_VALUE; c <= Byte.MAX_VALUE; c++) { Byte other = new Byte((byte) c); Assert.assertEquals(String.format("Failed for %d and %d;", b, c), b == c, object.equals(other)); } } } /** * Tests hashCode method. */ @Test public void testHashCode() { for (int b = Byte.MIN_VALUE; b <= Byte.MAX_VALUE; b++) { Byte object = new Byte((byte) b); Assert.assertEquals(String.format("Failed for %d;", b), b, object.hashCode()); } } /** * Tests isEven method. */ @Test public void testIsEven() { for (int b = Byte.MIN_VALUE; b <= Byte.MAX_VALUE; b++) { Byte object = new Byte((byte) b); Assert.assertEquals(String.format("Failed for %d;", b), b % 2 == 0, object.isEven()); } } /** * Tests toString method. */ @Test public void testToString() { for (int b = Byte.MIN_VALUE; b <= Byte.MAX_VALUE; b++) { Byte object = new Byte((byte) b); Assert.assertEquals(String.format("Failed for %d;", b), "" + b, object.toString()); } } }