### Question:
GenericWeighting extends AbstractWeighting { @Override public double calcWeight(EdgeIteratorState edgeState, boolean reverse, int prevOrNextEdgeId) { if (reverse) { if (!gEncoder.isBackward(edgeState, accessType)) return Double.POSITIVE_INFINITY; } else if (!gEncoder.isForward(edgeState, accessType)) { return Double.POSITIVE_INFINITY; } if (gEncoder.isStoreHeight() && overLimit(height, gEncoder.getHeight(edgeState)) || gEncoder.isStoreWeight() && overLimit(weight, gEncoder.getWeight(edgeState)) || gEncoder.isStoreWidth() && overLimit(width, gEncoder.getWidth(edgeState))) return Double.POSITIVE_INFINITY; long time = calcMillis(edgeState, reverse, prevOrNextEdgeId); if (time == Long.MAX_VALUE) return Double.POSITIVE_INFINITY; switch (gEncoder.getAccessValue(edgeState.getFlags())) { case NOT_ACCESSIBLE: return Double.POSITIVE_INFINITY; case EVENTUALLY_ACCESSIBLE: time = time * uncertainAccessiblePenalty; } return time; } GenericWeighting(DataFlagEncoder encoder, PMap hintsMap); @Override double getMinWeight(double distance); @Override double calcWeight(EdgeIteratorState edgeState, boolean reverse, int prevOrNextEdgeId); @Override long calcMillis(EdgeIteratorState edgeState, boolean reverse, int prevOrNextEdgeId); @Override String getName(); static final String HEIGHT_LIMIT; static final String WEIGHT_LIMIT; static final String WIDTH_LIMIT; }### Answer:
@Test public void testRoadAttributeRestriction() { EdgeIteratorState edge = graph.getEdgeIteratorState(0, 1); Weighting instance = new GenericWeighting(encoder, new HintsMap().put(GenericWeighting.HEIGHT_LIMIT, 4.0)); assertEquals(edgeWeight, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8); instance = new GenericWeighting(encoder, new HintsMap().put(GenericWeighting.HEIGHT_LIMIT, 5.0)); assertEquals(Double.POSITIVE_INFINITY, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8); }
@Test public void testDisabledRoadAttributes() { DataFlagEncoder simpleEncoder = new DataFlagEncoder(); EncodingManager simpleEncodingManager = new EncodingManager(simpleEncoder); Graph simpleGraph = new GraphBuilder(simpleEncodingManager).create(); ReaderWay way = new ReaderWay(27l); way.setTag("highway", "primary"); way.setTag("maxspeed", "10"); way.setTag("maxheight", "4.4"); simpleGraph.edge(0, 1, 1, true); AbstractRoutingAlgorithmTester.updateDistancesFor(simpleGraph, 0, 0.00, 0.00); AbstractRoutingAlgorithmTester.updateDistancesFor(simpleGraph, 1, 0.01, 0.01); simpleGraph.getEdgeIteratorState(0, 1).setFlags(simpleEncoder.handleWayTags(way, 1, 0)); Weighting instance = new GenericWeighting(simpleEncoder, new HintsMap().put(GenericWeighting.HEIGHT_LIMIT, 5.0)); EdgeIteratorState edge = simpleGraph.getEdgeIteratorState(0, 1); assertEquals(edgeWeight, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8); }