Refine curve to add type

This commit is contained in:
WQY\qiong
2022-11-04 22:18:01 +08:00
parent 91ae7608a3
commit f9de76ee1d
6 changed files with 181 additions and 43 deletions

View File

@@ -1648,15 +1648,25 @@ class TestApi:
self.enter(p)
assert is_curve(p, 'c0') == False
c0 = get_curve(p, 'c0')
assert c0['id'] == 'c0'
assert c0['coords'] == []
set_curve(p, ChangeSet({'id' : 'c0', 'coords': [{'x': 1.0, 'y': 2.0}, {'x': 2.0, 'y': 1.0}]}))
add_curve(p, ChangeSet({'id' : 'c0', 'c_type' : CURVE_TYPE_PUMP, 'coords': [{'x': 1.0, 'y': 2.0}, {'x': 2.0, 'y': 1.0}]}))
assert is_curve(p, 'c0')
c0 = get_curve(p, 'c0')
assert c0['id'] == 'c0'
assert c0['c_type'] == CURVE_TYPE_PUMP
xys = c0['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_curve(p, ChangeSet({'id' : 'c0', 'c_type': CURVE_TYPE_EFFICIENCY}))
c0 = get_curve(p, 'c0')
assert c0['id'] == 'c0'
assert c0['c_type'] == CURVE_TYPE_EFFICIENCY
xys = c0['coords']
assert len(xys) == 2
assert xys[0]['x'] == 1.0
@@ -1666,11 +1676,15 @@ class TestApi:
set_curve(p, ChangeSet({'id' : 'c0', 'coords': []}))
assert is_curve(p, 'c0') == False
c0 = get_curve(p, 'c0')
assert c0['id'] == 'c0'
assert c0['c_type'] == CURVE_TYPE_EFFICIENCY
assert c0['coords'] == []
delete_curve(p, ChangeSet({'id' : 'c0'}))
assert is_curve(p, 'c0') == False
self.leave(p)
@@ -1678,10 +1692,40 @@ class TestApi:
p = 'test_curve_op'
self.enter(p)
cs = set_curve(p, ChangeSet({'id' : 'c0', 'coords': [{'x': 1.0, 'y': 2.0}, {'x': 2.0, 'y': 1.0}]})).operations[0]
cs = add_curve(p, ChangeSet({'id' : 'c0', 'c_type' : CURVE_TYPE_PUMP, 'coords': [{'x': 1.0, 'y': 2.0}, {'x': 2.0, 'y': 1.0}]})).operations[0]
assert cs['operation'] == API_ADD
assert cs['type'] == CURVE
assert cs['id'] == 'c0'
assert cs['c_type'] == CURVE_TYPE_PUMP
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_DELETE
assert cs['type'] == CURVE
assert cs['id'] == 'c0'
cs = execute_redo(p).operations[0]
assert cs['operation'] == API_ADD
assert cs['type'] == CURVE
assert cs['id'] == 'c0'
assert cs['c_type'] == CURVE_TYPE_PUMP
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 = set_curve(p, ChangeSet({'id' : 'c0', 'c_type': CURVE_TYPE_EFFICIENCY})).operations[0]
assert cs['operation'] == API_UPDATE
assert cs['type'] == CURVE
assert cs['id'] == 'c0'
assert cs['c_type'] == CURVE_TYPE_EFFICIENCY
xys = cs['coords']
assert len(xys) == 2
assert xys[0]['x'] == 1.0
@@ -1693,12 +1737,7 @@ class TestApi:
assert cs['operation'] == API_UPDATE
assert cs['type'] == CURVE
assert cs['id'] == 'c0'
assert cs['coords'] == []
cs = execute_redo(p).operations[0]
assert cs['operation'] == API_UPDATE
assert cs['type'] == CURVE
assert cs['id'] == 'c0'
assert cs['c_type'] == CURVE_TYPE_PUMP
xys = cs['coords']
assert len(xys) == 2
assert xys[0]['x'] == 1.0
@@ -1706,6 +1745,44 @@ class TestApi:
assert xys[1]['x'] == 2.0
assert xys[1]['y'] == 1.0
cs = execute_redo(p).operations[0]
assert cs['operation'] == API_UPDATE
assert cs['type'] == CURVE
assert cs['id'] == 'c0'
assert cs['c_type'] == CURVE_TYPE_EFFICIENCY
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 = set_curve(p, ChangeSet({'id' : 'c0', 'coords': []})).operations[0]
assert cs['operation'] == API_UPDATE
assert cs['type'] == CURVE
assert cs['id'] == 'c0'
assert cs['c_type'] == CURVE_TYPE_EFFICIENCY
assert cs['coords'] == []
cs = execute_undo(p).operations[0]
assert cs['operation'] == API_UPDATE
assert cs['type'] == CURVE
assert cs['id'] == 'c0'
assert cs['c_type'] == CURVE_TYPE_EFFICIENCY
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_redo(p).operations[0]
assert cs['operation'] == API_UPDATE
assert cs['type'] == CURVE
assert cs['id'] == 'c0'
assert cs['c_type'] == CURVE_TYPE_EFFICIENCY
assert cs['coords'] == []
self.leave(p)
@@ -1993,7 +2070,7 @@ class TestApi:
assert ge['pattern'] == 'pa0'
assert ge['effic'] == None
set_curve(p, ChangeSet({'id' : 'c0', 'coords': [{'x': 1.0, 'y': 2.0}, {'x': 2.0, 'y': 1.0}]}))
add_curve(p, ChangeSet({'id' : 'c0', 'c_type' : CURVE_TYPE_PUMP, 'coords': [{'x': 1.0, 'y': 2.0}, {'x': 2.0, 'y': 1.0}]}))
set_pump_energy(p, ChangeSet({'pump' : 'p0', 'effic': 'c0'}))
ge = get_pump_energy(p, 'p0')
assert ge['pump'] == 'p0'
@@ -2012,7 +2089,7 @@ class TestApi:
add_junction(p, ChangeSet({'id': 'j2', 'x': 0.0, 'y': 10.0, 'elevation': 20.0}))
add_pump(p, ChangeSet({'id': 'p0', 'node1': 'j1', 'node2': 'j2', 'power': 0.0}))
add_pattern(p, ChangeSet({'id' : 'pa0', 'factors': [1.0, 2.0, 3.0]}))
set_curve(p, ChangeSet({'id' : 'c0', 'coords': [{'x': 1.0, 'y': 2.0}, {'x': 2.0, 'y': 1.0}]}))
add_curve(p, ChangeSet({'id' : 'c0', 'c_type' : CURVE_TYPE_PUMP, 'coords': [{'x': 1.0, 'y': 2.0}, {'x': 2.0, 'y': 1.0}]}))
cs = set_pump_energy(p, ChangeSet({'pump' : 'p0'})).operations[0]
assert cs['operation'] == API_UPDATE