MarginaliaSearch/code/libraries/coded-sequence/test/nu/marginalia/sequence/SequenceOperationsTest.java
Viktor Lofgren 36160988e2 (index) Integrate positions data with indexes WIP
This change integrates the new positions data with the forward and reverse indexes.

The ranking code is still only partially re-written.
2024-06-10 15:09:06 +02:00

75 lines
2.7 KiB
Java

package nu.marginalia.sequence;
import it.unimi.dsi.fastutil.ints.IntIterator;
import org.junit.jupiter.api.Test;
import java.nio.ByteBuffer;
import static org.junit.jupiter.api.Assertions.*;
class SequenceOperationsTest {
@Test
void intersectSequencesSingle() {
ByteBuffer wa = ByteBuffer.allocate(1024);
GammaCodedSequence seq1 = GammaCodedSequence.generate(wa, 1);
assertTrue(SequenceOperations.intersectSequences(seq1.iterator()));
}
@Test
void intersectSequencesTrivialMatch() {
ByteBuffer wa = ByteBuffer.allocate(1024);
GammaCodedSequence seq1 = GammaCodedSequence.generate(wa, 1);
GammaCodedSequence seq2 = GammaCodedSequence.generate(wa, 1);
assertTrue(SequenceOperations.intersectSequences(seq1.iterator(), seq2.iterator()));
}
@Test
void intersectSequencesTrivialMismatch() {
ByteBuffer wa = ByteBuffer.allocate(1024);
GammaCodedSequence seq1 = GammaCodedSequence.generate(wa, 1);
GammaCodedSequence seq2 = GammaCodedSequence.generate(wa, 2);
assertFalse(SequenceOperations.intersectSequences(seq1.iterator(), seq2.iterator()));
}
@Test
void intersectSequencesOffsetMatch() {
ByteBuffer wa = ByteBuffer.allocate(1024);
GammaCodedSequence seq1 = GammaCodedSequence.generate(wa, 1);
GammaCodedSequence seq2 = GammaCodedSequence.generate(wa, 3);
assertTrue(SequenceOperations.intersectSequences(seq1.offsetIterator(0), seq2.offsetIterator(-2)));
}
@Test
void intersectSequencesDeepMatch() {
ByteBuffer wa = ByteBuffer.allocate(1024);
GammaCodedSequence seq1 = GammaCodedSequence.generate(wa, 1, 3, 4, 7, 8, 9, 11);
GammaCodedSequence seq2 = GammaCodedSequence.generate(wa, 2, 5, 8, 14);
assertTrue(SequenceOperations.intersectSequences(seq1.iterator(), seq2.iterator()));
}
@Test
void intersectSequencesDeepMatch3() {
ByteBuffer wa = ByteBuffer.allocate(1024);
GammaCodedSequence seq1 = GammaCodedSequence.generate(wa, 1, 3, 4, 7, 8, 9, 11);
GammaCodedSequence seq2 = GammaCodedSequence.generate(wa, 2, 5, 8, 14);
GammaCodedSequence seq3 = GammaCodedSequence.generate(wa, 1, 5, 8, 9);
assertTrue(SequenceOperations.intersectSequences(seq1.iterator(), seq2.iterator(), seq3.iterator()));
}
@Test
void intersectSequencesDeepMismatch() {
ByteBuffer wa = ByteBuffer.allocate(1024);
GammaCodedSequence seq1 = GammaCodedSequence.generate(wa, 1, 3, 4, 7, 8, 9, 11);
GammaCodedSequence seq2 = GammaCodedSequence.generate(wa, 2, 5, 14);
assertFalse(SequenceOperations.intersectSequences(seq1.iterator(), seq2.iterator()));
}
}