@Test(dataProvider = "flags") public void setXAndGetConfigurationBehaveAsExpeced(List<Boolean> flags) { // builder with no template XId nodeConfigId = XId.newId(); Builder builder = NodeConfiguration.builder(nodeConfigId); for (Fragment fragment : Fragment.values()) { setConfigParameter(flags, builder, fragment); } NodeConfiguration nodeConfig = builder.newInstance(); assertThat( "", // nodeConfig.getId(), isEqualTo(nodeConfigId)); for (Fragment fragment : Fragment.values()) { testConfigsParameter(flags, nodeConfig, fragment, NodeConfiguration.DEFAULT_CONFIGURATION); } // builder with template nodeConfigId = XId.newId(); builder = NodeConfiguration.builder(nodeConfigId).setTemplate(TEMPLATE); for (Fragment fragment : Fragment.values()) { setConfigParameter(flags, builder, fragment); } nodeConfig = builder.newInstance(); assertThat( "", // nodeConfig.getId(), isEqualTo(nodeConfigId)); for (Fragment fragment : Fragment.values()) { testConfigsParameter(flags, nodeConfig, fragment, TEMPLATE); } }
public Map(GameState gameState, MapConfiguration config) { this.config = config; nodes = new ArrayList<Node>(); int id = 0; for (NodeConfiguration nc : config.getNodes()) nodes.add(nc.createNode(gameState, id++)); lanes = new ArrayList<Lane>(); for (LaneConfiguration lc : config.getLanes()) lanes.add(lc.createLane(gameState)); }
public void constructorSucceeds() { assertThat( "", // NodeConfiguration.builder(), isNotNull()); assertThat( "", // NodeConfiguration.builder(XId.newId()), isNotNull()); }
static { List<Boolean> addFlags = new ArrayList<Boolean>(); for (int i = 0; i < Fragment.values().length; i++) { addFlags.add(RandomUtil.nextBoolean()); } List<List<Boolean>> testFlags = new ArrayList<List<Boolean>>(); for (int i = 0; i < Fragment.values().length; i++) { Collections.rotate(addFlags, 1); testFlags.add(new ArrayList<Boolean>(addFlags)); } FLAGS = TestUtils.createData(testFlags.toArray()); List<Range<?>> ranges = new ArrayList<Range<?>>(); for (Fragment fragment : Fragment.values()) { switch (fragment) { case DOES_INVERT: ranges.add(Range.getInstance(false, true)); ranges.add(Range.getInstance(false, true)); break; case DELAY: case OSCILLATION_OFFSET: case OSCILLATION_PERIOD: ranges.add(Range.getInstance(RandomUtil.nextInteger())); ranges.add(Range.getInstance(RandomUtil.nextInteger())); break; default: ranges.add(Range.getInstance(RandomUtil.nextFloat())); ranges.add(Range.getInstance(RandomUtil.nextFloat())); break; } } RANGES = ranges.toArray(new Range<?>[0]); TEMPLATE = NodeConfiguration // .builder() // .setDelay(Range.getInstance(0), null) // .setInvertFlag(Range.<Boolean>openRange(), null) // .setEnergy(Range.<Float>openRange(), null) // .setEnergyDecay(Range.<Float>openRange(), null) // .setExcitatoryScale(Range.<Float>openRange(), null) // .setInhibitoryScale(Range.<Float>openRange(), null) // .setOscillationMaximum(Range.<Float>openRange(), null) // .setOscillationMinimum(Range.<Float>openRange(), null) // .setOscillationOffset(Range.<Integer>openRange(), null) // .setOscillationPeriod(Range.<Integer>openRange(), null) // .setScale(Range.<Float>openRange(), null) // .setShift(Range.<Float>openRange(), null) // .setTwitchMaximum(Range.<Float>openRange(), null) // .setTwitchMinimum(Range.<Float>openRange(), null) // .setTwitchProbability(Range.<Float>openRange(), null) // .newInstance(); }
private void testConfigsParameter( List<Boolean> flags, NodeConfiguration nodeConfig, Fragment fragment, NodeConfiguration template) { if (!Fragment.ENERGIES.equals(fragment)) { int index = fragment.ordinal(); if (flags.get(index)) { assertThat( fragment.getParameterId().toString(), // ((RangeXParameter<?>) nodeConfig.getParameter(fragment.getParameterId())) .getLifetimeRange(), // isEqualTo(RANGES[2 * index])); assertThat( fragment.getParameterId().toString(), // ((RangeXParameter<?>) nodeConfig.getParameter(fragment.getParameterId())) .getInitialRange(), // isEqualTo(RANGES[2 * index + 1])); } else { assertThat( fragment.getParameterId().toString(), // ((RangeXParameter<?>) nodeConfig.getParameter(fragment.getParameterId())) .getLifetimeRange(), // isEqualTo( ((RangeXParameter<?>) template.getParameter(fragment.getParameterId())) .getLifetimeRange())); assertThat( fragment.getParameterId().toString(), // ((RangeXParameter<?>) nodeConfig.getParameter(fragment.getParameterId())) .getInitialRange(), // isEqualTo( ((RangeXParameter<?>) template.getParameter(fragment.getParameterId())) .getInitialRange())); } } }