Search in sources :

Example 1 with KorypheBinaryOperator

use of uk.gov.gchq.koryphe.binaryoperator.KorypheBinaryOperator in project Gaffer by gchq.

the class ElementAggregatorTest method shouldAggregateElementUsingKorypheBinaryOperator.

@Test
public void shouldAggregateElementUsingKorypheBinaryOperator() {
    // Given
    final String reference = "reference1";
    final BinaryOperator<Integer> function = new KorypheBinaryOperator<Integer>() {

        @Override
        public Integer _apply(final Integer a, final Integer b) {
            return a + b;
        }
    };
    final ElementAggregator aggregator = new ElementAggregator.Builder().select(reference).execute(function).build();
    final Edge edge1 = new Edge.Builder().property(reference, 1).build();
    final Edge edge2 = new Edge.Builder().property(reference, 2).build();
    // When
    final Element result = aggregator.apply(edge1, edge2);
    // Then
    assertEquals(3, result.getProperty(reference));
}
Also used : Element(uk.gov.gchq.gaffer.data.element.Element) KorypheBinaryOperator(uk.gov.gchq.koryphe.binaryoperator.KorypheBinaryOperator) Edge(uk.gov.gchq.gaffer.data.element.Edge) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)1 Edge (uk.gov.gchq.gaffer.data.element.Edge)1 Element (uk.gov.gchq.gaffer.data.element.Element)1 KorypheBinaryOperator (uk.gov.gchq.koryphe.binaryoperator.KorypheBinaryOperator)1