57 assertEquals(0, BinaryPrefix.getFloorLog1024(0)); 58 assertEquals(NOBI, BinaryPrefix.getFloorPrefix(0)); 59 } 60 61 @Test 62 public void testZeroDouble() { 63 assertEquals(0, BinaryPrefix.getFloorLog1024(0.0)); 64 assertEquals(NOBI, BinaryPrefix.getFloorPrefix(0.0)); 65 } 66 67 @Test 68 public void testPositive() { 69 int oldLog1024 = -1; 70 BinaryPrefix oldPrefix = null; 71 int i = 0; 72 for (long val = 1; val != 0; val <<= 1) { 73 int log1024 = BinaryPrefix.getFloorLog1024(val); 74 BinaryPrefix prefix = BinaryPrefix.getFloorPrefix(val); 75 76 if ((i++ % 10) == 0) { 77 assertGreaterThan("For value " + val, oldLog1024, log1024); //$NON-NLS-1$ 78 if (oldPrefix == null) { 79 assertNotNull(prefix); 80 } else { 81 assertGreaterThan(oldPrefix, prefix); 82 } 83 } else { 84 assertEquals("For value " + val, oldLog1024, log1024); //$NON-NLS-1$ 85 assertSame(oldPrefix, prefix); 86 } 87 88 oldLog1024 = log1024; 89 oldPrefix = prefix; 90 } 91 } 92 93 @Test 94 public void testPositiveDouble() { 95 int oldLog1024 = -1; 96 BinaryPrefix oldPrefix = null; 97 int i = 0; 98 for (int powOf2 = 0; powOf2 < 90; powOf2++) { 99 double val = Math.scalb(1.0, powOf2); 100 int log1024 = BinaryPrefix.getFloorLog1024(val); 101 BinaryPrefix prefix = BinaryPrefix.getFloorPrefix(val); 102 103 if ((i++ % 10) == 0) { 104 assertGreaterThan("For value " + val, oldLog1024, log1024); //$NON-NLS-1$ 105 if (oldPrefix == null) { 106 assertNotNull(prefix); 107 } else { 108 assertGreaterThan(oldPrefix, prefix); 109 } 110 } else { 111 assertEquals("For value " + val, oldLog1024, log1024); //$NON-NLS-1$ 112 assertSame(oldPrefix, prefix); 113 } 114 115 oldLog1024 = log1024; 116 oldPrefix = prefix; 117 } 118 } 119 120 @Test 121 public void testNegative() { 122 int oldLog1024 = -1; 123 BinaryPrefix oldPrefix = null; 124 int i = 0; 125 for (long val = -1; val != 0; val <<= 1) { 126 int log1024 = BinaryPrefix.getFloorLog1024(val); 127 BinaryPrefix prefix = BinaryPrefix.getFloorPrefix(val); 128 129 if ((i++ % 10) == 0) { 130 assertGreaterThan("For value " + val, oldLog1024, log1024); //$NON-NLS-1$ 131 if (oldPrefix == null) { 132 assertNotNull(prefix); 133 } else { 134 assertGreaterThan(oldPrefix, prefix); 135 } 136 } else { 137 assertEquals("For value " + val, oldLog1024, log1024); //$NON-NLS-1$ 138 assertSame(oldPrefix, prefix); 139 } 140 141 oldLog1024 = log1024; 142 oldPrefix = prefix; 143 } 144 } 145 146 @Test 147 public void testNegativeDouble() { 148 int oldLog1024 = -1; 149 BinaryPrefix oldPrefix = null; 150 int i = 0; 151 for (int powOf2 = 0; powOf2 < 90; powOf2++) { 152 double val = -Math.scalb(1.0, powOf2); 153 int log1024 = BinaryPrefix.getFloorLog1024(val); 154 BinaryPrefix prefix = BinaryPrefix.getFloorPrefix(val); 155 156 if ((i++ % 10) == 0) { 157 assertGreaterThan("For value " + val, oldLog1024, log1024); //$NON-NLS-1$ 158 if (oldPrefix == null) { 159 assertNotNull(prefix); 160 } else { 161 assertGreaterThan(oldPrefix, prefix); 162 } 163 } else { 164 assertEquals("For value " + val, oldLog1024, log1024); //$NON-NLS-1$ 165 assertSame(oldPrefix, prefix); 166 } 167 168 oldLog1024 = log1024; 169 oldPrefix = prefix; 170 } 171 } 172 173 @Test 174 public void testBinaryLongAlignment() throws Exception { 175 assertAlignmentLog2(0, 1); 176 assertAlignmentLog2(0, 17); 177 assertAlignmentLog2(0, 1027); 178 assertAlignmentLog2(1, 2); 179 assertAlignmentLog2(1, 42); 180 assertAlignmentLog2(1, 1030); 181 assertAlignmentLog2(2, 4); 182 assertAlignmentLog2(3, 8); 183 assertAlignmentLog2(4, 16); 184 assertAlignmentLog2(10, 1024); | 57 assertEquals(0, BinaryPrefix.getFloorLog1024(0)); 58 assertEquals(NOBI, BinaryPrefix.getFloorPrefix(0)); 59 } 60 61 @Test 62 public void testZeroDouble() { 63 assertEquals(0, BinaryPrefix.getFloorLog1024(0.0)); 64 assertEquals(NOBI, BinaryPrefix.getFloorPrefix(0.0)); 65 } 66 67 @Test 68 public void testPositive() { 69 int oldLog1024 = -1; 70 BinaryPrefix oldPrefix = null; 71 int i = 0; 72 for (long val = 1; val != 0; val <<= 1) { 73 int log1024 = BinaryPrefix.getFloorLog1024(val); 74 BinaryPrefix prefix = BinaryPrefix.getFloorPrefix(val); 75 76 if ((i++ % 10) == 0) { 77 assertGreaterThan("For value " + val, oldLog1024, log1024); 78 if (oldPrefix == null) { 79 assertNotNull(prefix); 80 } else { 81 assertGreaterThan(oldPrefix, prefix); 82 } 83 } else { 84 assertEquals("For value " + val, oldLog1024, log1024); 85 assertSame(oldPrefix, prefix); 86 } 87 88 oldLog1024 = log1024; 89 oldPrefix = prefix; 90 } 91 } 92 93 @Test 94 public void testPositiveDouble() { 95 int oldLog1024 = -1; 96 BinaryPrefix oldPrefix = null; 97 int i = 0; 98 for (int powOf2 = 0; powOf2 < 90; powOf2++) { 99 double val = Math.scalb(1.0, powOf2); 100 int log1024 = BinaryPrefix.getFloorLog1024(val); 101 BinaryPrefix prefix = BinaryPrefix.getFloorPrefix(val); 102 103 if ((i++ % 10) == 0) { 104 assertGreaterThan("For value " + val, oldLog1024, log1024); 105 if (oldPrefix == null) { 106 assertNotNull(prefix); 107 } else { 108 assertGreaterThan(oldPrefix, prefix); 109 } 110 } else { 111 assertEquals("For value " + val, oldLog1024, log1024); 112 assertSame(oldPrefix, prefix); 113 } 114 115 oldLog1024 = log1024; 116 oldPrefix = prefix; 117 } 118 } 119 120 @Test 121 public void testNegative() { 122 int oldLog1024 = -1; 123 BinaryPrefix oldPrefix = null; 124 int i = 0; 125 for (long val = -1; val != 0; val <<= 1) { 126 int log1024 = BinaryPrefix.getFloorLog1024(val); 127 BinaryPrefix prefix = BinaryPrefix.getFloorPrefix(val); 128 129 if ((i++ % 10) == 0) { 130 assertGreaterThan("For value " + val, oldLog1024, log1024); 131 if (oldPrefix == null) { 132 assertNotNull(prefix); 133 } else { 134 assertGreaterThan(oldPrefix, prefix); 135 } 136 } else { 137 assertEquals("For value " + val, oldLog1024, log1024); 138 assertSame(oldPrefix, prefix); 139 } 140 141 oldLog1024 = log1024; 142 oldPrefix = prefix; 143 } 144 } 145 146 @Test 147 public void testNegativeDouble() { 148 int oldLog1024 = -1; 149 BinaryPrefix oldPrefix = null; 150 int i = 0; 151 for (int powOf2 = 0; powOf2 < 90; powOf2++) { 152 double val = -Math.scalb(1.0, powOf2); 153 int log1024 = BinaryPrefix.getFloorLog1024(val); 154 BinaryPrefix prefix = BinaryPrefix.getFloorPrefix(val); 155 156 if ((i++ % 10) == 0) { 157 assertGreaterThan("For value " + val, oldLog1024, log1024); 158 if (oldPrefix == null) { 159 assertNotNull(prefix); 160 } else { 161 assertGreaterThan(oldPrefix, prefix); 162 } 163 } else { 164 assertEquals("For value " + val, oldLog1024, log1024); 165 assertSame(oldPrefix, prefix); 166 } 167 168 oldLog1024 = log1024; 169 oldPrefix = prefix; 170 } 171 } 172 173 @Test 174 public void testBinaryLongAlignment() throws Exception { 175 assertAlignmentLog2(0, 1); 176 assertAlignmentLog2(0, 17); 177 assertAlignmentLog2(0, 1027); 178 assertAlignmentLog2(1, 2); 179 assertAlignmentLog2(1, 42); 180 assertAlignmentLog2(1, 1030); 181 assertAlignmentLog2(2, 4); 182 assertAlignmentLog2(3, 8); 183 assertAlignmentLog2(4, 16); 184 assertAlignmentLog2(10, 1024); |