Skip to content
This repository was archived by the owner on Apr 26, 2023. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 0 additions & 33 deletions docbrown/src/core/misc.rs

This file was deleted.

1 change: 0 additions & 1 deletion docbrown/src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ mod bitset;
mod edge_layer;
mod lazy_vec;
pub mod lsm;
mod misc;
mod props;
mod sorted_vec_map;
pub mod state;
Expand Down
85 changes: 85 additions & 0 deletions docbrown/src/db/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1897,4 +1897,89 @@ mod db_tests {
assert_eq!(windowed_times_of_farquaad, [4, 6, 7]);
assert_eq!(windowed_times_of_two, [5, 6, 7]);
}

#[test]
fn test_prop_display_str() {
let mut prop = Prop::Str(String::from("hello"));
assert_eq!(format!("{}", prop), "hello");

prop = Prop::I32(42);
assert_eq!(format!("{}", prop), "42");

prop = Prop::I64(9223372036854775807);
assert_eq!(format!("{}", prop), "9223372036854775807");

prop = Prop::U32(4294967295);
assert_eq!(format!("{}", prop), "4294967295");

prop = Prop::U64(18446744073709551615);
assert_eq!(format!("{}", prop), "18446744073709551615");

prop = Prop::F32(3.14159);
assert_eq!(format!("{}", prop), "3.14159");

prop = Prop::F64(3.141592653589793);
assert_eq!(format!("{}", prop), "3.141592653589793");

prop = Prop::Bool(true);
assert_eq!(format!("{}", prop), "true");
}

#[test]
fn test_temporral_edge_props_window() {
let g = Graph::new(1);
g.add_edge(1, 1, 2, &vec![("weight".to_string(), Prop::I64(1))], None)
.unwrap();
g.add_edge(2, 1, 2, &vec![("weight".to_string(), Prop::I64(2))], None)
.unwrap();
g.add_edge(3, 1, 2, &vec![("weight".to_string(), Prop::I64(3))], None)
.unwrap();

let e = g.vertex(1).unwrap().out_edges().next().unwrap();

let res = g.temporal_edge_props_window(EdgeRef::from(e), 1, 3);
let mut exp = HashMap::new();
exp.insert(
"weight".to_string(),
vec![(1, Prop::I64(1)), (2, Prop::I64(2))],
);
assert_eq!(res, exp);
}

#[test]
fn test_vertex_early_late_times() {
let g = Graph::new(1);
g.add_vertex(1, 1, &vec![]).unwrap();
g.add_vertex(2, 1, &vec![]).unwrap();
g.add_vertex(3, 1, &vec![]).unwrap();

assert_eq!(g.vertex(1).unwrap().earliest_time(), Some(1));
assert_eq!(g.vertex(1).unwrap().latest_time(), Some(3));

assert_eq!(g.at(2).vertex(1).unwrap().earliest_time(), Some(1));
assert_eq!(g.at(2).vertex(1).unwrap().latest_time(), Some(2));
}

#[test]
fn test_vertex_ids() {
let g = Graph::new(1);
g.add_vertex(1, 1, &vec![]).unwrap();
g.add_vertex(1, 2, &vec![]).unwrap();
g.add_vertex(2, 3, &vec![]).unwrap();

assert_eq!(g.vertex_ids().collect::<Vec<u64>>(), vec![1, 2, 3]);

let g_at = g.at(1);
assert_eq!(g.vertex_ids().collect::<Vec<u64>>(), vec![1, 2]);
}

