Add vertex api and test

This commit is contained in:
WQY\qiong
2022-11-04 16:30:09 +08:00
parent a5818ec463
commit 91ae7608a3
5 changed files with 163 additions and 2 deletions

View File

@@ -2488,6 +2488,79 @@ class TestApi:
self.leave(p)
# 25 vertex
def test_vertex(self):
p = 'test_vertex'
self.enter(p)
add_junction(p, ChangeSet({'id': 'j1', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
add_junction(p, ChangeSet({'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
add_pipe(p, ChangeSet({'id': 'p0', 'node1': 'j1', 'node2': 'j2', 'length': 100.0, 'diameter': 10.0, 'roughness': 0.1, 'minor_loss': 0.5, 'status': PIPE_STATUS_OPEN }))
v = get_vertex(p, 'p0')
assert v['link'] == 'p0'
assert v['coords'] == []
set_vertex(p, ChangeSet({'link' : 'p0', 'coords': [{'x': 1.0, 'y': 2.0}, {'x': 2.0, 'y': 1.0}]}))
v = get_vertex(p, 'p0')
xys = v['coords']
assert len(xys) == 2
assert xys[0]['x'] == 1.0
assert xys[0]['y'] == 2.0
assert xys[1]['x'] == 2.0
assert xys[1]['y'] == 1.0
set_vertex(p, ChangeSet({'link' : 'p0', 'coords': []}))
v = get_vertex(p, 'p0')
assert v['link'] == 'p0'
assert v['coords'] == []
self.leave(p)
def test_vertex_op(self):
p = 'test_vertex_op'
self.enter(p)
add_junction(p, ChangeSet({'id': 'j1', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
add_junction(p, ChangeSet({'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
add_pipe(p, ChangeSet({'id': 'p0', 'node1': 'j1', 'node2': 'j2', 'length': 100.0, 'diameter': 10.0, 'roughness': 0.1, 'minor_loss': 0.5, 'status': PIPE_STATUS_OPEN }))
cs = set_vertex(p, ChangeSet({'link' : 'p0', 'coords': [{'x': 1.0, 'y': 2.0}, {'x': 2.0, 'y': 1.0}]})).operations[0]
assert cs['operation'] == API_UPDATE
assert cs['type'] == 'vertex'
assert cs['link'] == 'p0'
xys = cs['coords']
assert len(xys) == 2
assert xys[0]['x'] == 1.0
assert xys[0]['y'] == 2.0
assert xys[1]['x'] == 2.0
assert xys[1]['y'] == 1.0
cs = execute_undo(p).operations[0]
assert cs['operation'] == API_UPDATE
assert cs['type'] == 'vertex'
assert cs['link'] == 'p0'
assert cs['coords'] == []
cs = execute_redo(p).operations[0]
assert cs['operation'] == API_UPDATE
assert cs['type'] == 'vertex'
assert cs['link'] == 'p0'
xys = cs['coords']
assert len(xys) == 2
assert xys[0]['x'] == 1.0
assert xys[0]['y'] == 2.0
assert xys[1]['x'] == 2.0
assert xys[1]['y'] == 1.0
self.leave(p)
# 26 label