@Test(expected = IllegalArgumentException.class) public void testWrongBoundSettingArray() { Random rand = new Random(); int[] lowerBounds = { 1, 2, 3 }; int[] upperBounds = { 2, 3, 4 }; IntegerBounds bounds = new IntegerBounds(lowerBounds, upperBounds); IntegerGenotype listBoundGeno = new IntegerGenotype(bounds); assertTrue(listBoundGeno.isEmpty()); listBoundGeno.init(rand, 3); assertEquals(3, listBoundGeno.size()); listBoundGeno.init(rand, 4); }
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++) { int lo = getLowerBound(i); int hi = getUpperBound(i); int value = lo + random.nextInt(hi - lo + 1); if (i >= size()) { add(value); } else { set(i, value); } } }
IntegerGenotype extends ArrayList<Integer> implements ListGenotype<Integer> { 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++) { int lo = getLowerBound(i); int hi = getUpperBound(i); int value = lo + random.nextInt(hi - lo + 1); if (i >= size()) { add(value); } else { set(i, value); } } } }
IntegerGenotype extends ArrayList<Integer> implements ListGenotype<Integer> { 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++) { int lo = getLowerBound(i); int hi = getUpperBound(i); int value = lo + random.nextInt(hi - lo + 1); if (i >= size()) { add(value); } else { set(i, value); } } } IntegerGenotype(int lowerBound, int upperBound);  IntegerGenotype(Bounds<Integer> bounds); }
IntegerGenotype extends ArrayList<Integer> implements ListGenotype<Integer> { 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++) { int lo = getLowerBound(i); int hi = getUpperBound(i); int value = lo + random.nextInt(hi - lo + 1); if (i >= size()) { add(value); } else { set(i, value); } } } IntegerGenotype(int lowerBound, int upperBound);  IntegerGenotype(Bounds<Integer> bounds); int getLowerBound(int index); int getUpperBound(int index); @SuppressWarnings("unchecked") @Override G newInstance(); void init(Random random, int n); }
IntegerGenotype extends ArrayList<Integer> implements ListGenotype<Integer> { 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++) { int lo = getLowerBound(i); int hi = getUpperBound(i); int value = lo + random.nextInt(hi - lo + 1); if (i >= size()) { add(value); } else { set(i, value); } } } IntegerGenotype(int lowerBound, int upperBound);  IntegerGenotype(Bounds<Integer> bounds); int getLowerBound(int index); int getUpperBound(int index); @SuppressWarnings("unchecked") @Override G newInstance(); void init(Random random, int n);  }