Skip to content

Commit ac26b2f

Browse files
committed
fix: tests now illustrate the query versus transform idioms
1 parent 3de6ca2 commit ac26b2f

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

test/subgraph_global_local.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,10 @@ void test_descriptor_conversion()
102102
BOOST_TEST(!g1a.find_edge(e12).second);
103103
}
104104

105-
// invariant: global_to_local on an edge that is not in the subgraph must return
106-
// a default-constructed descriptor rather than dereferencing a missing map entry.
105+
// idiom: find_edge is the membership query; global_to_local is the transform to
106+
// run once membership is confirmed.
107107
template < typename Directedness >
108-
void test_absent_edge_returns_default()
108+
void test_membership_query_then_convert()
109109
{
110110
using graph_t = subgraph_of< Directedness >;
111111
using edge_t = typename graph_traits< graph_t >::edge_descriptor;
@@ -119,15 +119,23 @@ void test_absent_edge_returns_default()
119119
add_vertex(1, sg);
120120
add_vertex(2, sg);
121121

122-
edge_t e01 = edge(0, 1, root).first; // in root, absent from sg
123-
BOOST_TEST(sg.global_to_local(e01) == edge_t());
122+
// Present edge: the query confirms membership, then the transform agrees
123+
// with the local descriptor the query returned.
124+
edge_t e12 = edge(1, 2, root).first;
125+
std::pair< edge_t, bool > found = sg.find_edge(e12);
126+
BOOST_TEST(found.second);
127+
BOOST_TEST(sg.global_to_local(e12) == found.first);
128+
129+
// Absent edge: the query reports it, so the transform is not run.
130+
edge_t e01 = edge(0, 1, root).first;
131+
BOOST_TEST(!sg.find_edge(e01).second);
124132
}
125133

126134
int main()
127135
{
128136
test_descriptor_conversion< directedS >();
129137
test_descriptor_conversion< bidirectionalS >();
130-
test_absent_edge_returns_default< directedS >();
131-
test_absent_edge_returns_default< bidirectionalS >();
138+
test_membership_query_then_convert< directedS >();
139+
test_membership_query_then_convert< bidirectionalS >();
132140
return boost::report_errors();
133141
}

0 commit comments

Comments
 (0)