use of com.yahoo.prelude.query.PureWeightedString in project vespa by vespa-engine.
the class ItemEncodingTestCase method testPureWeightedStringEncodingWithNonDefaultWeight.
@Test
public void testPureWeightedStringEncodingWithNonDefaultWeight() {
PureWeightedString a = new PureWeightedString("a", 7);
ByteBuffer buffer = ByteBuffer.allocate(128);
int count = a.encode(buffer);
buffer.flip();
assertEquals("Serialization size", 4, buffer.remaining());
assertEquals("Serialization count", 1, count);
assertType(buffer, 19, 1);
assertWeight(buffer, 7);
assertString(buffer, a.getString());
}
use of com.yahoo.prelude.query.PureWeightedString in project vespa by vespa-engine.
the class ItemEncodingTestCase method testPureWeightedStringEncoding.
@Test
public void testPureWeightedStringEncoding() {
PureWeightedString a = new PureWeightedString("a");
ByteBuffer buffer = ByteBuffer.allocate(128);
int count = a.encode(buffer);
buffer.flip();
assertEquals("Serialization size", 3, buffer.remaining());
assertEquals("Serialization count", 1, count);
assertType(buffer, 19, 0);
assertString(buffer, a.getString());
}
use of com.yahoo.prelude.query.PureWeightedString in project vespa by vespa-engine.
the class WeightedSetItemTestCase method testEncoding.
@Test
public void testEncoding() {
WeightedSetItem item = new WeightedSetItem("index");
// need 2 alternative reference encoding, as the encoding
// order is kept undefined to improve performance.
FakeWSItem ref1 = new FakeWSItem();
FakeWSItem ref2 = new FakeWSItem();
item.addToken("foo", 10);
item.addToken("bar", 20);
ref1.add("foo", 10);
ref1.add("bar", 20);
ref2.add("bar", 20);
ref2.add("foo", 10);
ByteBuffer actual = ByteBuffer.allocate(128);
ByteBuffer expect1 = ByteBuffer.allocate(128);
ByteBuffer expect2 = ByteBuffer.allocate(128);
expect1.put((byte) 15).put((byte) 2);
Item.putString("index", expect1);
new PureWeightedString("foo", 10).encode(expect1);
new PureWeightedString("bar", 20).encode(expect1);
expect2.put((byte) 15).put((byte) 2);
Item.putString("index", expect2);
new PureWeightedString("bar", 20).encode(expect2);
new PureWeightedString("foo", 10).encode(expect2);
assertEquals(3, item.encode(actual));
actual.flip();
expect1.flip();
expect2.flip();
if (actual.equals(expect1)) {
assertFalse(actual.equals(expect2));
} else {
assertTrue(actual.equals(expect2));
}
}
Aggregations