Skip to content

Commit 1354f59

Browse files
committed
more tests
1 parent 037ddb4 commit 1354f59

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

src/main/java/com/trivago/fastutilconcurrentwrapper/util/JBytes.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ public static byte[] concatOrSame (byte @Nullable [] a, byte @Nullable [] b) {
148148
System.arraycopy(b,0, c,len1, len2);
149149
return c;
150150
}
151-
/** @see #concatOrSame */
151+
152+
/** Similar to {@link #concatOrSame}, but if only one array is not empty → returns cloned array */
152153
public static byte[] concatClone (byte @Nullable [] a, byte @Nullable [] b) {
153154
int len1;
154155
if (a == null || (len1 = a.length) <= 0){
@@ -167,6 +168,7 @@ public static byte[] concatClone (byte @Nullable [] a, byte @Nullable [] b) {
167168
return c;
168169
}
169170

171+
/** Concat multiple byte arrays */
170172
public static byte[] concatMulti (byte @Nullable [] @Nullable ... byteArrays) {
171173
if (CFUtil.blankVarargs(byteArrays))
172174
return EMPTY_ARRAY;
@@ -207,6 +209,7 @@ public static long bytesToLong (byte[] bytes) {
207209
* All methods in this class will throw an {@linkplain NullPointerException} if {@code null} is
208210
* passed in as a method parameter for a byte array.
209211
* @see java.io.DataOutputStream
212+
* @see java.io.DataInputStream
210213
* @see jdk.internal.util.ByteArray
211214
* @see jdk.internal.util.ByteArrayLittleEndian
212215
*/

src/test/java/com/trivago/fastutilconcurrentwrapper/intkey/PrimitiveConcurrentMapTest.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,10 @@ void _hashLong () {
4848
void longsAreSame () {
4949
long total = 0, t = System.nanoTime();
5050
for (long i = Integer.MIN_VALUE; i <= Integer.MAX_VALUE; i++){
51-
assertEquals(CFUtil.bucket(Long.valueOf(i), 4_000_000), CFUtil.bucket(i, 4_000_000));
52-
assertEquals(CFUtil.bucket((int)i, 4_000_000), CFUtil.bucket(i, 4_000_000));
51+
int hc = CFUtil.bucket(i, 4_000_000);
52+
assertEquals(CFUtil.bucket(Long.valueOf(i), 4_000_000), hc);
53+
assertEquals(CFUtil.bucket((int)i, 4_000_000), hc);
54+
assertTrue(hc >= 0 && hc < 4_000_000);
5355
total++;
5456
}
5557
t = System.nanoTime() - t;
@@ -65,13 +67,22 @@ void longsAreSame () {
6567
var r = ThreadLocalRandom.current();
6668
for (int z = 0; z < 4_000_000; z++){
6769
long i = r.nextLong();
68-
assertEquals(CFUtil.bucket(Long.valueOf(i), 4_000_000), CFUtil.bucket(i, 4_000_000));
70+
int hc = CFUtil.bucket(i, 4_000_000);
71+
assertEquals(CFUtil.bucket(Long.valueOf(i), 4_000_000), hc);
72+
assertTrue(hc >= 0 && hc < 4_000_000);
73+
6974
i = Long.MIN_VALUE + z;
70-
assertEquals(CFUtil.bucket(Long.valueOf(i), 4_000_000), CFUtil.bucket(i, 4_000_000));
71-
assertEquals(CFUtil.bucket(Long.hashCode(i), 4_000_000), CFUtil.bucket(i, 4_000_000));
75+
hc = CFUtil.bucket(i, 4_000_000);
76+
assertEquals(CFUtil.bucket(Long.valueOf(i), 4_000_000), hc);
77+
assertEquals(CFUtil.bucket(Long.hashCode(i), 4_000_000), hc);
78+
assertTrue(hc >= 0 && hc < 4_000_000);
79+
7280
i = Long.MAX_VALUE - z;
73-
assertEquals(CFUtil.bucket(Long.valueOf(i), 4_000_000), CFUtil.bucket(i, 4_000_000));
74-
assertEquals(CFUtil.bucket(Long.hashCode(i), 4_000_000), CFUtil.bucket(i, 4_000_000));
81+
hc = CFUtil.bucket(i, Integer.MAX_VALUE);
82+
assertEquals(CFUtil.bucket(Long.valueOf(i), Integer.MAX_VALUE), hc);
83+
assertEquals(CFUtil.bucket(Long.hashCode(i), Integer.MAX_VALUE), hc);
84+
assertTrue(hc >= 0 && hc < Integer.MAX_VALUE);
85+
7586
total++;
7687
}
7788
assertEquals(4_000_000, total);

0 commit comments

Comments
 (0)