RandomPointFactory { public Point getHChallengePointWrtPercentageSizeOfReferenceFont(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 yVariation = (GlobalConstants.CHALLENGE_DELTA_PERCENTAGE * referenceFont.getSize()) / 100; int xOffset = rand.nextInt(xSpacing + 1) * (rand.nextBoolean() ? 1 : -1); int yOffset = rand.nextInt(yVariation + 1) * (rand.nextBoolean() ? 1 : -1); int newX = (int) referencePoint.getX() + xOffset + (int) (referenceFont.getSize() * H_FONT_MULTIPLIER); int newY = (int) referencePoint.getY() + yOffset; if (newY > rectangle.y + rectangle.height) { newY -= (2 * Math.abs(yOffset)); } else if (newY < rectangle.y) { newY += (2 * Math.abs(yOffset)); } if (newX > rectangle.x + rectangle.width || newX < rectangle.x) newX = rectangle.x + rectangle.width; if (newY > rectangle.y + rectangle.height) newY = rectangle.y + rectangle.height; 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 testGetHChallengePointWrtPercentageSizeOfReferenceFont() 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.getHChallengePointWrtPercentageSizeOfReferenceFont(testRectangle, referencePoint, referenceFont, nextFont); assertTrue(isPointInsideRectangleAndNextXGreaterThanReferenceX(testRectangle, referencePoint, temp)); } } } }