Search in sources :

Example 1 with StringValue

use of com.baidu.hugegraph.computer.core.graph.value.StringValue in project hugegraph-computer by hugegraph.

the class HugeConverterTest method testConvertValue.

@Test
public void testConvertValue() {
    Assert.assertEquals(NullValue.get(), HugeConverter.convertValue(null));
    Assert.assertEquals(new BooleanValue(true), HugeConverter.convertValue(true));
    Assert.assertEquals(new IntValue(1), HugeConverter.convertValue(1));
    Assert.assertEquals(new LongValue(-1L), HugeConverter.convertValue(-1L));
    Assert.assertEquals(new FloatValue(0.999F), HugeConverter.convertValue(0.999F));
    Assert.assertEquals(new DoubleValue(-0.001D), HugeConverter.convertValue(-0.001D));
    Assert.assertEquals(new StringValue("test"), HugeConverter.convertValue("test"));
    ListValue<IntValue> listValue = new ListValue<>(ValueType.INT);
    listValue.add(new IntValue(1));
    listValue.add(new IntValue(2));
    List<Integer> list = ImmutableList.of(1, 2);
    Assert.assertEquals(listValue, HugeConverter.convertValue(list));
    ListValue<ListValue<LongValue>> nestListValue = new ListValue<>(ValueType.LIST_VALUE);
    ListValue<LongValue> subListValue1 = new ListValue<>(ValueType.LONG);
    subListValue1.add(new LongValue(1L));
    subListValue1.add(new LongValue(2L));
    ListValue<LongValue> subListValue2 = new ListValue<>(ValueType.LONG);
    subListValue2.add(new LongValue(3L));
    subListValue2.add(new LongValue(4L));
    nestListValue.add(subListValue1);
    nestListValue.add(subListValue2);
    List<List<Long>> nestList = ImmutableList.of(ImmutableList.of(1L, 2L), ImmutableList.of(3L, 4L));
    Assert.assertEquals(nestListValue, HugeConverter.convertValue(nestList));
    Assert.assertThrows(ComputerException.class, () -> HugeConverter.convertValue(new byte[0]));
}
Also used : ListValue(com.baidu.hugegraph.computer.core.graph.value.ListValue) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) BooleanValue(com.baidu.hugegraph.computer.core.graph.value.BooleanValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) StringValue(com.baidu.hugegraph.computer.core.graph.value.StringValue) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue) Test(org.junit.Test)

Aggregations

BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)1 DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)1 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)1 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)1 ListValue (com.baidu.hugegraph.computer.core.graph.value.ListValue)1 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)1 StringValue (com.baidu.hugegraph.computer.core.graph.value.StringValue)1 ImmutableList (com.google.common.collect.ImmutableList)1 List (java.util.List)1 Test (org.junit.Test)1