AccuracyAggregator implements CombinerAggregator<AccuracyState<L>> { @Override public AccuracyState<L> init(TridentTuple tuple) { Instance<L> instance = (Instance<L>) tuple.getValue(0); L prediction = (L) tuple.getValue(1); L expected = instance.getLabel(); boolean equals = Objects.equals(expected, prediction); AccuracyState<L> state = new AccuracyState<L>(1, equals ? 0 : 1); return state; }  @Override AccuracyState<L> init(TridentTuple tuple); @Override AccuracyState<L> combine(AccuracyState<L> val1, AccuracyState<L> val2); @Override AccuracyState<L> zero();  }
@Test public void should_init_accuracy_with_error() { Boolean label = true; Boolean prediction = false; Instance<Boolean> instance = mock(Instance.class); when(instance.getLabel()).thenReturn(label); TridentTuple tuple = mock(TridentTuple.class); when(tuple.getValue(0)).thenReturn(instance); when(tuple.getValue(1)).thenReturn(prediction); AccuracyState<Boolean> actualState = agrgegator.init(tuple); assertThat(actualState).isEqualTo(new AccuracyState<Boolean>(1, 1)); }
@Test public void should_init_accuracy_without_error() { Boolean label = true; Boolean prediction = true; Instance<Boolean> instance = mock(Instance.class); when(instance.getLabel()).thenReturn(label); TridentTuple tuple = mock(TridentTuple.class); when(tuple.getValue(0)).thenReturn(instance); when(tuple.getValue(1)).thenReturn(prediction); AccuracyState<Boolean> actualState = agrgegator.init(tuple); assertThat(actualState).isEqualTo(new AccuracyState<Boolean>(1, 0)); }