### Question:
WMAIndicator extends CachedIndicator<Num> { @Override protected Num calculate(int index) { if (index == 0) { return indicator.getValue(0); } Num value = numOf(0); if (index - barCount < 0) { for (int i = index + 1; i > 0; i--) { value = value.plus(numOf(i).multipliedBy(indicator.getValue(i - 1))); } return value.dividedBy(numOf(((index + 1) * (index + 2)) / 2)); } int actualIndex = index; for (int i = barCount; i > 0; i--) { value = value.plus(numOf(i).multipliedBy(indicator.getValue(actualIndex))); actualIndex--; } return value.dividedBy(numOf((barCount * (barCount + 1)) / 2)); } WMAIndicator(Indicator<Num> indicator, int barCount); @Override String toString();  }### Answer:
@Test public void calculate() { MockBarSeries series = new MockBarSeries(numFunction, 1d, 2d, 3d, 4d, 5d, 6d); Indicator<Num> close = new ClosePriceIndicator(series); Indicator<Num> wmaIndicator = new WMAIndicator(close, 3); assertNumEquals(1, wmaIndicator.getValue(0)); assertNumEquals(1.6667, wmaIndicator.getValue(1)); assertNumEquals(2.3333, wmaIndicator.getValue(2)); assertNumEquals(3.3333, wmaIndicator.getValue(3)); assertNumEquals(4.3333, wmaIndicator.getValue(4)); assertNumEquals(5.3333, wmaIndicator.getValue(5)); }