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