Skip to content

Commit e6a863f

Browse files
committed
Add Guava comparators to further verify project's comparators (#7)
1 parent d268660 commit e6a863f

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,12 @@
101101
<version>4.1.13.Final</version>
102102
<scope>test</scope>
103103
</dependency>
104+
<dependency>
105+
<groupId>com.google.guava</groupId>
106+
<artifactId>guava</artifactId>
107+
<version>22.0</version>
108+
<scope>test</scope>
109+
</dependency>
104110
<dependency>
105111
<groupId>org.lmdbjava</groupId>
106112
<artifactId>lmdbjava-native-linux-x86_64</artifactId>

src/test/java/org/lmdbjava/ComparatorTest.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020

2121
package org.lmdbjava;
2222

23+
import com.google.common.primitives.SignedBytes;
24+
import com.google.common.primitives.UnsignedBytes;
2325
import io.netty.buffer.ByteBuf;
2426
import static io.netty.buffer.PooledByteBufAllocator.DEFAULT;
2527
import java.nio.ByteBuffer;
2628
import static java.nio.charset.StandardCharsets.US_ASCII;
29+
import java.util.Comparator;
2730
import org.agrona.DirectBuffer;
2831
import org.agrona.concurrent.UnsafeBuffer;
2932
import static org.hamcrest.core.Is.is;
@@ -72,7 +75,9 @@ public static Object[] data() {
7275
final ComparatorRunner ba = new ByteArrayRunner();
7376
final ComparatorRunner bb = new ByteBufferRunner();
7477
final ComparatorRunner netty = new NettyRunner();
75-
return new Object[]{string, db, ba, bb, netty};
78+
final ComparatorRunner gub = new GuavaUnsignedBytes();
79+
final ComparatorRunner gsb = new GuavaSignedBytes();
80+
return new Object[]{string, db, ba, bb, netty, gub, gsb};
7681
}
7782

7883
private static byte[] buffer(final int... bytes) {
@@ -168,6 +173,30 @@ public int compare(final byte[] o1, final byte[] o2) {
168173
}
169174
}
170175

176+
/**
177+
* Tests using Guava's {@link SignedBytes} comparator.
178+
*/
179+
private static class GuavaSignedBytes implements ComparatorRunner {
180+
181+
@Override
182+
public int compare(final byte[] o1, final byte[] o2) {
183+
final Comparator<byte[]> c = SignedBytes.lexicographicalComparator();
184+
return c.compare(o1, o2);
185+
}
186+
}
187+
188+
/**
189+
* Tests using Guava's {@link UnsignedBytes} comparator.
190+
*/
191+
private static class GuavaUnsignedBytes implements ComparatorRunner {
192+
193+
@Override
194+
public int compare(final byte[] o1, final byte[] o2) {
195+
final Comparator<byte[]> c = UnsignedBytes.lexicographicalComparator();
196+
return c.compare(o1, o2);
197+
}
198+
}
199+
171200
/**
172201
* Tests {@link ByteBufProxy}.
173202
*/

0 commit comments

Comments
 (0)