Skip to content

Commit ccacea1

Browse files
fabianmurariugithub-actions[bot]miratepuffin
authored
Indexed node additions and moves tests into separate raphtory/tests (#2289)
* move raphtory tests into raphtory/tests/ * break away proto and df loaders tests * import Materialized graph * bring debug symbols back and remove some of the warnings from the new tests * missing use * fixed comments on PR * chore: apply tidy-public auto-fixes --------- Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Ben Steer <[email protected]>
1 parent fe847d7 commit ccacea1

File tree

99 files changed

+25755
-25814
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+25755
-25814
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ edition = "2021"
3030
# debug symbols are using a lot of resources
3131
[profile.dev]
3232
split-debuginfo = "unpacked"
33-
debug = false
33+
debug = true
3434

3535
[profile.release-with-debug]
3636
inherits = "release"

pometry-storage-private

raphtory-api/src/core/entities/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ impl GID {
225225
}
226226
}
227227

228-
pub fn to_str(&self) -> Cow<str> {
228+
pub fn to_str(&'_ self) -> Cow<'_, str> {
229229
match self {
230230
GID::U64(v) => Cow::Owned(v.to_string()),
231231
GID::Str(v) => Cow::Borrowed(v),

raphtory-storage/src/disk/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ pub struct DiskGraphStorage {
4949
graph_props: Arc<GraphMeta>,
5050
}
5151

52+
impl From<TemporalGraph> for DiskGraphStorage {
53+
fn from(value: TemporalGraph) -> Self {
54+
Self::new(value)
55+
}
56+
}
57+
5258
impl Serialize for DiskGraphStorage {
5359
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
5460
where

raphtory-storage/src/graph/graph.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,13 @@ impl From<TemporalGraph> for GraphStorage {
4848
}
4949
}
5050

51+
#[cfg(feature = "storage")]
52+
impl From<DiskGraphStorage> for GraphStorage {
53+
fn from(value: DiskGraphStorage) -> Self {
54+
Self::Disk(Arc::new(value))
55+
}
56+
}
57+
5158
impl Default for GraphStorage {
5259
fn default() -> Self {
5360
GraphStorage::Unlocked(Arc::new(TemporalGraph::default()))

raphtory/src/algorithms/centrality/betweenness.rs

Lines changed: 0 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -99,54 +99,3 @@ pub fn betweenness_centrality<'graph, G: GraphViewOps<'graph>>(
9999

100100
NodeState::new_from_eval(g.clone(), betweenness)
101101
}
102-
103-
#[cfg(test)]
104-
mod betweenness_centrality_test {
105-
use super::*;
106-
use crate::{prelude::*, test_storage};
107-
108-
#[test]
109-
fn test_betweenness_centrality() {
110-
let graph = Graph::new();
111-
let vs = vec![
112-
(1, 2),
113-
(1, 3),
114-
(1, 4),
115-
(2, 3),
116-
(2, 4),
117-
(2, 5),
118-
(3, 4),
119-
(3, 5),
120-
(3, 6),
121-
(4, 3),
122-
(4, 2),
123-
(4, 4),
124-
];
125-
for (src, dst) in &vs {
126-
graph.add_edge(0, *src, *dst, NO_PROPS, None).unwrap();
127-
}
128-
129-
test_storage!(&graph, |graph| {
130-
let mut expected: HashMap<String, f64> = HashMap::new();
131-
expected.insert("1".to_string(), 0.0);
132-
expected.insert("2".to_string(), 1.0);
133-
expected.insert("3".to_string(), 4.0);
134-
expected.insert("4".to_string(), 1.0);
135-
expected.insert("5".to_string(), 0.0);
136-
expected.insert("6".to_string(), 0.0);
137-
138-
let res = betweenness_centrality(graph, None, false);
139-
assert_eq!(res, expected);
140-
141-
let mut expected: HashMap<String, f64> = HashMap::new();
142-
expected.insert("1".to_string(), 0.0);
143-
expected.insert("2".to_string(), 0.05);
144-
expected.insert("3".to_string(), 0.2);
145-
expected.insert("4".to_string(), 0.05);
146-
expected.insert("5".to_string(), 0.0);
147-
expected.insert("6".to_string(), 0.0);
148-
let res = betweenness_centrality(graph, None, true);
149-
assert_eq!(res, expected);
150-
});
151-
}
152-
}

raphtory/src/algorithms/centrality/degree_centrality.rs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,33 +30,3 @@ pub fn degree_centrality<G: StaticGraphViewOps>(g: &G) -> NodeState<'static, f64
3030

3131
NodeState::new_from_values(g.clone(), values)
3232
}
33-
34-
#[cfg(test)]
35-
mod degree_centrality_test {
36-
use crate::{
37-
algorithms::centrality::degree_centrality::degree_centrality,
38-
db::{api::mutation::AdditionOps, graph::graph::Graph},
39-
prelude::NO_PROPS,
40-
test_storage,
41-
};
42-
use std::collections::HashMap;
43-
44-
#[test]
45-
fn test_degree_centrality() {
46-
let graph = Graph::new();
47-
let vs = vec![(1, 2), (1, 3), (1, 4), (2, 3), (2, 4)];
48-
for (src, dst) in &vs {
49-
graph.add_edge(0, *src, *dst, NO_PROPS, None).unwrap();
50-
}
51-
test_storage!(&graph, |graph| {
52-
let mut expected: HashMap<String, f64> = HashMap::new();
53-
expected.insert("1".to_string(), 1.0);
54-
expected.insert("2".to_string(), 1.0);
55-
expected.insert("3".to_string(), 2.0 / 3.0);
56-
expected.insert("4".to_string(), 2.0 / 3.0);
57-
58-
let res = degree_centrality(graph);
59-
assert_eq!(res, expected);
60-
});
61-
}
62-
}

raphtory/src/algorithms/centrality/hits.rs

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -150,62 +150,3 @@ pub fn hits<G: StaticGraphViewOps>(
150150
None,
151151
)
152152
}
153-
154-
#[cfg(test)]
155-
mod hits_tests {
156-
use crate::{
157-
db::{api::mutation::AdditionOps, graph::graph::Graph},
158-
prelude::NO_PROPS,
159-
test_storage,
160-
};
161-
use std::collections::HashMap;
162-
163-
use super::*;
164-
165-
fn load_graph(edges: Vec<(u64, u64)>) -> Graph {
166-
let graph = Graph::new();
167-
168-
for (src, dst) in edges {
169-
graph.add_edge(0, src, dst, NO_PROPS, None).unwrap();
170-
}
171-
graph
172-
}
173-
174-
#[test]
175-
fn test_hits() {
176-
let graph = load_graph(vec![
177-
(1, 4),
178-
(2, 3),
179-
(2, 5),
180-
(3, 1),
181-
(4, 2),
182-
(4, 3),
183-
(5, 2),
184-
(5, 3),
185-
(5, 4),
186-
(5, 6),
187-
(6, 3),
188-
(6, 8),
189-
(7, 1),
190-
(7, 3),
191-
(8, 1),
192-
]);
193-
test_storage!(&graph, |graph| {
194-
let results = hits(graph, 20, None);
195-
196-
assert_eq!(
197-
results,
198-
HashMap::from([
199-
("1".to_string(), (0.0431365, 0.096625775)),
200-
("2".to_string(), (0.14359662, 0.18366566)),
201-
("3".to_string(), (0.030866561, 0.36886504)),
202-
("4".to_string(), (0.1865414, 0.12442485)),
203-
("5".to_string(), (0.26667944, 0.05943252)),
204-
("6".to_string(), (0.14359662, 0.10755368)),
205-
("7".to_string(), (0.15471625, 0.0)),
206-
("8".to_string(), (0.030866561, 0.05943252))
207-
])
208-
);
209-
});
210-
}
211-
}

raphtory/src/algorithms/centrality/pagerank.rs

Lines changed: 0 additions & 191 deletions
Original file line numberDiff line numberDiff line change
@@ -168,194 +168,3 @@ pub fn unweighted_page_rank<G: StaticGraphViewOps>(
168168
None,
169169
)
170170
}
171-
172-
#[cfg(test)]
173-
pub mod page_rank_tests {
174-
use super::*;
175-
use crate::{
176-
db::{api::mutation::AdditionOps, graph::graph::Graph},
177-
prelude::{NodeStateOps, NO_PROPS},
178-
test_storage,
179-
};
180-
use itertools::Itertools;
181-
use pretty_assertions::assert_eq;
182-
use std::borrow::Borrow;
183-
184-
fn load_graph() -> Graph {
185-
let graph = Graph::new();
186-
187-
let edges = vec![(1, 2), (1, 4), (2, 3), (3, 1), (4, 1)];
188-
189-
for (src, dst) in edges {
190-
graph.add_edge(0, src, dst, NO_PROPS, None).unwrap();
191-
}
192-
graph
193-
}
194-
195-
#[test]
196-
fn test_page_rank() {
197-
let graph = load_graph();
198-
199-
test_storage!(&graph, |graph| {
200-
let results = unweighted_page_rank(graph, Some(1000), Some(1), None, true, None);
201-
202-
assert_eq_f64(results.get_by_node("1"), Some(&0.38694), 5);
203-
assert_eq_f64(results.get_by_node("2"), Some(&0.20195), 5);
204-
assert_eq_f64(results.get_by_node("4"), Some(&0.20195), 5);
205-
assert_eq_f64(results.get_by_node("3"), Some(&0.20916), 5);
206-
});
207-
}
208-
209-
#[test]
210-
fn motif_page_rank() {
211-
let edges = vec![
212-
(1, 2, 1),
213-
(1, 3, 2),
214-
(1, 4, 3),
215-
(3, 1, 4),
216-
(3, 4, 5),
217-
(3, 5, 6),
218-
(4, 5, 7),
219-
(5, 6, 8),
220-
(5, 8, 9),
221-
(7, 5, 10),
222-
(8, 5, 11),
223-
(1, 9, 12),
224-
(9, 1, 13),
225-
(6, 3, 14),
226-
(4, 8, 15),
227-
(8, 3, 16),
228-
(5, 10, 17),
229-
(10, 5, 18),
230-
(10, 8, 19),
231-
(1, 11, 20),
232-
(11, 1, 21),
233-
(9, 11, 22),
234-
(11, 9, 23),
235-
];
236-
237-
let graph = Graph::new();
238-
239-
for (src, dst, t) in edges {
240-
graph.add_edge(t, src, dst, NO_PROPS, None).unwrap();
241-
}
242-
243-
test_storage!(&graph, |graph| {
244-
let results = unweighted_page_rank(graph, Some(1000), Some(4), None, true, None);
245-
246-
assert_eq_f64(results.get_by_node("10"), Some(&0.072082), 5);
247-
assert_eq_f64(results.get_by_node("8"), Some(&0.136473), 5);
248-
assert_eq_f64(results.get_by_node("3"), Some(&0.15484), 5);
249-
assert_eq_f64(results.get_by_node("6"), Some(&0.07208), 5);
250-
assert_eq_f64(results.get_by_node("11"), Some(&0.06186), 5);
251-
assert_eq_f64(results.get_by_node("2"), Some(&0.03557), 5);
252-
assert_eq_f64(results.get_by_node("1"), Some(&0.11284), 5);
253-
assert_eq_f64(results.get_by_node("4"), Some(&0.07944), 5);
254-
assert_eq_f64(results.get_by_node("7"), Some(&0.01638), 5);
255-
assert_eq_f64(results.get_by_node("9"), Some(&0.06186), 5);
256-
assert_eq_f64(results.get_by_node("5"), Some(&0.19658), 5);
257-
});
258-
}
259-
260-
#[test]
261-
fn two_nodes_page_rank() {
262-
let edges = vec![(1, 2), (2, 1)];
263-
264-
let graph = Graph::new();
265-
266-
for (t, (src, dst)) in edges.into_iter().enumerate() {
267-
graph.add_edge(t as i64, src, dst, NO_PROPS, None).unwrap();
268-
}
269-
270-
test_storage!(&graph, |graph| {
271-
let results = unweighted_page_rank(graph, Some(1000), Some(4), None, false, None);
272-
273-
assert_eq_f64(results.get_by_node("1"), Some(&0.5), 3);
274-
assert_eq_f64(results.get_by_node("2"), Some(&0.5), 3);
275-
});
276-
}
277-
278-
#[test]
279-
fn three_nodes_page_rank_one_dangling() {
280-
let edges = vec![(1, 2), (2, 1), (2, 3)];
281-
282-
let graph = Graph::new();
283-
284-
for (t, (src, dst)) in edges.into_iter().enumerate() {
285-
graph.add_edge(t as i64, src, dst, NO_PROPS, None).unwrap();
286-
}
287-
288-
test_storage!(&graph, |graph| {
289-
let results = unweighted_page_rank(graph, Some(10), Some(4), None, false, None);
290-
291-
assert_eq_f64(results.get_by_node("1"), Some(&0.303), 3);
292-
assert_eq_f64(results.get_by_node("2"), Some(&0.393), 3);
293-
assert_eq_f64(results.get_by_node("3"), Some(&0.303), 3);
294-
});
295-
}
296-
297-
#[test]
298-
fn dangling_page_rank() {
299-
let edges = vec![
300-
(1, 2),
301-
(1, 3),
302-
(2, 3),
303-
(3, 1),
304-
(3, 2),
305-
(3, 4),
306-
// dangling from here
307-
(4, 5),
308-
(5, 6),
309-
(6, 7),
310-
(7, 8),
311-
(8, 9),
312-
(9, 10),
313-
(10, 11),
314-
]
315-
.into_iter()
316-
.enumerate()
317-
.map(|(t, (src, dst))| (src, dst, t as i64))
318-
.collect_vec();
319-
320-
let graph = Graph::new();
321-
322-
for (src, dst, t) in edges {
323-
graph.add_edge(t, src, dst, NO_PROPS, None).unwrap();
324-
}
325-
test_storage!(&graph, |graph| {
326-
let results = unweighted_page_rank(graph, Some(1000), Some(4), None, true, None);
327-
328-
assert_eq_f64(results.get_by_node("1"), Some(&0.055), 3);
329-
assert_eq_f64(results.get_by_node("2"), Some(&0.079), 3);
330-
assert_eq_f64(results.get_by_node("3"), Some(&0.113), 3);
331-
assert_eq_f64(results.get_by_node("4"), Some(&0.055), 3);
332-
assert_eq_f64(results.get_by_node("5"), Some(&0.070), 3);
333-
assert_eq_f64(results.get_by_node("6"), Some(&0.083), 3);
334-
assert_eq_f64(results.get_by_node("7"), Some(&0.093), 3);
335-
assert_eq_f64(results.get_by_node("8"), Some(&0.102), 3);
336-
assert_eq_f64(results.get_by_node("9"), Some(&0.110), 3);
337-
assert_eq_f64(results.get_by_node("10"), Some(&0.117), 3);
338-
assert_eq_f64(results.get_by_node("11"), Some(&0.122), 3);
339-
});
340-
}
341-
342-
pub fn assert_eq_f64<T: Borrow<f64> + PartialEq + std::fmt::Debug>(
343-
a: Option<T>,
344-
b: Option<T>,
345-
decimals: u8,
346-
) {
347-
if a.is_none() || b.is_none() {
348-
assert_eq!(a, b);
349-
} else {
350-
let factor = 10.0_f64.powi(decimals as i32);
351-
match (a, b) {
352-
(Some(a), Some(b)) => {
353-
let left = (a.borrow() * factor).round();
354-
let right = (b.borrow() * factor).round();
355-
assert_eq!(left, right,);
356-
}
357-
_ => unreachable!(),
358-
}
359-
}
360-
}
361-
}

0 commit comments

Comments
 (0)