### Question:
ParameterizableStringListFactory extends AbstractFeatureFactory<T> { @Override public T random() { int numFields = MathUtil.RANDOM.nextInt(minSetSize, maxSetSize + 1); List<ParameterizableStringFactory> tmp = new ArrayList<>(); tmp.addAll(factories); Collections.shuffle(tmp); List<ParameterizableString> ret = new ArrayList<>(); for (int i = 0; i < numFields; i++) { ret.add(tmp.get(i).random()); } return (T)newInstance(ret); } ParameterizableStringListFactory(String name, Class clazz,
                                            List<ParameterizableStringFactory> factories,
                                            int minSetSize, int maxSetSize); @Override T random(); @Override List<T> permute(int maxSize); @Override T mutate(ParameterizableStringListFeature listFeature,
                                                   double probability, double amplitude); @Override Pair<T, T> crossover(T parentA, T parentB);  }### Answer:
@Test public void testRandom() throws Exception { String paramString1 = "abc[1,2,3],[4,5,6],[$2])"; String paramString2 = "def[7,8,9],[10,11,12],[$2])"; String paramString3 = "ghi[13,14,15],[16,17,18],[$2])"; List<ParameterizableStringFactory> factories = new ArrayList<>(); factories.add(new ParameterizableStringFactory("bf", "0", TestParam.class, paramString1)); factories.add(new ParameterizableStringFactory("bf", "0", TestParam.class, paramString2)); factories.add(new ParameterizableStringFactory("bf", "0", TestParam.class, paramString3)); ParameterizableStringListFactory parameterizableStringListFactory = new ParameterizableStringListFactory( "name", TestParamList.class, factories, 1, 3); int min = -1; int max = -1; for (int i = 0; i < 100; i++) { List<ParameterizableString> strings = parameterizableStringListFactory.random().getParameterizableStrings(); if (i == 0) { min = strings.size(); max = strings.size(); } else { if (strings.size() < min) { min = strings.size(); } if (strings.size() > max) { max = strings.size(); } } } assertEquals(1, min); assertEquals(3, max); }
@Test public void testFormats() { String paramString = "[-.0000000001]"; ParameterizableStringFactory<TestParam> fact = new ParameterizableStringFactory("bf", "0", TestParam.class, paramString); assertEquals("-1.0E-10", fact.random().toString()); paramString = "[5000.1]"; fact = new ParameterizableStringFactory("bf", "0", TestParam.class, paramString); assertEquals("5000.1", fact.random().toString()); paramString = "[10.123423]"; fact = new ParameterizableStringFactory("bf", "0", TestParam.class, paramString); assertEquals("10.123", fact.random().toString()); paramString = "[0.123423]"; fact = new ParameterizableStringFactory("bf", "0", TestParam.class, paramString); assertEquals("0.123", fact.random().toString()); paramString = "[7.1]"; fact = new ParameterizableStringFactory("bf", "0", TestParam.class, paramString); assertEquals("7.1", fact.random().toString()); }