Пример #1
0
def test_succesors():
    node = Node("1", point=Point(1, 2, 3), data={"1": 2})

    e1 = Edge("1", "2", distance=15)
    e2 = Edge("1", "4", distance=25)
    node.edges = [e1, e2]

    assert (node.successors() == {"2": 15, "4": 25})

    # Check if edge not really good
    node = Node("3", point=Point(1, 2, 3), data={"1": 2})

    e1 = Edge("1", "2", distance=15)
    e2 = Edge("1", "4", distance=25)
    node.edges = [e1, e2]

    assert (node.successors() == {})

    # Check
    node = Node("3", point=Point(1, 2, 3), data={"1": 2})

    e1 = Edge("1", "3", distance=15)
    e2 = Edge("2", "3", distance=25)
    node.edges = [e1, e2]

    assert (node.successors() == {"1": 15, "2": 25})

    # Check edge between same node
    node = Node("3", point=Point(1, 2, 3), data={"1": 2})

    e1 = Edge("3", "3", distance=15)
    e2 = Edge("3", "3", distance=25)
    node.edges = [e1, e2]

    assert (node.successors() == {})
Пример #2
0
def test_merge():
    node = Node("Test", point=Point(1, 2, 3), data={"1": 2})

    e1 = Edge("1", "2")
    e2 = Edge("2", "4")
    node.edges = [e1, e2]

    node2 = deepcopy(node)
    e3 = Edge("2", "3")
    node2.add_edge(e3)

    node2.set("1", 3)
    node2.set("2", 4)

    node.merge(node2)

    assert (node.name == "Test")
    assert (node.point.x == 1)
    assert (node.point.y == 2)
    assert (node.point.z == 3)

    assert (node.get("1") == 3)
    assert (node.get("2") == 4)

    assert (node.edges == [e1, e2, e3])
Пример #3
0
def test_basic():
    """Basic test"""
    point = 42
    node = Node("Test", point=point)

    node_test(node, "Test", point, {}, [])

    point = Point()

    node.point = point
    node.name = "Titi"
    toto = {"ici": "la"}
    node.data = toto
    print(node.data)
    node.edges = ["a", "b"]

    node_test(node, "Titi", point, toto, ["a", "b"])

    assert (node.get("ici") == "la")
    assert (node.get("la") is None)
    assert (node.get("la", default=42) == 42)

    node.set("la", "This is a test")
    assert (node.get("la") == "This is a test")
    assert (node.get("la", default=42) == "This is a test")

    assert (node.to_dict() == {
        "name": "Titi",
        "point": point.to_dict(),
        "data": node.data
    })

    e1 = Edge("1", "2")
    e2 = Edge("2", "4")
    node.edges = [e1, e2]

    assert (node.format() == {
        "name": node.name,
        "data": node.data,
        "point": point.to_dict(),
        "edges": ["1-2", "2-4"]
    })
Пример #4
0
def test_deep_copy():
    """Test deepcopy"""
    node = Node("Test", point=Point(1, 2, 3), data={"1": 2})

    node.edges = ["a", "b"]
    node_copy = deepcopy(node)

    assert (node_copy.name == node.name)
    assert (node_copy.data == node.data)
    assert (node_copy.edges == node.edges)

    assert (node_copy.point.x == 1)
    assert (node_copy.point.y == 2)
    assert (node_copy.point.z == 3)
Пример #5
0
 def make_node(self, data):
     return Node(data["id"],
                 point=Point(data["x"], data["y"], data["z"]),
                 data=data["data"])
Пример #6
0
def test_point():
    point = Point()

    def point_test(x, y, z, ptype):
        assert (point.x == x)
        assert (point.y == y)
        assert (point.z == z)
        assert (point.type == ptype)

    point_test(0, 0, 0, POINT_TYPE_GPS)

    point.x = 10
    point.y = 15
    point.z = 20

    point_test(10, 15, 20, POINT_TYPE_GPS)

    assert (point.is_gps() is True)

    assert (point.to_dict() == {
        "latitude": 10,
        "longitude": 15,
        "altitude": 20,
        "type": POINT_TYPE_GPS
    })

    point.latitude = 25
    point.longitude = 30
    point.altitude = 35

    assert (point.latitude == 25)
    assert (point.longitude == 30)
    assert (point.altitude == 35)

    point_test(25, 30, 35, POINT_TYPE_GPS)

    point.type = 42

    assert (point.is_gps() is False)

    point.x = 10
    point.y = 15
    point.z = 20

    assert (point.to_dict() == {"x": 10, "y": 15, "z": 20, "type": 42})
Пример #7
0
def test_angle():
    a = Point(x=48.850000, y=2.350000)  # Paris
    b = Point(x=40.716667, y=-74.000000)  # NewYork
    c = Point(x=9.08196, y=7.402968)  # Abuja (Nigeria)
    assert (round(get_angle(a, b, c), 5) == 1.97882)
Пример #8
0
def test_distance():
    a = Point(x=48.850000, y=2.350000)  # Paris
    b = Point(x=40.716667, y=-74.000000)  # NewYork
    assert (round(get_distance(a, b), 5 == 5843114.78844))
Пример #9
0
import copy

from opv.graphe import Point, Node, Graphe, GrapheHelper

if __name__ == "__main__":

    name = "test.json"
    if len(sys.argv) > 1:
        name = sys.argv[1]

    with open(name, "r") as fic:
        data = json.load(fic)

    graphe = Graphe("Test")
    for name, gps in data.items():
        point = Point(x=gps["latitude"], y=gps["longitude"], z=gps["altitude"])

        graphe.create_node(name, point=point)

    graphe.generate_json("01_points.json")
    graphe.detect_nears_nodes()
    for_reporting = copy.deepcopy(graphe)
    for_reporting.create_edge_from_near_nodes()
    for_reporting.generate_json("02_detect_nears_panorama.json")
    graphes = graphe.get_sub_graphes()
    graphe_helper = GrapheHelper()
    graphe = graphe_helper.merge_subgraphe(graphes)
    graphe.hotpoints = ['634', '633', '660', '670', '86', '770', '777', '767']
    graphe.generate_json("03_merge_graphe.json")
    graphe.get_end_points()
    graphe.generate_json("04_get_endpoints.json")