|
| 1 | +import numpy as np |
| 2 | +import openpnm as op |
| 3 | + |
| 4 | + |
| 5 | +class DelaunayGabrielTest: |
| 6 | + def setup_class(self): |
| 7 | + pass |
| 8 | + |
| 9 | + def teardown_class(self): |
| 10 | + pass |
| 11 | + |
| 12 | + def test_delaunay_square_with_2D_points(self): |
| 13 | + np.random.seed(0) |
| 14 | + pts = np.random.rand(50, 2) |
| 15 | + tri = op.network.Delaunay(points=pts, shape=[1, 1, 0]) |
| 16 | + assert tri.coords.shape == (50, 3) |
| 17 | + assert np.all(tri.coords[:, :2] == pts) |
| 18 | + |
| 19 | + def test_delaunay_square_with_3D_points(self): |
| 20 | + np.random.seed(0) |
| 21 | + pts = np.random.rand(50, 3) |
| 22 | + tri = op.network.Delaunay(points=pts, shape=[1, 1, 0]) |
| 23 | + assert tri.coords.shape == (50, 3) |
| 24 | + assert np.all(tri.coords[:, :2] == pts[:, :2]) |
| 25 | + assert np.all(tri.coords[:, -1] != pts[:, -1]) |
| 26 | + assert np.all(tri.coords[:, -1] == 0.0) |
| 27 | + |
| 28 | + def test_delaunay_cube_with_points(self): |
| 29 | + np.random.seed(0) |
| 30 | + pts = np.random.rand(50, 3) |
| 31 | + tri = op.network.Delaunay(points=pts, shape=[1, 1, 1]) |
| 32 | + assert tri.coords.shape == (50, 3) |
| 33 | + assert np.all(tri.coords == pts) |
| 34 | + |
| 35 | + def test_delaunay_disk_with_2D_points(self): |
| 36 | + np.random.seed(0) |
| 37 | + pts = np.random.rand(50, 2) |
| 38 | + tri = op.network.Delaunay(points=pts, shape=[1, 0]) |
| 39 | + assert tri.coords.shape == (50, 3) |
| 40 | + assert np.all(tri.coords[:, :2] == pts[:, :2]) |
| 41 | + assert np.all(tri.coords[:, -1] != pts[:, -1]) |
| 42 | + assert np.all(tri.coords[:, -1] == 0.0) |
| 43 | + |
| 44 | + def test_delaunay_disk_with_3D_points(self): |
| 45 | + np.random.seed(0) |
| 46 | + pts = np.random.rand(50, 3) |
| 47 | + tri = op.network.Delaunay(points=pts, shape=[1, 1]) |
| 48 | + assert tri.coords.shape == (50, 3) |
| 49 | + assert np.all(tri.coords == pts) |
| 50 | + |
| 51 | + def test_delaunay_cylinder_with_points(self): |
| 52 | + np.random.seed(0) |
| 53 | + pts = np.random.rand(50, 3) |
| 54 | + tri = op.network.Delaunay(points=pts, shape=[1, 1]) |
| 55 | + assert tri.coords.shape == (50, 3) |
| 56 | + assert np.all(tri.coords == pts) |
| 57 | + |
| 58 | + |
| 59 | +if __name__ == '__main__': |
| 60 | + |
| 61 | + t = DelaunayGabrielTest() |
| 62 | + t.setup_class() |
| 63 | + self = t |
| 64 | + for item in t.__dir__(): |
| 65 | + if item.startswith('test'): |
| 66 | + print('running test: '+item) |
| 67 | + t.__getattribute__(item)() |
0 commit comments