|
| 1 | +from compas.datastructures import HashTree |
| 2 | +from compas.datastructures import Mesh |
| 3 | + |
| 4 | + |
| 5 | +def test_hashtree_from_dict(): |
| 6 | + |
| 7 | + tree1 = HashTree.from_dict({"a": {"b": 1, "c": 3}, "d": [1, 2, 3], "e": 2}) |
| 8 | + tree2 = HashTree.from_dict({"a": {"b": 1, "c": 2}, "d": [1, 2, 3], "f": 2}) |
| 9 | + diff = tree2.diff(tree1) |
| 10 | + |
| 11 | + assert diff["added"] == [{"path": ".f", "value": 2}] |
| 12 | + assert diff["removed"] == [{"path": ".e", "value": 2}] |
| 13 | + assert diff["modified"] == [{"path": ".a.c", "old": 3, "new": 2}] |
| 14 | + |
| 15 | + |
| 16 | +def test_hashtree_from_mesh(): |
| 17 | + mesh = Mesh.from_polyhedron(4) |
| 18 | + tree1 = HashTree.from_dict(mesh.__data__) |
| 19 | + mesh.vertex_attribute(0, "x", 1.0) |
| 20 | + mesh.delete_face(3) |
| 21 | + tree2 = HashTree.from_dict(mesh.__data__) |
| 22 | + diff = tree2.diff(tree1) |
| 23 | + |
| 24 | + assert diff["added"] == [] |
| 25 | + assert diff["removed"] == [{"path": ".face.3", "value": [1, 3, 2]}, {"path": ".facedata.3", "value": None}] |
| 26 | + assert diff["modified"] == [{"path": ".vertex.0.x", "old": -0.8164965809277261, "new": 1.0}] |
0 commit comments