DoubleGenotype extends ArrayList<Double> implements ListGenotype<Double> { public void init(Random random, int n) { try { getLowerBound(n - 1); getUpperBound(n - 1); } catch (IndexOutOfBoundsException outOfBoundException) { throw new IllegalArgumentException( "Cannot initialize a genotype with " + n + " entries with the specified bounds", outOfBoundException); } for (int i = 0; i < n; i++) { double lo = getLowerBound(i); double hi = getUpperBound(i); double value = lo + random.nextDouble() * (hi - lo); if (i >= size()) { add(value); } else { set(i, value); } } } DoubleGenotype();  DoubleGenotype(double lowerBound, double upperBound);  DoubleGenotype(Bounds<Double> bounds); double getLowerBound(int index); double getUpperBound(int index); @Override @SuppressWarnings("unchecked") G newInstance(); void init(Random random, int n);  }
@Test(expected = IllegalArgumentException.class) public void testWrongSettingBoundList() { Random rand = new Random(); List<Double> lowerBounds = new ArrayList<>(); lowerBounds.add(-1.0); lowerBounds.add(-0.5); lowerBounds.add(0.0); List<Double> upperBounds = new ArrayList<>(); upperBounds.add(-0.5); upperBounds.add(0.0); upperBounds.add(0.5); DoubleBounds bounds = new DoubleBounds(lowerBounds, upperBounds); DoubleGenotype listGeno = new DoubleGenotype(bounds); assertTrue(listGeno.isEmpty()); listGeno.init(rand, 4); }
@Test(expected = IllegalArgumentException.class) public void testWrongBoundSettingArray() { Random rand = new Random(); double[] lowerBounds = { -1.0, -0.5, 0.0 }; double[] upperBounds = { -0.5, 0.0, 0.5 }; DoubleBounds bounds = new DoubleBounds(lowerBounds, upperBounds); DoubleGenotype listGeno = new DoubleGenotype(bounds); assertTrue(listGeno.isEmpty()); listGeno.init(rand, 4); }