-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
ChangeGraphHelperTest.java
78 lines (69 loc) · 3.07 KB
/
ChangeGraphHelperTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.graphhopper.storage.change;
import com.graphhopper.json.GHJson;
import com.graphhopper.json.GHJsonFactory;
import com.graphhopper.json.JsonFeatureConverter;
import com.graphhopper.routing.AbstractRoutingAlgorithmTester;
import com.graphhopper.routing.util.AllEdgesIterator;
import com.graphhopper.routing.util.EncodingManager;
import com.graphhopper.routing.util.FlagEncoder;
import com.graphhopper.storage.GraphBuilder;
import com.graphhopper.storage.GraphHopperStorage;
import com.graphhopper.storage.RAMDirectory;
import com.graphhopper.storage.index.LocationIndex;
import com.graphhopper.storage.index.LocationIndexTree;
import com.graphhopper.util.GHUtility;
import com.graphhopper.util.Helper;
import org.junit.Before;
import org.junit.Test;
import java.io.InputStreamReader;
import java.io.Reader;
import static org.junit.Assert.*;
/**
* @author Peter Karich
*/
public class ChangeGraphHelperTest {
private EncodingManager encodingManager;
private GraphHopperStorage graph;
private GHJson ghson;
@Before
public void setUp() {
encodingManager = new EncodingManager("car");
graph = new GraphBuilder(encodingManager).create();
ghson = new GHJsonFactory().create();
}
@Test
public void testApplyChanges() {
// 0-1-2
// | |
// 3-4
graph.edge(0, 1, 1, true);
graph.edge(1, 2, 1, true);
graph.edge(3, 4, 1, true);
graph.edge(0, 3, 1, true);
graph.edge(1, 4, 1, true);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.01, 0.00);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 2, 0.01, 0.02);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 3, 0.00, 0.00);
AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 4, 0.00, 0.01);
LocationIndex locationIndex = new LocationIndexTree(graph, new RAMDirectory()).prepareIndex();
FlagEncoder encoder = encodingManager.getEncoder("car");
double defaultSpeed = encoder.getSpeed(GHUtility.getEdge(graph, 0, 1).getFlags());
AllEdgesIterator iter = graph.getAllEdges();
while (iter.next()) {
long flags = GHUtility.getEdge(graph, 0, 1).getFlags();
assertEquals(defaultSpeed, encoder.getSpeed(flags), .1);
assertTrue(encoder.isForward(flags));
}
Reader reader = new InputStreamReader(getClass().getResourceAsStream("overlaydata1.json"), Helper.UTF_CS);
ChangeGraphHelper instance = new ChangeGraphHelper(graph, locationIndex);
JsonFeatureConverter converter = new JsonFeatureConverter(ghson, instance, encodingManager);
long updates = converter.applyChanges(reader);
assertEquals(2, updates);
// assert changed speed and access
double newSpeed = encoder.getSpeed(GHUtility.getEdge(graph, 0, 1).getFlags());
assertEquals(10, newSpeed, .1);
assertTrue(newSpeed < defaultSpeed);
assertFalse(encoder.isForward(GHUtility.getEdge(graph, 3, 4).getFlags()));
}
}