SpiralShape extends Shape { @Override public void calculate() { ShapeConfig pc = getShapeConfig(); int numberOfItems = pc.getNumberOfElements(); float centerY = (pc.getViewHeight() / 2) - (pc.getItemSize() / 2) - (pc.getItemMargin() / 2); float centerX = (pc.getViewWidth() / 2) - (pc.getItemSize() / 2) - (pc.getItemMargin() / 2); float angle = pc.getItemSize(); for (int i = 0; i < numberOfItems; i++) { setX(centerX, angle, i); setY(centerY, angle, i); } } SpiralShape(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 shouldConfigureElementsFollowingAnArchimedeanSpiral() { ShapeConfig shapeConfig = givenAShapeConfig(10, ANY_VIEW_WIDTH, ANY_VIEW_HEIGHT, ANY_ITEM_SIZE, ANY_ITEM_MARGIN); shape = getShape(shapeConfig); shape.calculate(); assertElementsConformAnSpiral(shapeConfig); }