-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update to new
roaring_graphs
library version
Co-authored-by: James Walker <[email protected]>
- Loading branch information
Showing
6 changed files
with
213 additions
and
1 deletion.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Seeds for failure cases proptest has generated in the past. It is | ||
# automatically read and these particular cases re-run before any | ||
# novel cases are generated. | ||
# | ||
# It is recommended to check this file in to source control so that | ||
# everyone who runs the test benefits from these saved cases. | ||
cc ecfcb732e093de600a3a3012674efabacf88f817b47d75c0ad0da9762ca3b6f7 # shrinks to input = _WalkDagNeverIteratesBlockTwiceArgs { dag: [(Cid(bafyreigvk2vd4s7ecxqhr7vlf5ei5tpdpalx73wbt53zokomvab5ouzq2a), b"\x86\xd8*X%\0\x01q\x12 pg\xacO\xb3\xfe\xacy\xd9k\xee\xc10\xdd\x8b\xbbc\x81\xc1\x06\x12\xf5Uw\x9e\xed\x11n\r?8\xdc\xd8*X%\0\x01q\x12 \xe0\xed\xdb\xa6\x0c\x8b\xf9\xe2fk\x12\xdd3\xf9\xb9Y%[\x85\xf6\xd9\xd8\x15\x8a\xce3\xbb\xdfN\xcfM\x93\xd8*X%\0\x01q\x12 \xfei\x9fJr\x7f\xed\xfd\t\0\x02lz5\x0eD\xc5\xf9\xe2\xda\"\x9ez5y\xd5\xc8\x02\xab+\xc0\x92\xd8*X%\0\x01q\x12 \xc6M\xa8\xd1B\x12\xcfT\xbfC\xd0\x1e\x89\x8c\xaa\x11\xafq\xed^sF\xb5\xda\x19\x98\xf2B\xb9\xe2\x9f\xb3\xd8*X%\0\x01q\x12 v\xbe\x8bR\x8d\0u\xf7\xaa\xe9\x8do\xa5zm<\x83\xaeH\n\x84i\xe6h\xd7\xb0\xaf\x96\x89\x95\xacq\xd8*X%\0\x01q\x12 \x92`zHK\xcfR\xb8\x10G\xa3+t\t\xb7_\xc9\xf6\x9b+\xee\xe0\x83S\"#\xba\xe8Q\xdd\x10\x02")] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
use std::{collections::HashSet, fmt::Debug}; | ||
|
||
use bytes::Bytes; | ||
use libipld::{Cid, Ipld, IpldCodec}; | ||
use libipld_core::codec::Encode; | ||
use proptest::strategy::Strategy; | ||
use roaring_graphs::{arb_dag, DirectedAcyclicGraph, Vertex}; | ||
|
||
pub fn encode(ipld: &Ipld) -> Bytes { | ||
Check failure on line 9 in car-mirror/src/test_utils/dag_strategy.rs GitHub Actions / run-checks (stable)
|
||
let mut vec = Vec::new(); | ||
ipld.encode(IpldCodec::DagCbor, &mut vec).unwrap(); // TODO(matheus23) unwrap | ||
Bytes::from(vec) | ||
} | ||
|
||
pub fn generate_dag<T: Debug + Clone>( | ||
Check failure on line 15 in car-mirror/src/test_utils/dag_strategy.rs GitHub Actions / run-checks (stable)
|
||
max_nodes: u16, | ||
generate_block: fn(Vec<Cid>) -> (Cid, T), | ||
) -> impl Strategy<Value = (Vec<(Cid, T)>, Cid)> { | ||
arb_dag(1..max_nodes, 0.5).prop_map(move |dag| dag_to_nodes(&dag, generate_block)) | ||
} | ||
|
||
pub fn dag_to_nodes<T>( | ||
Check failure on line 22 in car-mirror/src/test_utils/dag_strategy.rs GitHub Actions / run-checks (stable)
|
||
dag: &DirectedAcyclicGraph, | ||
generate_node: fn(Vec<Cid>) -> (Cid, T), | ||
) -> (Vec<(Cid, T)>, Cid) { | ||
let mut blocks = Vec::new(); | ||
let mut visited = HashSet::new(); | ||
let (cid, block) = dag_to_nodes_helper(dag, 0, generate_node, &mut blocks, &mut visited); | ||
blocks.push((cid, block)); | ||
(blocks, cid) | ||
} | ||
|
||
pub fn dag_to_nodes_helper<T>( | ||
Check failure on line 33 in car-mirror/src/test_utils/dag_strategy.rs GitHub Actions / run-checks (stable)
|
||
dag: &DirectedAcyclicGraph, | ||
root: Vertex, | ||
generate_node: fn(Vec<Cid>) -> (Cid, T), | ||
arr: &mut Vec<(Cid, T)>, | ||
visited: &mut HashSet<Vertex>, | ||
) -> (Cid, T) { | ||
let mut child_blocks = Vec::new(); | ||
for child in dag.iter_children(root) { | ||
if visited.contains(&child) { | ||
continue; | ||
} | ||
visited.insert(child); | ||
child_blocks.push(dag_to_nodes_helper(dag, child, generate_node, arr, visited)); | ||
} | ||
let result = generate_node(child_blocks.iter().map(|(cid, _)| *cid).collect()); | ||
arr.extend(child_blocks); | ||
result | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
#[cfg(feature = "test_utils")] | ||
mod dag_strategy; | ||
/// Random value generator for sampling data. | ||
#[cfg(feature = "test_utils")] | ||
mod rvg; | ||
#[cfg(feature = "test_utils")] | ||
pub use dag_strategy::*; | ||
#[cfg(feature = "test_utils")] | ||
pub use rvg::*; |