1 package org.opentrafficsim.core.network;
2
3 import static org.junit.Assert.assertTrue;
4
5 import java.util.HashMap;
6 import java.util.Map;
7
8 import org.djunits.unit.FrequencyUnit;
9 import org.djunits.value.vdouble.scalar.Frequency;
10 import org.junit.Test;
11 import org.opentrafficsim.core.dsol.OTSSimulatorInterface;
12 import org.opentrafficsim.core.geometry.OTSGeometryException;
13 import org.opentrafficsim.core.geometry.OTSLine3D;
14 import org.opentrafficsim.core.geometry.OTSPoint3D;
15 import org.opentrafficsim.core.gtu.GTUType;
16 import org.opentrafficsim.core.mock.MockSimulator;
17
18
19
20
21
22
23
24
25
26
27
28
29 public class CapacityOTSLinkTest
30 {
31
32
33
34
35
36 @Test
37 public final void constructorTest() throws NetworkException, OTSGeometryException
38 {
39 OTSPoint3D fromPoint = new OTSPoint3D(100, 200, 300);
40 OTSPoint3D toPoint = new OTSPoint3D(1000, 2000, 330);
41 Network network = new OTSNetwork("testNetworkForCapacityOTSLink", true);
42 Node fromNode = new OTSNode(network, "startNode", fromPoint);
43 Node toNode = new OTSNode(network, "endNode", toPoint);
44 LinkType linkType = network.getLinkType(LinkType.DEFAULTS.ROAD);
45 OTSLine3D designLine = new OTSLine3D(fromPoint, toPoint);
46 OTSSimulatorInterface simulator = MockSimulator.createMock();
47 Frequency initialCapacity = new Frequency(1234, FrequencyUnit.PER_HOUR);
48 Frequency finalCapacity = new Frequency(1234, FrequencyUnit.PER_HOUR);
49 Map<GTUType, LongitudinalDirectionality> directionalityMap = new HashMap<>();
50 directionalityMap.put(network.getGtuType(GTUType.DEFAULTS.VEHICLE), LongitudinalDirectionality.DIR_PLUS);
51 CapacityOTSLink link =
52 new CapacityOTSLink(network, "link", fromNode, toNode, linkType, designLine, simulator, initialCapacity);
53 assertTrue("from point matches", fromPoint.equals(link.getDesignLine().get(0)));
54 assertTrue("to point matches", toPoint.equals(link.getDesignLine().get(1)));
55 assertTrue("from node matches", fromNode.equals(link.getStartNode()));
56 assertTrue("to node matches", toNode.equals(link.getEndNode()));
57 assertTrue("capacity mathes", initialCapacity.equals(link.getCapacity()));
58 link.setCapacity(finalCapacity);
59 assertTrue("capacity mathes", finalCapacity.equals(link.getCapacity()));
60
61 Network newNetwork = new OTSNetwork("clonedNetworkForCapacityOTSLink", true);
62
63 new OTSNode(newNetwork, fromNode.getId(), fromPoint);
64 new OTSNode(newNetwork, toNode.getId(), toPoint);
65 OTSSimulatorInterface newSimulator = MockSimulator.createMock();
66 CapacityOTSLink clonedLink = new CapacityOTSLink(newNetwork, newSimulator, link);
67 assertTrue("from point matches", fromPoint.equals(clonedLink.getDesignLine().get(0)));
68 assertTrue("to point matches", toPoint.equals(clonedLink.getDesignLine().get(1)));
69
70 assertTrue("from node matches", fromNode.equals(clonedLink.getStartNode()));
71 assertTrue("to node matches", toNode.equals(clonedLink.getEndNode()));
72 assertTrue("capacity mathes", finalCapacity.equals(clonedLink.getCapacity()));
73 clonedLink.setCapacity(initialCapacity);
74 assertTrue("capacity mathes", initialCapacity.equals(clonedLink.getCapacity()));
75 newNetwork.removeLink(clonedLink);
76 clonedLink = link.clone(newNetwork, newSimulator);
77 assertTrue("from point matches", fromPoint.equals(clonedLink.getDesignLine().get(0)));
78 assertTrue("to point matches", toPoint.equals(clonedLink.getDesignLine().get(1)));
79
80 assertTrue("from node matches", fromNode.equals(clonedLink.getStartNode()));
81 assertTrue("to node matches", toNode.equals(clonedLink.getEndNode()));
82 assertTrue("capacity mathes", finalCapacity.equals(clonedLink.getCapacity()));
83 clonedLink.setCapacity(initialCapacity);
84 assertTrue("capacity mathes", initialCapacity.equals(clonedLink.getCapacity()));
85 assertTrue("toString method returns something with the class name in it", link.toString().contains("CapacityOTSLink"));
86 }
87 }