RandomPointFactory { public Point getVChallengePointWrtPercentageSizeOfReferenceFont(Rectangle rectangle, Point referencePoint, Font referenceFont, Font nextFont) { if (referencePoint.getX() < 0 || referencePoint.getY() < 0) { throw new IllegalArgumentException("Either X or Y coordinate is negative "); } int xVariation = (GlobalConstants.CHALLENGE_DELTA_PERCENTAGE * referenceFont.getSize()) / 100; int xOffset = rand.nextInt(xVariation + 1) * (rand.nextBoolean() ? 1 : -1); int yOffset = rand.nextInt((int) (1.5 * ySpacing) + 1); int newX = (int) referencePoint.getX() + xOffset; int newY = (int) referencePoint.getY() + nextFont.getSize() + yOffset; if (newX > rectangle.x + rectangle.width) { newX -= (2 * Math.abs(xOffset)); } else if (newX < rectangle.x) { newX += (2 * Math.abs(xOffset)); } if (newX > rectangle.x + rectangle.width || newX < rectangle.x) newX = (rectangle.x + rectangle.width) / 2; if (newY >= rectangle.y + rectangle.height) { newY = rectangle.y + rectangle.height - 1; } return new Point(newX, newY); } RandomPointFactory();  RandomPointFactory(int xSpacing, int ySpacing); static Point getFirstVChallengePointFromTopInRegion(Rectangle challengeRectangle, int challengeCount); Point getVChallengePointWrtPercentageSizeOfReferenceFont(Rectangle rectangle, Point referencePoint, Font referenceFont, Font nextFont); static Point getFirstHChallengePointFromLeftInRegion(Rectangle challengeRectangle, int challengeCount); Point getHChallengePointWrtPercentageSizeOfReferenceFont(Rectangle rectangle, Point referencePoint, Font referenceFont, Font nextFont); static Point getRandomPoint(Rectangle rect); static Point getRandomPointWithDistance(Rectangle rectangle, List<Point> reference, int distance); static final int DEFAULT_SPACING; static final int MAX_SPACING; }
@Test public void testGetVChallengePointWrtPercentageSizeOfReferenceFont() throws Exception { Point temp; Font referenceFont; Font nextFont; Point referencePoint; for (int i = 0; i < 1000; i++) { referencePoint = rpf.getRandomPoint(testRectangle); for (int reference = 10; reference < MAX / 2; reference += 5) { for (int next = 10; next < MAX / 2; next += 5) { referenceFont = getNewFont(reference); nextFont = getNewFont(next); temp = rpf.getVChallengePointWrtPercentageSizeOfReferenceFont(testRectangle, referencePoint, referenceFont, nextFont); assertTrue(isPointInsideRectangleAndNextYGreaterThanReferenceY(testRectangle, referencePoint, temp)); } } } }