1 32 33 package com.jeantessier.classreader; 34 35 import junit.framework.*; 36 37 public class TestBitFormat extends TestCase { 38 public void testDefault() { 39 BitFormat format = new BitFormat(); 40 41 assertEquals("0", "00000000 00000000 00000000 00000000", format.format(0)); 42 assertEquals("1", "00000000 00000000 00000000 00000001", format.format(1)); 43 assertEquals("-1", "11111111 11111111 11111111 11111111", format.format(-1)); 44 assertEquals("20", "00000000 00000000 00000000 00010100", format.format(20)); 45 assertEquals("Byte.MAX_VALUE", "00000000 00000000 00000000 01111111", format.format(Byte.MAX_VALUE)); 46 assertEquals("Byte.MIN_VALUE", "11111111 11111111 11111111 10000000", format.format(Byte.MIN_VALUE)); 47 assertEquals("Short.MAX_VALUE", "00000000 00000000 01111111 11111111", format.format(Short.MAX_VALUE)); 48 assertEquals("Short.MIN_VALUE", "11111111 11111111 10000000 00000000", format.format(Short.MIN_VALUE)); 49 assertEquals("Integer.MAX_VALUE", "01111111 11111111 11111111 11111111", format.format(Integer.MAX_VALUE)); 50 assertEquals("Integer.MIN_VALUE", "10000000 00000000 00000000 00000000", format.format(Integer.MIN_VALUE)); 51 } 52 53 public void testLength4() { 54 BitFormat format = new BitFormat(4); 55 56 assertEquals("0", "0000", format.format(0)); 57 assertEquals("1", "0001", format.format(1)); 58 assertEquals("-1", "1111", format.format(-1)); 59 assertEquals("20", "0100", format.format(20)); 60 assertEquals("Byte.MAX_VALUE", "1111", format.format(Byte.MAX_VALUE)); 61 assertEquals("Byte.MIN_VALUE", "0000", format.format(Byte.MIN_VALUE)); 62 assertEquals("Short.MAX_VALUE", "1111", format.format(Short.MAX_VALUE)); 63 assertEquals("Short.MIN_VALUE", "0000", format.format(Short.MIN_VALUE)); 64 assertEquals("Integer.MAX_VALUE", "1111", format.format(Integer.MAX_VALUE)); 65 assertEquals("Integer.MIN_VALUE", "0000", format.format(Integer.MIN_VALUE)); 66 } 67 68 public void testLength16() { 69 BitFormat format = new BitFormat(16); 70 71 assertEquals("0", "00000000 00000000", format.format(0)); 72 assertEquals("1", "00000000 00000001", format.format(1)); 73 assertEquals("-1", "11111111 11111111", format.format(-1)); 74 assertEquals("20", "00000000 00010100", format.format(20)); 75 assertEquals("Byte.MAX_VALUE", "00000000 01111111", format.format(Byte.MAX_VALUE)); 76 assertEquals("Byte.MIN_VALUE", "11111111 10000000", format.format(Byte.MIN_VALUE)); 77 assertEquals("Short.MAX_VALUE", "01111111 11111111", format.format(Short.MAX_VALUE)); 78 assertEquals("Short.MIN_VALUE", "10000000 00000000", format.format(Short.MIN_VALUE)); 79 assertEquals("Integer.MAX_VALUE", "11111111 11111111", format.format(Integer.MAX_VALUE)); 80 assertEquals("Integer.MIN_VALUE", "00000000 00000000", format.format(Integer.MIN_VALUE)); 81 } 82 83 public void testGroups8() { 84 BitFormat format = new BitFormat(BitFormat.DEFAULT_MAX_LENGTH, 4); 85 86 assertEquals("0", "0000 0000 0000 0000 0000 0000 0000 0000", format.format(0)); 87 assertEquals("1", "0000 0000 0000 0000 0000 0000 0000 0001", format.format(1)); 88 assertEquals("-1", "1111 1111 1111 1111 1111 1111 1111 1111", format.format(-1)); 89 assertEquals("20", "0000 0000 0000 0000 0000 0000 0001 0100", format.format(20)); 90 assertEquals("Byte.MAX_VALUE", "0000 0000 0000 0000 0000 0000 0111 1111", format.format(Byte.MAX_VALUE)); 91 assertEquals("Byte.MIN_VALUE", "1111 1111 1111 1111 1111 1111 1000 0000", format.format(Byte.MIN_VALUE)); 92 assertEquals("Short.MAX_VALUE", "0000 0000 0000 0000 0111 1111 1111 1111", format.format(Short.MAX_VALUE)); 93 assertEquals("Short.MIN_VALUE", "1111 1111 1111 1111 1000 0000 0000 0000", format.format(Short.MIN_VALUE)); 94 assertEquals("Integer.MAX_VALUE", "0111 1111 1111 1111 1111 1111 1111 1111", format.format(Integer.MAX_VALUE)); 95 assertEquals("Integer.MIN_VALUE", "1000 0000 0000 0000 0000 0000 0000 0000", format.format(Integer.MIN_VALUE)); 96 } 97 98 public void testSeparator() { 99 BitFormat format = new BitFormat(BitFormat.DEFAULT_MAX_LENGTH, BitFormat.DEFAULT_GROUP_SIZE, '-'); 100 101 assertEquals("0", "00000000-00000000-00000000-00000000", format.format(0)); 102 assertEquals("1", "00000000-00000000-00000000-00000001", format.format(1)); 103 assertEquals("-1", "11111111-11111111-11111111-11111111", format.format(-1)); 104 assertEquals("20", "00000000-00000000-00000000-00010100", format.format(20)); 105 assertEquals("Byte.MAX_VALUE", "00000000-00000000-00000000-01111111", format.format(Byte.MAX_VALUE)); 106 assertEquals("Byte.MIN_VALUE", "11111111-11111111-11111111-10000000", format.format(Byte.MIN_VALUE)); 107 assertEquals("Short.MAX_VALUE", "00000000-00000000-01111111-11111111", format.format(Short.MAX_VALUE)); 108 assertEquals("Short.MIN_VALUE", "11111111-11111111-10000000-00000000", format.format(Short.MIN_VALUE)); 109 assertEquals("Integer.MAX_VALUE", "01111111-11111111-11111111-11111111", format.format(Integer.MAX_VALUE)); 110 assertEquals("Integer.MIN_VALUE", "10000000-00000000-00000000-00000000", format.format(Integer.MIN_VALUE)); 111 } 112 } 113 | Popular Tags |