Skip to content

Commit 72ea87b

Browse files
committed
Removed 'TwoVerticesIn' in favor of 'VertexInGraph<_,2,_>'.
1 parent 946c81d commit 72ea87b

File tree

10 files changed

+70
-269
lines changed

10 files changed

+70
-269
lines changed

src/algo/tarjan_scc.rs

-1
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,6 @@ where
293293
/// This is similar to `next`, however can be used when `TarjanScc` receives
294294
/// a non-copy ensure.
295295
///
296-
///
297296
pub fn next_scc(&mut self) -> Option<ConnectedGraph<SubgraphProxy<&G::Graph>>>
298297
{
299298
next_scc_impl!(self, .graph())

tests/common/adjacency_list/impl_graph.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use crate::{
44
common::adjacency_list::adj_list_from_mock,
55
mock_graph::{
6-
arbitrary::{Arb, EdgeIn, TwoVerticesIn},
6+
arbitrary::{Arb, EdgeIn},
77
utilities::unordered_equivalent_lists_equal,
88
MockGraph,
99
},
@@ -65,9 +65,10 @@ mod __
6565
/// Tests that when we create an AdjListGraph from a MockGraph,
6666
/// any edge in the mock is in the AdjListGraph
6767
#[quickcheck]
68-
fn edges_between(Arb(mock): Arb<TwoVerticesIn<MockGraph<directedness>>>) -> bool
68+
fn edges_between(Arb(mock): Arb<VertexInGraph<MockGraph<directedness>, 2, false>>) -> bool
6969
{
70-
let (v1, v2) = mock.get_both();
70+
let v1 = mock.vertex_at::<0>();
71+
let v2 = mock.vertex_at::<1>();
7172
let mock = mock.0.release_all();
7273
let (g, v_map) = adj_list_from_mock(&mock);
7374

@@ -80,9 +81,10 @@ mod __
8081
/// Tests that `edges_between_mut` returns the same edges as its immutable
8182
/// version
8283
#[quickcheck]
83-
fn edges_between_mut(Arb(mock): Arb<TwoVerticesIn<MockGraph<directedness>>>) -> bool
84+
fn edges_between_mut(Arb(mock): Arb<VertexInGraph<MockGraph<directedness>, 2, false>>) -> bool
8485
{
85-
let (v1, v2) = mock.get_both();
86+
let v1 = mock.vertex_at::<0>();
87+
let v2 = mock.vertex_at::<1>();
8688
let mock = mock.0.release_all();
8789
let (mut g, v_map) = adj_list_from_mock(&mock);
8890

tests/core/graph/edge_lookup_methods.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use graphene::core::{
1010
Directed, Edge, Graph, Release, Undirected,
1111
};
1212

13-
use crate::mock_graph::arbitrary::{Arb, TwoVerticesIn};
13+
use crate::mock_graph::arbitrary::Arb;
1414

1515
#[duplicate_item(
1616
duplicate!{
@@ -37,7 +37,7 @@ use crate::mock_graph::arbitrary::{Arb, TwoVerticesIn};
3737
vertices_init [ let v = g.vertex_at::<0>().clone() ]
3838
vertices_init_invalid [ let v = g.1 ]
3939
closure [ |e| if closure_nested {Some((e.other(v),e.2))} else {None} ]
40-
arb_graph [ VertexInGraph ]
40+
arb_graph(G) [ VertexInGraph<G, 1, true> ]
4141
arb_invalid_graph [ VertexOutside ]
4242
base_graph [ MockGraph<directedness_nested> ]
4343
]
@@ -52,7 +52,10 @@ use crate::mock_graph::arbitrary::{Arb, TwoVerticesIn};
5252
module [module_nested]
5353
method [edges_between]
5454
vertices [ &v, &_v2 ]
55-
vertices_init [let (v, _v2) = g.get_both()]
55+
vertices_init [
56+
let v = g.vertex_at::<0>();
57+
let _v2 = g.vertex_at::<1>()
58+
]
5659
vertices_init_invalid [let v = g.1;let _v2 = g.2]
5760
closure [
5861
|e| {
@@ -63,7 +66,7 @@ use crate::mock_graph::arbitrary::{Arb, TwoVerticesIn};
6366
} else {None}
6467
}
6568
]
66-
arb_graph [ TwoVerticesIn ]
69+
arb_graph(G) [ VertexInGraph<G, 2, false> ]
6770
arb_invalid_graph [ EdgeOutside ]
6871
base_graph [ MockGraph<directedness> ]
6972
]
@@ -75,7 +78,7 @@ mod module
7578

7679
/// Ensures that all edges are returned.
7780
#[quickcheck]
78-
fn returns_all_edges(Arb(g): Arb<arb_graph<base_graph>>) -> bool
81+
fn returns_all_edges(Arb(g): Arb<arb_graph([base_graph])>) -> bool
7982
{
8083
vertices_init;
8184
let g = g.release_all();

tests/core/property/acyclic.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ mod __
5959
weight: MockEdgeWeight,
6060
) -> bool
6161
{
62-
let (v1, v2) = graph.0.get_both();
62+
let v1 = graph.0.vertex_at::<0>();
63+
let v2 = graph.0.vertex_at::<1>();
6364
let edge_count = graph.all_edges().count();
6465

6566
let mut g = AcyclicGraph::guard_unchecked(graph.release_all());

tests/core/property/connectedness.rs

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! Tests the `core::Connected` trait and its ensurer `core::ConnectedGraph`.
22
33
use crate::mock_graph::{
4-
arbitrary::{Arb, TwoVerticesIn, UnconnectedGraph},
4+
arbitrary::{Arb, UnconnectedGraph},
55
MockDirectedness, MockEdgeWeight, MockGraph, MockVertexWeight,
66
};
77
use duplicate::duplicate_item;
@@ -69,11 +69,12 @@ mod module
6969
/// Tests that a graph always accepts adding an edge.
7070
#[quickcheck]
7171
fn accept_add_edge_weighted(
72-
Arb(g): Arb<TwoVerticesIn<arb_connected>>,
72+
Arb(g): Arb<VertexInGraph<arb_connected, 2, false>>,
7373
e_weight: MockEdgeWeight,
7474
) -> bool
7575
{
76-
let (v1, v2) = g.get_both();
76+
let v1 = g.vertex_at::<0>();
77+
let v2 = g.vertex_at::<1>();
7778
let mut g = connected_graph::guard_unchecked(g.release_all());
7879

7980
g.add_edge_weighted(&v1, &v2, e_weight).is_ok()
@@ -83,11 +84,12 @@ mod module
8384
/// for connectedness
8485
#[quickcheck]
8586
fn accept_remove_edge_where_weight(
86-
Arb(g): Arb<TwoVerticesIn<arb_connected>>,
87+
Arb(g): Arb<VertexInGraph<arb_connected, 2, false>>,
8788
e_weight: MockEdgeWeight,
8889
) -> bool
8990
{
90-
let (v1, v2) = g.get_both();
91+
let v1 = g.vertex_at::<0>();
92+
let v2 = g.vertex_at::<1>();
9193
let mut g = connected_graph::guard_unchecked(g.release_all());
9294
// To ensure we can remove an edge, we first create an edge to remove
9395
g.add_edge_weighted(&v1, &v2, e_weight.clone()).unwrap();
@@ -193,14 +195,16 @@ mod module
193195
/// graph unconnected
194196
#[quickcheck]
195197
fn reject_remove_vertex(
196-
Arb(g1): Arb<TwoVerticesIn<arb_reject_remove>>,
197-
Arb(g2): Arb<TwoVerticesIn<arb_reject_remove>>,
198+
Arb(g1): Arb<VertexInGraph<arb_reject_remove, 2, false>>,
199+
Arb(g2): Arb<VertexInGraph<arb_reject_remove, 2, false>>,
198200
e_weight: MockEdgeWeight,
199201
v_weight: MockVertexWeight,
200202
) -> bool
201203
{
202-
let (v11, v12) = g1.get_both();
203-
let (v21, v22) = g2.get_both();
204+
let v11 = g1.vertex_at::<0>();
205+
let v12 = g1.vertex_at::<1>();
206+
let v21 = g2.vertex_at::<0>();
207+
let v22 = g2.vertex_at::<1>();
204208
let mut graph = g1.0.release_all();
205209
// We start by joining 2 connected graphs into a unconnected graph with the 2
206210
// components

tests/core/property/has_vertex_rooted.rs

+15-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
/// Tests `HasVertexGraph`, VertexInGraph`, and `RootedGraph`
2-
use crate::mock_graph::arbitrary::Unique;
3-
use crate::mock_graph::{
4-
arbitrary::{Arb, TwoVerticesIn},
5-
MockGraph, MockVertexWeight,
6-
};
2+
use crate::mock_graph::{arbitrary::Arb, MockGraph, MockVertexWeight};
73
use duplicate::duplicate_item;
84
use graphene::core::{
95
property::{
10-
HasVertex, HasVertexGraph, NewVertex, RemoveVertex, Rooted, RootedGraph, VertexInGraph,
6+
HasVertex, HasVertexGraph, NewVertex, RemoveVertex, Rooted, RootedGraph, VertexIn,
7+
VertexInGraph,
118
},
129
Directed, Undirected,
1310
};
@@ -79,8 +76,9 @@ mod __
7976

8077
/// Tests that can remove a vertex if there are at least 2.
8178
#[quickcheck]
82-
fn accept_remove_vertex(Arb(g): Arb<TwoVerticesIn<MockGraph<directedness>, Unique>>)
83-
-> bool
79+
fn accept_remove_vertex(
80+
Arb(g): Arb<VertexInGraph<MockGraph<directedness>, 2, true>>,
81+
) -> bool
8482
{
8583
let v = g.any_vertex();
8684
let mut g = HasVertexGraph::guard(g.release_all()).unwrap();
@@ -118,10 +116,11 @@ mod __
118116
/// the graph
119117
#[quickcheck]
120118
fn vertex_in_accept_remove_vertex(
121-
Arb(g): Arb<TwoVerticesIn<MockGraph<directedness>, Unique>>,
119+
Arb(g): Arb<VertexInGraph<MockGraph<directedness>, 2, true>>,
122120
) -> bool
123121
{
124-
let (v1, v2) = g.get_both();
122+
let v1 = g.vertex_at::<0>();
123+
let v2 = g.vertex_at::<1>();
125124
let mut g = GraphStruct::ensure_unchecked(g.release_all().0, ensure_wrap([v1]));
126125

127126
g.remove_vertex(v2).is_ok()
@@ -151,9 +150,10 @@ mod __
151150
/// Tests that the graph can change the specific underlying
152151
/// vertex
153152
#[quickcheck]
154-
fn set_vertex(Arb(g): Arb<TwoVerticesIn<MockGraph<directedness>, Unique>>) -> bool
153+
fn set_vertex(Arb(g): Arb<VertexInGraph<MockGraph<directedness>, 2, true>>) -> bool
155154
{
156-
let (v1, v2) = g.get_both();
155+
let v1 = g.vertex_at::<0>();
156+
let v2 = g.vertex_at::<1>();
157157
let mut g = GraphStruct::ensure_unchecked(g.release_all().0, ensure_wrap([v1]));
158158

159159
g.set_method(ensure_wrap([v2])).is_ok() && g.get_method() == v2
@@ -187,10 +187,11 @@ mod __
187187

188188
/// Tests that RootedGraphs `is_root` returns false when not given the root
189189
#[quickcheck]
190-
fn is_root_false(Arb(g): Arb<TwoVerticesIn<MockGraph<directedness>, Unique>>) -> bool
190+
fn is_root_false(Arb(g): Arb<VertexInGraph<MockGraph<directedness>, 2, true>>) -> bool
191191
{
192192
use graphene::core::{Ensure, Release};
193-
let (v1, v2) = g.get_both();
193+
let v1 = g.vertex_at::<0>();
194+
let v2 = g.vertex_at::<1>();
194195
let g = RootedGraph::ensure_unchecked(g.release_all(), v1);
195196

196197
!g.is_root(v2)
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
mod edge_in;
22
mod edge_outside;
33
mod two_reachable_vertices;
4-
mod two_vertices_in;
54
mod vertex_outside;
65
mod vertices_in;
76

87
pub use self::{
9-
edge_in::*, edge_outside::*, two_reachable_vertices::*, two_vertices_in::*, vertex_outside::*,
10-
vertices_in::*,
8+
edge_in::*, edge_outside::*, two_reachable_vertices::*, vertex_outside::*, vertices_in::*,
119
};

tests/mock_graph/arbitrary/combinations/two_reachable_vertices.rs

+18-20
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use crate::mock_graph::{
2-
arbitrary::{GuidedArbGraph, Limit, NonUnique, TwoVerticesIn, Uniqueness},
2+
arbitrary::{GuidedArbGraph, Limit},
33
MockType, TestGraph,
44
};
55
use graphene::{
66
algo::{Bfs, Dfs},
77
core::{
8-
property::{AddEdge, RemoveEdge, VertexInGraph},
8+
property::{AddEdge, RemoveEdge, VertexIn, VertexInGraph},
99
Ensure, Graph, GraphDerefMut, Release,
1010
},
1111
impl_ensurer,
@@ -16,35 +16,34 @@ use std::{collections::HashSet, fmt::Debug};
1616

1717
/// An arbitrary graph and two vertices in it.
1818
///
19+
/// Guarantees that the second vertex is reachable from the first.
20+
///
1921
/// Depending on `U`, the two vertices are either allowed to be the same
2022
/// (`NonUnique`, default), or they must be unique (`Unique`).
2123
///
2224
/// Note: All graphs will have at least 1 vertex for non-unique and 2 vertices
2325
/// for unique, meaning this type never includes the empty graph.
2426
#[derive(Clone, Debug)]
25-
pub struct TwoReachableVerticesIn<G, U = NonUnique>(pub TwoVerticesIn<G, U>)
27+
pub struct TwoReachableVerticesIn<G, const UNIQUE: bool = false>(pub VertexInGraph<G, 2, UNIQUE>)
2628
where
2729
G: GuidedArbGraph,
2830
G::Graph: TestGraph,
29-
<G::Graph as Graph>::EdgeWeight: MockType,
30-
U: Uniqueness;
31+
<G::Graph as Graph>::EdgeWeight: MockType;
3132

3233
impl_ensurer! {
33-
use<G,U> TwoReachableVerticesIn<G,U>
34-
as (self.0): TwoVerticesIn<G,U>
34+
use<G; const U: bool> TwoReachableVerticesIn<G,U>
35+
as (self.0): VertexInGraph<G, 2, U>
3536
where
3637
G: GuidedArbGraph,
3738
G::Graph: TestGraph,
3839
<G::Graph as Graph>::EdgeWeight: MockType,
39-
U: Uniqueness
4040
}
4141

42-
impl<Gr, U> GuidedArbGraph for TwoReachableVerticesIn<Gr, U>
42+
impl<Gr, const U: bool> GuidedArbGraph for TwoReachableVerticesIn<Gr, U>
4343
where
4444
Gr: GuidedArbGraph + GraphDerefMut,
4545
Gr::Graph: TestGraph + RemoveEdge + AddEdge,
4646
<Gr::Graph as Graph>::EdgeWeight: MockType,
47-
U: 'static + Uniqueness,
4847
{
4948
fn choose_size<G: Gen>(
5049
g: &mut G,
@@ -58,15 +57,13 @@ where
5857

5958
// we need at least 1 edge. We'll delegate to TwoVerticesIn to ensure we get
6059
// at least 1 or 2 vertices (depending on U).
61-
TwoVerticesIn::<Gr, U>::choose_size(g, v_min, v_max, std::cmp::max(e_min, 1), e_max)
60+
VertexInGraph::<Gr, 2, U>::choose_size(g, v_min, v_max, std::cmp::max(e_min, 1), e_max)
6261
}
6362

6463
fn arbitrary_fixed<G: Gen>(g: &mut G, v_count: usize, e_count: usize) -> Self
6564
{
6665
// Create a graph with at least 1 or 2 vertices (1 for non-unique, 2 for Unique)
67-
let graph = TwoVerticesIn::<Gr, U>::arbitrary_fixed(g, v_count, e_count)
68-
.release()
69-
.release();
66+
let graph = VertexInGraph::<Gr, 2, U>::arbitrary_fixed(g, v_count, e_count).release();
7067

7168
let mut vert_reachables: Vec<_> = graph
7269
.graph()
@@ -81,7 +78,7 @@ where
8178
graph.graph(),
8279
[v.clone()],
8380
)));
84-
if !U::unique() && graph.graph().edges_between(v.clone(), v.clone()).count() > 0
81+
if !U && graph.graph().edges_between(v.clone(), v.clone()).count() > 0
8582
{
8683
reachable.push(v.clone());
8784
}
@@ -100,13 +97,14 @@ where
10097
// Choose a vertex that ends the path
10198
let v2 = reachable[g.gen_range(0, reachable.len())];
10299

103-
Self(TwoVerticesIn::new(graph, v1.clone(), v2))
100+
Self(VertexInGraph::ensure_unchecked(graph, [v1.clone(), v2]))
104101
}
105102

106103
fn shrink_guided(&self, mut limits: HashSet<Limit>) -> Box<dyn Iterator<Item = Self>>
107104
{
108105
let mut result: Vec<Self> = Vec::new();
109-
let (v1, v2) = self.0.get_both();
106+
let v1 = self.0.vertex_at::<0>();
107+
let v2 = self.0.vertex_at::<1>();
110108

111109
// First find a path between the vertices
112110
let g = VertexInGraph::ensure_unchecked(self, [v1]);
@@ -137,7 +135,7 @@ where
137135
clone
138136
.0
139137
.shrink_guided(limits)
140-
.map(|g| Self(TwoVerticesIn::new(g.release(), v1, v2)))
138+
.map(|g| Self(VertexInGraph::ensure_unchecked(g, [v1, v2])))
141139
});
142140

143141
// Shrink by either removing superfluous edges from last link
@@ -168,8 +166,8 @@ where
168166
{
169167
g.add_edge_weighted(v1, v1, w).unwrap();
170168
}
171-
g.1 = v2;
172-
result.push(Self(g));
169+
let g = g.release();
170+
result.push(Self(VertexInGraph::ensure_unchecked(g, [v1, v2])));
173171
}
174172
Box::new(result.into_iter())
175173
}

0 commit comments

Comments
 (0)