RandomIntELFunction implements ELFunction { @Override public String evalute(String... args) { Random generator = new Random(); if (args != null) { switch (args.length) { case 1: int maxValue = Integer.MAX_VALUE; try { maxValue = Integer.parseInt(args[0]); } catch (NumberFormatException nfe) { } return String.valueOf(generator.nextInt(maxValue)); case 2: int minValue = 0; maxValue = Integer.MAX_VALUE; try { minValue = Integer.parseInt(args[0]); maxValue = Integer.parseInt(args[1]); } catch (NumberFormatException nfe) { } return String.valueOf(generator.nextInt(maxValue - minValue) + minValue); default: return String.valueOf(generator.nextInt()); } } return String.valueOf(generator.nextInt()); }  @Override String evalute(String... args);  }
@Test public void testSimpleEvaluation() { RandomIntELFunction function = new RandomIntELFunction(); String randomIntString = function.evalute(); int randomInt = Integer.parseInt(randomIntString); assertTrue(randomInt >= Integer.MIN_VALUE); assertTrue(randomInt <= Integer.MAX_VALUE); }
@Test public void testBoundedEvaluation() { RandomIntELFunction function = new RandomIntELFunction(); String randomIntString = function.evalute("50"); int randomInt = Integer.parseInt(randomIntString); assertTrue(randomInt >= 0); assertTrue(randomInt <= 50); }
@Test public void testIntervalEvaluation() { RandomIntELFunction function = new RandomIntELFunction(); String randomIntString = function.evalute("25", "50"); int randomInt = Integer.parseInt(randomIntString); assertTrue(randomInt >= 25); assertTrue(randomInt <= 50); }