@@ -239,41 +239,20 @@ impl<G: BasicSourceControlGraph> search::Strategy<G> for BasicStrategy {
239239
240240#[ cfg( test) ]
241241mod tests {
242- use std:: convert:: Infallible ;
243-
244- use itertools:: Itertools ;
245- use maplit:: { hashmap, hashset} ;
246- use proptest:: prelude:: Strategy as ProptestStrategy ;
247- use proptest:: prelude:: * ;
248- use proptest:: proptest;
242+ use super :: * ;
249243
250244 use crate :: search:: Bounds ;
251245 use crate :: search:: EagerSolution ;
252246 use crate :: search:: Search ;
253247 use crate :: search:: Status ;
248+ use crate :: testing:: arb_strategy;
249+ use crate :: testing:: arb_test_graph_and_nodes;
250+ use crate :: testing:: TestGraph ;
251+ use crate :: testing:: UsizeGraph ;
254252
255- use super :: BasicStrategyKind ;
256- use super :: * ;
257-
258- #[ derive( Clone , Debug ) ]
259- struct UsizeGraph {
260- max : usize ,
261- }
262-
263- impl BasicSourceControlGraph for UsizeGraph {
264- type Node = usize ;
265- type Error = Infallible ;
266-
267- fn ancestors ( & self , node : Self :: Node ) -> Result < HashSet < Self :: Node > , Infallible > {
268- assert ! ( node < self . max) ;
269- Ok ( ( 0 ..=node) . collect ( ) )
270- }
271-
272- fn descendants ( & self , node : Self :: Node ) -> Result < HashSet < Self :: Node > , Infallible > {
273- assert ! ( node < self . max) ;
274- Ok ( ( node..self . max ) . collect ( ) )
275- }
276- }
253+ use itertools:: Itertools ;
254+ use maplit:: hashmap;
255+ use maplit:: hashset;
277256
278257 #[ test]
279258 fn test_search_stick ( ) {
@@ -289,10 +268,6 @@ mod tests {
289268 strategy : BasicStrategyKind :: Binary ,
290269 } ;
291270 let mut search = Search :: new ( graph. clone ( ) , nodes. clone ( ) ) ;
292- // let mut linear_search = Search::new(graph.clone(), linear_strategy, nodes.clone());
293- // let mut linear_reverse_search =
294- // Search::new(graph.clone(), linear_reverse_strategy, nodes.clone());
295- // let mut binary_search = Search::new(graph.clone(), binary_strategy, nodes.clone());
296271
297272 assert_eq ! (
298273 search
@@ -455,34 +430,6 @@ mod tests {
455430 "### ) ;
456431 }
457432
458- #[ derive( Clone , Debug ) ]
459- struct TestGraph {
460- nodes : HashMap < char , HashSet < char > > ,
461- }
462-
463- impl BasicSourceControlGraph for TestGraph {
464- type Node = char ;
465- type Error = Infallible ;
466-
467- fn ancestors ( & self , node : Self :: Node ) -> Result < HashSet < Self :: Node > , Infallible > {
468- let mut result = hashset ! { node} ;
469- let parents: HashSet < char > = self
470- . nodes
471- . iter ( )
472- . filter_map ( |( k, v) | if v. contains ( & node) { Some ( * k) } else { None } )
473- . collect ( ) ;
474- result. extend ( self . ancestors_all ( parents) ?) ;
475- Ok ( result)
476- }
477-
478- fn descendants ( & self , node : Self :: Node ) -> Result < HashSet < Self :: Node > , Infallible > {
479- let mut result = hashset ! { node} ;
480- let children: HashSet < char > = self . nodes [ & node] . clone ( ) ;
481- result. extend ( self . descendants_all ( children) ?) ;
482- Ok ( result)
483- }
484- }
485-
486433 #[ test]
487434 fn test_search_dag ( ) {
488435 let graph = TestGraph {
@@ -586,51 +533,7 @@ mod tests {
586533 ) ;
587534 }
588535
589- fn arb_strategy ( ) -> impl ProptestStrategy < Value = BasicStrategyKind > {
590- prop_oneof ! [
591- Just ( BasicStrategyKind :: Linear ) ,
592- Just ( BasicStrategyKind :: LinearReverse ) ,
593- Just ( BasicStrategyKind :: Binary ) ,
594- ]
595- }
596-
597- fn arb_test_graph_and_nodes ( ) -> impl ProptestStrategy < Value = ( TestGraph , Vec < char > ) > {
598- let nodes = prop:: collection:: hash_set (
599- prop:: sample:: select ( vec ! [ 'a' , 'b' , 'c' , 'd' , 'e' , 'f' , 'g' , 'h' ] ) ,
600- 1 ..=8 ,
601- ) ;
602- nodes
603- . prop_flat_map ( |nodes| {
604- let num_nodes = nodes. len ( ) ;
605- let nodes_kv = nodes
606- . iter ( )
607- . copied ( )
608- . map ( |node| ( node, HashSet :: new ( ) ) )
609- . collect ( ) ;
610- let graph = TestGraph { nodes : nodes_kv } ;
611- let lineages = prop:: collection:: vec (
612- prop:: sample:: subsequence ( nodes. into_iter ( ) . collect_vec ( ) , 0 ..num_nodes) ,
613- 0 ..num_nodes,
614- ) ;
615- ( Just ( graph) , lineages)
616- } )
617- . prop_map ( |( mut graph, lineages) | {
618- for lineage in lineages {
619- for ( parent, child) in lineage. into_iter ( ) . tuple_windows ( ) {
620- graph. nodes . get_mut ( & parent) . unwrap ( ) . insert ( child) ;
621- }
622- }
623- graph
624- } )
625- . prop_flat_map ( |graph| {
626- let nodes = graph. nodes . keys ( ) . copied ( ) . collect :: < Vec < _ > > ( ) ;
627- let num_nodes = nodes. len ( ) ;
628- let failure_nodes = prop:: sample:: subsequence ( nodes, 0 ..num_nodes) ;
629- ( Just ( graph) , failure_nodes)
630- } )
631- }
632-
633- proptest ! {
536+ proptest:: proptest! {
634537 #[ test]
635538 fn test_search_dag_proptest( strategy in arb_strategy( ) , ( graph, failure_nodes) in arb_test_graph_and_nodes( ) ) {
636539 let nodes = graph. nodes. keys( ) . sorted( ) . copied( ) . collect:: <Vec <_>>( ) ;
0 commit comments