|
7 | 7 |
|
8 | 8 | import static org.testng.Assert.assertEquals; |
9 | 9 | import static org.testng.Assert.assertFalse; |
| 10 | +import static org.testng.Assert.assertNull; |
10 | 11 | import static org.testng.Assert.assertTrue; |
11 | 12 |
|
12 | 13 | import org.testng.annotations.Test; |
@@ -109,27 +110,53 @@ private static void printDiffs(byte[] arr1, byte[] arr2) { |
109 | 110 | } |
110 | 111 |
|
111 | 112 | @Test |
112 | | - public void checkToByteArray() { |
| 113 | + public void checkCouponToByteArray() { |
113 | 114 | int lgK = 8; |
114 | 115 | TgtHllType type = TgtHllType.HLL_8; |
115 | 116 | int bytes = HllSketch.getMaxUpdatableSerializationBytes(lgK, type); |
116 | 117 | WritableMemory wmem = WritableMemory.allocate(bytes); |
117 | 118 | HllSketch sk = new HllSketch(lgK, type, wmem); |
118 | | - for (int i = 0; i < 7; i++) { sk.update(i); } |
| 119 | + int i; |
| 120 | + for (i = 0; i < 7; i++) { sk.update(i); } //LIST |
119 | 121 |
|
120 | 122 | //toCompactMemArr from compact mem |
121 | 123 | byte[] compactByteArr = sk.toCompactByteArray(); |
122 | 124 | Memory compactMem = Memory.wrap(compactByteArr); |
123 | | - HllSketch sk2 = HllSketch.wrap(compactMem); |
124 | | - byte[] compactByteArr2 = sk2.toCompactByteArray(); |
| 125 | + HllSketch skCompact = HllSketch.wrap(compactMem); |
| 126 | + byte[] compactByteArr2 = skCompact.toCompactByteArray(); |
125 | 127 | assertEquals(compactByteArr2, compactByteArr); |
126 | 128 |
|
127 | 129 | //now check to UpdatableByteArr from compact mem |
128 | 130 | byte[] updatableByteArr = sk.toUpdatableByteArray(); |
129 | | - byte[] updatableByteArr2 = sk2.toUpdatableByteArray(); |
| 131 | + byte[] updatableByteArr2 = skCompact.toUpdatableByteArray(); |
130 | 132 | assertEquals(updatableByteArr2.length, updatableByteArr.length); |
131 | | - assertEquals(sk2.getEstimate(), sk.getEstimate()); |
| 133 | + assertEquals(skCompact.getEstimate(), sk.getEstimate()); |
132 | 134 |
|
| 135 | + |
| 136 | + sk.update(i); //SET |
| 137 | + //toCompactMemArr from compact mem |
| 138 | + compactByteArr = sk.toCompactByteArray(); |
| 139 | + compactMem = Memory.wrap(compactByteArr); |
| 140 | + skCompact = HllSketch.wrap(compactMem); |
| 141 | + compactByteArr2 = skCompact.toCompactByteArray(); |
| 142 | + assertEquals(compactByteArr2, compactByteArr); |
| 143 | + |
| 144 | + //now check to UpdatableByteArr from compact mem |
| 145 | + updatableByteArr = sk.toUpdatableByteArray(); |
| 146 | + updatableByteArr2 = skCompact.toUpdatableByteArray(); |
| 147 | + assertEquals(updatableByteArr2.length, updatableByteArr.length); |
| 148 | + assertEquals(skCompact.getEstimate(), sk.getEstimate()); |
| 149 | + } |
| 150 | + |
| 151 | + @Test |
| 152 | + public void checkDirectGetCouponIntArr() { |
| 153 | + int lgK = 8; |
| 154 | + TgtHllType type = TgtHllType.HLL_8; |
| 155 | + int bytes = HllSketch.getMaxUpdatableSerializationBytes(lgK, type); |
| 156 | + WritableMemory wmem = WritableMemory.allocate(bytes); |
| 157 | + HllSketch sk = new HllSketch(lgK, type, wmem); |
| 158 | + AbstractCoupons absCoup = (AbstractCoupons)sk.hllSketchImpl; |
| 159 | + assertNull(absCoup.getCouponIntArr()); |
133 | 160 | } |
134 | 161 |
|
135 | 162 | @Test |
|
0 commit comments