| 1 |
package morfologik.stemming; |
| 2 |
|
| 3 |
import java.io.IOException; |
| 4 |
import java.nio.ByteBuffer; |
| 5 |
import java.nio.charset.StandardCharsets; |
| 6 |
|
| 7 |
import org.assertj.core.api.Assertions; |
| 8 |
import org.junit.Test; |
| 9 |
|
| 10 |
import com.carrotsearch.randomizedtesting.RandomizedTest; |
| 11 |
|
| 12 |
public class EncodersTest extends RandomizedTest { |
| 13 |
@Test |
| 14 |
public void testSharedPrefix() throws IOException { |
| 15 |
Assertions.assertThat( |
| 16 |
BufferUtils.sharedPrefixLength( |
| 17 |
ByteBuffer.wrap(b("abcdef")), |
| 18 |
ByteBuffer.wrap(b("abcd__")))) |
| 19 |
.isEqualTo(4); |
| 20 |
|
| 21 |
Assertions.assertThat( |
| 22 |
BufferUtils.sharedPrefixLength( |
| 23 |
ByteBuffer.wrap(b("")), |
| 24 |
ByteBuffer.wrap(b("_")))) |
| 25 |
.isEqualTo(0); |
| 26 |
|
| 27 |
Assertions.assertThat( |
| 28 |
BufferUtils.sharedPrefixLength( |
| 29 |
ByteBuffer.wrap(b( "abcdef"), 2, 2), |
| 30 |
ByteBuffer.wrap(b("___cd__"), 3, 2))) |
| 31 |
.isEqualTo(2); |
| 32 |
} |
| 33 |
|
| 34 |
private static byte[] b(String arg) { |
| 35 |
byte[] bytes = arg.getBytes(StandardCharsets.UTF_8); |
| 36 |
Assertions.assertThat(bytes).hasSize(arg.length()); |
| 37 |
return bytes; |
| 38 |
} |
| 39 |
} |