CircularShape extends Shape { @Override public void calculate() { ShapeConfig pc = getShapeConfig(); int numberOfItems = pc.getNumberOfElements(); final float centerX = getCenterX(); final float centerY = getCenterY(); float radius = getDistance(); int item = 0; int iteration = 0; while (item < numberOfItems) { int numberOfElementsPerIteration = calculatePositionsForIteration(item, radius, iteration, centerX, centerY); item += numberOfElementsPerIteration; iteration++; } } CircularShape(ShapeConfig shapeConfig); @Override void calculate();  }
@Test public void shouldReturnTheMiddleOfTheViewAsPositionForJustOneElement() { ShapeConfig shapeConfig = givenAShapeConfig(1, ANY_VIEW_WIDTH, ANY_VIEW_HEIGHT, ANY_ITEM_SIZE, ANY_ITEM_MARGIN); shape = getShape(shapeConfig); shape.calculate(); float expectedLeft = (ANY_VIEW_WIDTH / 2) - (ANY_ITEM_SIZE / 2) - (ANY_ITEM_MARGIN / 2); assertEquals(expectedLeft, shape.getXForItemAtPosition(0), DELTA); float expectedTop = (ANY_VIEW_HEIGHT / 2) - (ANY_ITEM_SIZE / 2) - (ANY_ITEM_MARGIN / 2); assertEquals(expectedTop, shape.getYForItemAtPosition(0), DELTA); }
@Test public void shouldPositionElementsFollowingACircle() { ShapeConfig shapeConfig = givenAShapeConfig(5, ANY_VIEW_WIDTH, ANY_VIEW_HEIGHT, ANY_ITEM_SIZE, ANY_ITEM_MARGIN); shape = getShape(shapeConfig); shape.calculate(); float centerX = ANY_VIEW_WIDTH / 2 - ANY_ITEM_SIZE / 2 - ANY_ITEM_MARGIN / 2; float centerY = ANY_VIEW_HEIGHT / 2 - ANY_ITEM_SIZE / 2 - ANY_ITEM_MARGIN / 2; float radius = ANY_ITEM_SIZE + ANY_ITEM_MARGIN; assertElementPositions(0, centerX, centerY, shape); assertElementPositions(1, centerX, centerY + radius, shape); assertElementPositions(2, centerX + radius, centerY, shape); assertElementPositions(3, centerX, centerY - radius, shape); assertElementPositions(4, centerX - radius, centerY, shape); }