// #[test]
// fn test_vertex_refs_shard() {
// let g = Graph::new(2);
// g.add_vertex(1, 1, &vec![]).unwrap();
// g.add_vertex(1, 2, &vec![]).unwrap();
// g.add_vertex(2, 3, &vec![]).unwrap();
//
// assert_eq!(g.vertex_refs_shard(0).collect::<Vec<_>>(), vec![1, 2]);
// }
}
4 changes: 2 additions & 2 deletions docbrown/src/graph_loader/lotr_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ pub fn lotr_graph(shards: usize) -> Graph {

CsvLoader::new(lotr_file().unwrap())
.load_into_graph(&g, |lotr: Lotr, g: &Graph| {
let src_id = &lotr.src_id;
let dst_id = &lotr.dst_id;
let src_id = lotr.src_id;
let dst_id = lotr.dst_id;
let time = lotr.time;

g.add_vertex(time, src_id.clone(), &vec![])
Expand Down
17 changes: 16 additions & 1 deletion docbrown/src/graph_loader/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use std::env;
use std::fs::File;
use std::io::{copy, Cursor};
use std::io::{copy, Cursor, Read};
use std::path::PathBuf;
use std::time::Duration;

Expand Down Expand Up @@ -48,3 +48,18 @@ pub fn fetch_file(
}
Ok(filepath)
}

#[cfg(test)]
mod graph_loader_test {
use crate::graph_loader::fetch_file;

#[test]
fn test_fetch_file() {
let path = fetch_file(
"lotr2.csv",
"https://raw.githubusercontent.com/Raphtory/Data/main/lotr_test.csv",
600,
);
assert!(path.is_ok());
}
}
60 changes: 38 additions & 22 deletions docbrown/src/graph_loader/reddit_hyperlinks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
//! use docbrown::db::graph::Graph;
//! use docbrown::db::view_api::*;
//!
//! let graph = reddit_graph(1, 120);
//! let graph = reddit_graph(1, 120, false);
//!
//! println!("The graph has {:?} vertices", graph.num_vertices());
//! println!("The graph has {:?} edges", graph.num_edges());
Expand All @@ -53,12 +53,22 @@ use std::path::PathBuf;
/// * `timeout` - The timeout in seconds for downloading the dataset
/// # Returns
/// * `PathBuf` - The path to the file
pub fn reddit_file(timeout: u64) -> Result<PathBuf, Box<dyn std::error::Error>> {
fetch_file(
"reddit-title.tsv",
"http://snap.stanford.edu/data/soc-redditHyperlinks-title.tsv",
timeout,
)
pub fn reddit_file(
timeout: u64,
test_file: Option<bool>,
) -> Result<PathBuf, Box<dyn std::error::Error>> {
match test_file {
Some(true) => fetch_file(
"reddit-title-test.tsv",
"https://raw.githubusercontent.com/Raphtory/Data/main/reddit-title-test.tsv",
timeout,
),
_ => fetch_file(
"reddit-title.tsv",
"http://snap.stanford.edu/data/soc-redditHyperlinks-title.tsv",
timeout,
),
}
}

/// Read the file line by line
Expand All @@ -80,11 +90,11 @@ where
/// # Returns
///
/// * `Graph` - The graph containing the Reddit hyperlinks dataset
pub fn reddit_graph(shards: usize, timeout: u64) -> Graph {
pub fn reddit_graph(shards: usize, timeout: u64, test_file: bool) -> Graph {
let graph = {
let g = Graph::new(shards);

if let Ok(path) = reddit_file(timeout) {
if let Ok(path) = reddit_file(timeout, Some(test_file)) {
if let Ok(lines) = read_lines(path.as_path()) {
// Consumes the iterator, returns an (Optional) String
for reddit in lines.dropping(1).flatten() {
Expand Down Expand Up @@ -142,16 +152,22 @@ pub fn reddit_graph(shards: usize, timeout: u64) -> Graph {
};
graph
}
// #[cfg(test)]
// mod reddit_test {
// use crate::graph_loader::reddit_hyperlinks::reddit_graph;
// use crate::db::view_api::GraphViewOps;
//
// #[test]
// fn check_data() {
// if let Ok(g) = reddit_graph(1, 600) {
// println!("{} {}",g.num_vertices(),g.num_edges());
// };
// }
// }
//

#[cfg(test)]
mod reddit_test {
use crate::db::view_api::GraphViewOps;
use crate::graph_loader::reddit_hyperlinks::{reddit_file, reddit_graph};

#[test]
fn check_data() {
let file = reddit_file(100, Some(true));
assert!(file.is_ok());
}

#[test]
fn check_graph() {
let graph = reddit_graph(1, 100, true);
assert_eq!(graph.num_vertices(), 16);
assert_eq!(graph.num_edges(), 9);
}
}
1 change: 1 addition & 0 deletions python/src/graph_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ pub(crate) fn reddit_hyperlink_graph(shards: usize, timeout_seconds: u64) -> PyR
PyGraph::py_from_db_graph(docbrown::graph_loader::reddit_hyperlinks::reddit_graph(
shards,
timeout_seconds,
false,
))
}