@@ -63,3 +63,104 @@ def test_default_cell_attributes():
6363 assert he .cell_attribute (cell , name = 'b' ) == 2
6464 he .cell_attribute (cell , name = 'a' , value = 3 )
6565 assert he .cell_attribute (cell , name = 'a' ) == 3
66+
67+
68+ # ==============================================================================
69+ # Tests - Vertex Queries
70+ # ==============================================================================
71+
72+ def test_vertices_where ():
73+ hf = HalfFace (default_vertex_attributes = {'a' : 1 , 'b' : 2 })
74+ hf .add_vertex (0 )
75+ hf .add_vertex (1 , {'a' : 5 })
76+ hf .add_vertex (2 , {'a' : 5 , 'b' : 10 })
77+ assert list (hf .vertices_where ({'a' : 5 })) == [1 , 2 ]
78+ assert list (hf .vertices_where ({'a' : 1 , 'b' : 2 }))[0 ] == 0
79+
80+
81+ def test_vertices_where_predicate ():
82+ hf = HalfFace (default_vertex_attributes = {'a' : 1 , 'b' : 2 })
83+ hf .add_vertex (0 )
84+ hf .add_vertex (1 , {'a' : 5 , 'b' : 10 })
85+ hf .add_vertex (2 , {'a' : 15 , 'b' : 20 })
86+ assert list (hf .vertices_where_predicate (
87+ lambda v , attr : attr ['b' ] - attr ['a' ] == 5 )) == [1 , 2 ]
88+
89+
90+ # ==============================================================================
91+ # Tests - Edge Queries
92+ # ==============================================================================
93+
94+ def test_edges_where ():
95+ hf = HalfFace (default_edge_attributes = {'a' : 1 , 'b' : 2 })
96+ for vkey in range (3 ):
97+ hf .add_vertex (vkey )
98+ hf .add_halfface ([0 , 1 , 2 ])
99+ hf .edge_attribute ((0 , 1 ), 'a' , 5 )
100+ assert list (hf .edges_where ({'a' : 1 })) == [(1 , 2 ), (2 , 0 )]
101+
102+
103+ def test_edges_where_predicate ():
104+ hf = HalfFace (default_edge_attributes = {'a' : 1 , 'b' : 2 })
105+ for vkey in range (3 ):
106+ hf .add_vertex (vkey )
107+ hf .add_halfface ([0 , 1 , 2 ])
108+ hf .edge_attribute ((0 , 1 ), 'a' , 5 )
109+ assert list (hf .edges_where_predicate (
110+ lambda e , attr : attr ['a' ] - attr ['b' ] == 3 ))[0 ] == (0 , 1 )
111+
112+
113+ # ==============================================================================
114+ # Tests - Face Queries
115+ # ==============================================================================
116+
117+ def test_faces_where ():
118+ hf = HalfFace (default_face_attributes = {'a' : 1 , 'b' : 2 })
119+ for vkey in range (4 ):
120+ hf .add_vertex (vkey )
121+ for i in range (3 ):
122+ hf .add_halfface ([i , i + 1 , i + 2 ])
123+ hf .face_attribute (1 , 'a' , 5 )
124+ assert list (hf .faces_where ({'a' : 1 })) == [0 , 2 ]
125+
126+
127+ def test_faces_where_predicate ():
128+ hf = HalfFace (default_face_attributes = {'a' : 1 , 'b' : 2 })
129+ for vkey in range (4 ):
130+ hf .add_vertex (vkey )
131+ for i in range (3 ):
132+ hf .add_halfface ([i , i + 1 , i + 2 ])
133+ hf .face_attribute (1 , 'a' , 5 )
134+ assert list (hf .faces_where_predicate (
135+ lambda e , attr : attr ['a' ] - attr ['b' ] == 3 ))[0 ] == 1
136+
137+
138+ # ==============================================================================
139+ # Tests - Cell Queries
140+ # ==============================================================================
141+
142+ def test_cells_where ():
143+ hf = HalfFace (default_cell_attributes = {'a' : 1 , 'b' : 2 })
144+ for vkey in range (5 ):
145+ hf .add_vertex (vkey )
146+ for i in range (3 ):
147+ hf .add_cell ([[i , i + 1 , i + 2 ],
148+ [i , i + 1 , i + 3 ],
149+ [i + 1 , i + 2 , i + 3 ],
150+ [i + 2 , i + 3 , i ]])
151+ hf .cell_attribute (1 , 'a' , 5 )
152+ assert list (hf .cells_where ({'a' : 1 })) == [0 , 2 ]
153+
154+
155+ def test_cells_where_predicate ():
156+ hf = HalfFace (default_cell_attributes = {'a' : 1 , 'b' : 2 })
157+ for vkey in range (5 ):
158+ hf .add_vertex (vkey )
159+ for i in range (3 ):
160+ hf .add_cell ([[i , i + 1 , i + 2 ],
161+ [i , i + 1 , i + 3 ],
162+ [i + 1 , i + 2 , i + 3 ],
163+ [i + 2 , i + 3 , i ]])
164+ hf .cell_attribute (1 , 'a' , 5 )
165+ assert list (hf .cells_where_predicate (
166+ lambda e , attr : attr ['a' ] - attr ['b' ] == 3 ))[0 ] == 1
0 commit comments