Search in sources :

Example 36 with DoubleValue

use of com.baidu.hugegraph.computer.core.graph.value.DoubleValue 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)

Example 37 with DoubleValue

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

the class HugeConverterTest method testConvertProperties.

@Test
public void testConvertProperties() {
    Map<String, Object> rawProperties = new HashMap<>();
    rawProperties.put("null-value", null);
    rawProperties.put("boolean-value", true);
    rawProperties.put("int-value", 1);
    rawProperties.put("long-value", 2L);
    rawProperties.put("float-value", 0.3F);
    rawProperties.put("double-value", 0.4D);
    rawProperties.put("list-value", ImmutableList.of(1, 2));
    Properties properties = graphFactory().createProperties();
    properties.put("null-value", NullValue.get());
    properties.put("boolean-value", new BooleanValue(true));
    properties.put("int-value", new IntValue(1));
    properties.put("long-value", new LongValue(2L));
    properties.put("float-value", new FloatValue(0.3F));
    properties.put("double-value", new DoubleValue(0.4D));
    ListValue<IntValue> listValue = new ListValue<>(ValueType.INT);
    listValue.add(new IntValue(1));
    listValue.add(new IntValue(2));
    properties.put("list-value", listValue);
    Assert.assertEquals(properties, HugeConverter.convertProperties(rawProperties));
}
Also used : HashMap(java.util.HashMap) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) BooleanValue(com.baidu.hugegraph.computer.core.graph.value.BooleanValue) ListValue(com.baidu.hugegraph.computer.core.graph.value.ListValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) FloatValue(com.baidu.hugegraph.computer.core.graph.value.FloatValue) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) IntValue(com.baidu.hugegraph.computer.core.graph.value.IntValue) Test(org.junit.Test)

Example 38 with DoubleValue

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

the class DefaultEdgeTest method testEquals.

@Test
public void testEquals() {
    DefaultEdge edge1 = new DefaultEdge(graphFactory());
    edge1.label("knows");
    edge1.name("2021-06-01");
    edge1.targetId(BytesId.of(1L));
    Properties properties = new DefaultProperties(graphFactory());
    properties.put("p1", new LongValue(1L));
    properties.put("p2", new DoubleValue(2.0D));
    edge1.properties(properties);
    DefaultEdge edge2 = new DefaultEdge(graphFactory(), "knows", "2021-06-01", BytesId.of(1L));
    edge2.properties().put("p1", new LongValue(1L));
    edge2.properties().put("p2", new DoubleValue(2.0D));
    Assert.assertEquals(edge1, edge2);
    Assert.assertNotEquals(edge1, properties);
}
Also used : DefaultProperties(com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) DefaultEdge(com.baidu.hugegraph.computer.core.graph.edge.DefaultEdge) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) DefaultProperties(com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties) Test(org.junit.Test)

Example 39 with DoubleValue

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

the class DefaultEdgeTest method testOverwrite.

@Test
public void testOverwrite() {
    DefaultEdge edge = new DefaultEdge(graphFactory());
    edge.label("knows");
    edge.name("2021-06-01");
    edge.targetId(BytesId.of(1L));
    Properties properties = new DefaultProperties(graphFactory());
    properties.put("p1", new LongValue(1L));
    properties.put("p2", new DoubleValue(2.0D));
    edge.properties(properties);
    Assert.assertEquals("knows", edge.label());
    Assert.assertEquals("2021-06-01", edge.name());
    Assert.assertEquals(BytesId.of(1L), edge.targetId());
    Assert.assertEquals(properties, edge.properties());
}
Also used : DefaultProperties(com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) DefaultEdge(com.baidu.hugegraph.computer.core.graph.edge.DefaultEdge) Properties(com.baidu.hugegraph.computer.core.graph.properties.Properties) DefaultProperties(com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties) Test(org.junit.Test)

Example 40 with DoubleValue

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

the class DefaultPropertiesTest method testReadWrite.

@Test
public void testReadWrite() throws IOException {
    DefaultProperties properties = new DefaultProperties(graphFactory());
    Assert.assertEquals(0, properties.get().size());
    properties.put("p1", new LongValue(1L));
    properties.put("p2", new DoubleValue(2.0D));
    DefaultProperties props2 = new DefaultProperties(graphFactory());
    UnitTestBase.assertEqualAfterWriteAndRead(properties, props2);
}
Also used : DefaultProperties(com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties) DoubleValue(com.baidu.hugegraph.computer.core.graph.value.DoubleValue) LongValue(com.baidu.hugegraph.computer.core.graph.value.LongValue) Test(org.junit.Test)

Aggregations

DoubleValue (com.baidu.hugegraph.computer.core.graph.value.DoubleValue)49 Test (org.junit.Test)28 LongValue (com.baidu.hugegraph.computer.core.graph.value.LongValue)21 IntValue (com.baidu.hugegraph.computer.core.graph.value.IntValue)14 Vertex (com.baidu.hugegraph.computer.core.graph.vertex.Vertex)13 FloatValue (com.baidu.hugegraph.computer.core.graph.value.FloatValue)12 Id (com.baidu.hugegraph.computer.core.graph.id.Id)10 GraphFactory (com.baidu.hugegraph.computer.core.graph.GraphFactory)8 DefaultProperties (com.baidu.hugegraph.computer.core.graph.properties.DefaultProperties)7 BytesId (com.baidu.hugegraph.computer.core.graph.id.BytesId)6 Properties (com.baidu.hugegraph.computer.core.graph.properties.Properties)5 BooleanValue (com.baidu.hugegraph.computer.core.graph.value.BooleanValue)4 Edge (com.baidu.hugegraph.computer.core.graph.edge.Edge)3 Value (com.baidu.hugegraph.computer.core.graph.value.Value)3 ComputerContext (com.baidu.hugegraph.computer.core.common.ComputerContext)2 DefaultEdge (com.baidu.hugegraph.computer.core.graph.edge.DefaultEdge)2 IdList (com.baidu.hugegraph.computer.core.graph.value.IdList)2 IdListList (com.baidu.hugegraph.computer.core.graph.value.IdListList)2 ListValue (com.baidu.hugegraph.computer.core.graph.value.ListValue)2 File (java.io.File)2