use of com.baidu.hugegraph.computer.core.graph.value.LongValue in project hugegraph-computer by hugegraph.
the class ValueMinCombinerTest method testCombine.
@Test
public void testCombine() {
LongValue min = new LongValue(0L);
ValueMinCombiner<LongValue> combiner = new ValueMinCombiner<>();
LongValue value1 = new LongValue(1L);
combiner.combine(min, value1, min);
LongValue value2 = new LongValue(2L);
combiner.combine(value2, min, min);
Assert.assertEquals(new LongValue(0L), min);
}
use of com.baidu.hugegraph.computer.core.graph.value.LongValue in project hugegraph-computer by hugegraph.
the class ValueMinCombinerTest method testCombineNull.
@Test
public void testCombineNull() {
LongValue value1 = new LongValue(1L);
LongValue value2 = new LongValue(2L);
ValueMinCombiner<LongValue> combiner = new ValueMinCombiner<>();
Assert.assertThrows(IllegalArgumentException.class, () -> {
combiner.combine(null, value2, value2);
}, e -> {
Assert.assertEquals("The combine parameter v1 can't be null", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
combiner.combine(value1, null, value1);
}, e -> {
Assert.assertEquals("The combine parameter v2 can't be null", e.getMessage());
});
}
use of com.baidu.hugegraph.computer.core.graph.value.LongValue in project hugegraph-computer by hugegraph.
the class MockMasterComputation method assertStep0Aggregators.
protected void assertStep0Aggregators(MasterComputationContext context) {
Assert.assertEquals(new IntValue(5), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_INT));
Assert.assertEquals(new FloatValue(5.2f), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_FLOAT));
Assert.assertEquals(new FloatValue(3.14f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_UNSTABLE));
Assert.assertEquals(new IntValue(10), context.aggregatedValue(MockMasterComputation.AGGR_INT_UNSTABLE));
Assert.assertEquals(new IntValue(5), context.aggregatedValue(MockMasterComputation.AGGR_INT_SUM));
Assert.assertEquals(new IntValue(8), context.aggregatedValue(MockMasterComputation.AGGR_INT_MAX));
Assert.assertEquals(new LongValue(5L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_SUM));
Assert.assertEquals(new LongValue(8L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_MAX));
Assert.assertEquals(new FloatValue(10.4f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_SUM));
Assert.assertEquals(new FloatValue(-10.0f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_MIN));
Assert.assertEquals(new DoubleValue(10.4), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_SUM));
Assert.assertEquals(new DoubleValue(-10.0), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_MIN));
}
use of com.baidu.hugegraph.computer.core.graph.value.LongValue in project hugegraph-computer by hugegraph.
the class MockMasterComputation method assertAggregatedValueWithError.
private void assertAggregatedValueWithError(MasterComputationContext context) {
Assert.assertThrows(IllegalArgumentException.class, () -> {
context.aggregatedValue(MockMasterComputation.AGGR_INT_SUM, new LongValue(7L));
}, e -> {
Assert.assertContains("Can't set long value '7' to int aggregator", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
context.aggregatedValue(MockMasterComputation.AGGR_LONG_SUM, new IntValue(7));
}, e -> {
Assert.assertContains("Can't set int value '7' to long aggregator", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_SUM, new FloatValue(7f));
}, e -> {
Assert.assertContains("Can't set float value '7.0' to double ", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_MIN, null);
}, e -> {
Assert.assertContains("Can't set value to null for aggregator " + "'aggr_double_min'", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_INT, null);
}, e -> {
Assert.assertContains("Can't set value to null for aggregator " + "'aggr_int'", e.getMessage());
});
Assert.assertThrows(ClassCastException.class, () -> {
context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_FLOAT, new IntValue(7));
}, e -> {
Assert.assertContains("IntValue cannot be cast to", e.getMessage());
Assert.assertContains("FloatValue", e.getMessage());
});
}
use of com.baidu.hugegraph.computer.core.graph.value.LongValue in project hugegraph-computer by hugegraph.
the class MockMasterComputation method assertStep1Aggregators.
protected void assertStep1Aggregators(MasterComputationContext context) {
Assert.assertEquals(new IntValue(5), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_INT));
Assert.assertEquals(new FloatValue(5.2f), context.aggregatedValue(MockMasterComputation.AGGR_CUSTOM_FLOAT));
Assert.assertEquals(new FloatValue(3.14f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_UNSTABLE));
Assert.assertEquals(new IntValue(9), context.aggregatedValue(MockMasterComputation.AGGR_INT_UNSTABLE));
Assert.assertEquals(new IntValue(5), context.aggregatedValue(MockMasterComputation.AGGR_INT_SUM));
Assert.assertEquals(new IntValue(8), context.aggregatedValue(MockMasterComputation.AGGR_INT_MAX));
Assert.assertEquals(new LongValue(5L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_SUM));
Assert.assertEquals(new LongValue(8L), context.aggregatedValue(MockMasterComputation.AGGR_LONG_MAX));
Assert.assertEquals(new FloatValue(10.4f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_SUM));
Assert.assertEquals(new FloatValue(-10.0f), context.aggregatedValue(MockMasterComputation.AGGR_FLOAT_MIN));
Assert.assertEquals(new DoubleValue(10.4), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_SUM));
Assert.assertEquals(new DoubleValue(-10.0), context.aggregatedValue(MockMasterComputation.AGGR_DOUBLE_MIN));
}
Aggregations