def test_getEdgeClockwise(self): net = getSimpleNet() v5 = net.getVertex("5") edge15 = net.getEdge("1", "5") edge51 = net.getEdge("5", "1") edge25 = net.getEdge("2", "5") edge52 = net.getEdge("5", "2") edge45 = net.getEdge("4", "5") edge54 = net.getEdge("5", "4") edge35 = net.getEdge("3", "5") edge53 = net.getEdge("5", "3") result = v5.getEdgeClockwise(edge15) assert result == edge51 result = v5.getEdgeClockwise(edge51) assert result == edge25 result = v5.getEdgeClockwise(edge25) assert result == edge52 result = v5.getEdgeClockwise(edge52) assert result == edge45 result = v5.getEdgeClockwise(edge45) assert result == edge54 result = v5.getEdgeClockwise(edge54) assert result == edge35 result = v5.getEdgeClockwise(edge35) assert result == edge53 result = v5.getEdgeClockwise(edge53) assert result == edge15
def test_hasObsCount(self): net = getSimpleNet() addSimVolumeToNet(net) sMov = net.getVertex("5").getMovement("1", "4") assert sMov.hasObsCount(0, 5) assert not sMov.hasObsCount(0, 30)
def test_iterEdgesClockwise(self): net = getSimpleNet() v5 = net.getVertex("5") result = [e.iid for e in v5.iterEdgesClockwise()] answer = [("2", "5"), ("5", "2"), ("4", "5"), ("5", "4"), ("3", "5"), ("5", "3"), ("1", "5"), ("5", "1")] assert result == answer
def test_setObsCount(self): net = getSimpleNet() addSimVolumeToNet(net) sMov = net.getVertex("5").getMovement("1", "4") sMov.setObsCount(0, 15, 0) nose.tools.assert_raises(SimError, sMov.setObsCount, 0, 15, -1)
def test_splitEdge(self): net = getSimpleNet() edge = net.getEdge("5", "4") edgesBefore = net.getNumEdges() verticesBefore = net.getNumVertices() net.splitEdge(edge) assert net.getNumEdges() == edgesBefore + 1 assert net.getNumVertices() == verticesBefore + 1
def testSimTTInMin(self): net = getSimpleNet() addSimVolumeToNet(net) sMov = net.getVertex("5").getMovement("1", "4") link51 = net.getEdge("5", "1") assert link51.lengthInFeet == 300 assert link51.lengthInMiles == 300 / 5280.0 #nose.tools.set_trace() assert sMov.getSimTTInMin(30, 40) == link51.lengthInMiles / link51.freeFlowSpeedInMPH * 60
def test_simFlow(self): net = getSimpleNet() addSimVolumeToNet(net) sMov = net.getVertex("5").getMovement("1", "4") assert sMov.getSimFlow(0, 5) == 1 * 12 assert sMov.getSimFlow(0, 10) == (1 + 2) * 6 assert sMov.getSimFlow(5, 20) == (2 + 3 + 4) * 4 assert sMov.getSimFlow(0, 20) == (1 + 2 + 3 + 4) * 3.0 assert sMov.getSimFlow(0, 30) == (1 + 2 + 3 + 4) * 2.0
def test_deleteVertex(self): net = getSimpleNet() v5 = net.getVertex("5") net.deleteVertex(v5) assert not net.hasEdge("1", "5") assert not net.hasEdge("2", "5") assert not net.hasVertex("5")
def test_getObsCount(self): """Obs counts have the same time step with the simResults""" net = getSimpleNet() addSimVolumeToNet(net) sMov = net.getVertex("5").getMovement("1", "4") assert sMov.getObsCount(0, 5) == 2 assert sMov.getObsCount(0, 10) == 5 assert sMov.getObsCount(10, 20) == 9 assert not sMov.getObsCount(0, 30)
def test_iterPredSuccAdjVertices(self): net = getSimpleNet() v1 = net.getVertex("1") assert v1.getNumPredecessorVertices() == 1 assert v1.getNumSuccessorVertices() == 1 assert v1.getNumAdjacentVertices() == 1 v5 = net.getVertex("5") assert v5.getNumAdjacentVertices() == 4
def test_simMeanTT(self): net = getSimpleNet() addSimVolumeToNet(net) sMov = net.getVertex("5").getMovement("1", "4") assert sMov.getSimTTInMin(0, 5) == 1 assert sMov.getSimTTInMin(0, 10) == (1 + 4) / 3.0 assert sMov.getSimTTInMin(5, 15) == (2 * 2 + 3 * 3) / 5.0 nose.tools.assert_raises(SimError, sMov.getSimTTInMin, 0, 30) nose.tools.assert_raises(SimError, sMov.getSimTTInMin, 30, 0) sMov.setSimTTInMin(15, 20, 4) assert sMov.getSimTTInMin(0, 30) == (1*1 + 2*2 + 3*3 + 4*4) / 10.0
def test_getObsCounts2(self): """Obs counts use a time step different than that of the simResults""" net = getSimpleNet() addSimVolumeToNet(net) sMov = net.getVertex("5").getMovement("1", "4") sMov2 = net.getVertex("4").getMovement("5", "8") sMov2.setObsCount(0, 10, 7) sMov2.setObsCount(10, 20, 13) sMov2.setObsCount(20, 30, 14) assert sMov2.getObsCount(0, 10) == 7 assert sMov2.getObsCount(0, 20) == 20 assert sMov2.getObsCount(0, 30) == 34
def test_adjacentVertices(self): net = getSimpleNet() v1 = net.getVertex("1") v2 = net.getVertex("2") v4 = net.getVertex("4") v3 = net.getVertex("3") v5 = net.getVertex("5") av = set([v for v in v5.iterAdjacentVertices()]) assert len(av) == 4 assert v1 in av assert v2 in av assert v3 in av assert v4 in av assert v5 not in av
def test_iterEdgePairs(self): net = getSimpleNet() v5 = net.getVertex("5") result = [(e1.iid, e2.iid) for e1, e2 in v5.iterEdgePairs()] answer = [ (("2", "5"), ("5", "2")), (("5", "2"), ("4", "5")), (("4", "5"), ("5", "4")), (("5", "4"), ("3", "5")), (("3", "5"), ("5", "3")), (("5", "3"), ("1", "5")), (("1", "5"), ("5", "1")), (("5", "1"), ("2", "5")), ] assert result == answer
def test_getAcuteAngle(self): v5 = constructIntersection(withMovements=True) e15 = v5.getInEdge("1") e52 = v5.getOutEdge("2") e25 = v5.getInEdge("2") e35 = v5.getInEdge("3") e54 = v5.getOutEdge("4") e45 = v5.getInEdge("4") assert e15.getAcuteAngle(e52) == 90 assert e52.getAcuteAngle(e15) == 90 assert e15.getAcuteAngle(e54) == 180 assert e15.getAcuteAngle(e45) == 180 net = getSimpleNet() v5 = net.getVertex("5") v8 = net.getVertex("8") e58 = Edge(v5, v8, 3) net.addEdge(e58) e15 = net.getEdge("1", "5") e51 = net.getEdge("5", "1") assert e15.getAcuteAngle(e58) == 135 assert e51.getAcuteAngle(e58) == 135 assert e58.getAcuteAngle(e15) == 135 assert e58.getAcuteAngle(e51) == 135 e85 = Edge(v8, v5, 2) net.addEdge(e85) assert e15.getAcuteAngle(e85) == 135 assert e51.getAcuteAngle(e85) == 135 assert e85.getAcuteAngle(e15) == 135 assert e85.getAcuteAngle(e51) == 135
def test_deleteEdge(self): net = getSimpleNet() edge15 = net.getEdge("1", "5") edge25 = net.getEdge("2", "5") edge47 = net.getEdge("4", "7") assert edge15.hasOutMovement("4") assert edge25.hasOutMovement("4") assert edge47.hasInMovement("5") edge54 = net.getEdge("5", "4") net.deleteEdge(edge54) assert not edge15.hasOutMovement("4") assert not edge25.hasOutMovement("4") assert not edge47.hasInMovement("5") assert not net.hasEdge("5", "4")
def test_isShapePoint(self): net = getSimpleNet() v7 = net.getVertex("7") assert not v7.isShapePoint() v9 = Vertex("9", 1200, 300) net.addVertex(v9) assert not v7.isShapePoint() e79 = Edge(v7, v9, 1) net.addEdge(e79) assert not v7.isShapePoint() e97 = Edge(v9, v7, 1) net.addEdge(e97) assert v7.isShapePoint()
def createNet(self): net = getSimpleNet() link15 = net.getEdge('1', '5') mov152 = link15.getOutMovement('2') mov152.setSimVolume(0, 5, 1) mov152.setSimTTInMin(0, 5, 1) mov152.setSimVolume(5, 10, 3) mov152.setSimTTInMin(5, 10, 4) mov152.setObsCount(0, 5, 11) mov152.setObsCount(5, 10, 11) mov154 = link15.getOutMovement('4') mov154.setSimVolume(0, 5, 2) mov154.setSimTTInMin(0, 5, 2) mov154.setSimVolume(5, 10, 5) mov154.setSimTTInMin(5, 10, 6.3) mov154.setObsCount(0, 5, 7) mov154.setObsCount(5, 10, 11) mov153 = link15.getOutMovement('3') mov153.setSimVolume(0, 5, 3) mov153.setSimTTInMin(0, 5, 3) mov153.setSimVolume(5, 10, 5) mov153.setSimTTInMin(5, 10, 8.9) mov153.setObsCount(0, 5, 43) mov153.setObsCount(5, 10, 23) link25 = net.getEdge('2', '5') link25.setObsCount(0, 5, 10) link25.setObsCount(5, 10, 20) return net, link15, link25