@@ -239,41 +239,20 @@ impl<G: BasicSourceControlGraph> search::Strategy<G> for BasicStrategy {
239
239
240
240
#[ cfg( test) ]
241
241
mod 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 :: * ;
249
243
250
244
use crate :: search:: Bounds ;
251
245
use crate :: search:: EagerSolution ;
252
246
use crate :: search:: Search ;
253
247
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 ;
254
252
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;
277
256
278
257
#[ test]
279
258
fn test_search_stick ( ) {
@@ -289,10 +268,6 @@ mod tests {
289
268
strategy : BasicStrategyKind :: Binary ,
290
269
} ;
291
270
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());
296
271
297
272
assert_eq ! (
298
273
search
@@ -455,34 +430,6 @@ mod tests {
455
430
"### ) ;
456
431
}
457
432
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
-
486
433
#[ test]
487
434
fn test_search_dag ( ) {
488
435
let graph = TestGraph {
@@ -586,51 +533,7 @@ mod tests {
586
533
) ;
587
534
}
588
535
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! {
634
537
#[ test]
635
538
fn test_search_dag_proptest( strategy in arb_strategy( ) , ( graph, failure_nodes) in arb_test_graph_and_nodes( ) ) {
636
539
let nodes = graph. nodes. keys( ) . sorted( ) . copied( ) . collect:: <Vec <_>>( ) ;
0 commit comments