@@ -9,72 +9,67 @@ public static class GraphsCyclesDetectorTests
99 [ Fact ]
1010 public static void DoTest ( )
1111 {
12- string [ ] V ;
13- DirectedSparseGraph < string > DAG ;
14- UndirectedSparseGraph < string > CyclicGraph ;
15- DirectedSparseGraph < string > DigraphWithCycles ;
16-
1712 // Init graph object
18- DigraphWithCycles = new DirectedSparseGraph < string > ( ) ;
13+ var digraphWithCycles = new DirectedSparseGraph < string > ( ) ;
1914
2015 // Init V
21- V = new string [ 6 ] { "r" , "s" , "t" , "x" , "y" , "z" } ;
16+ var v = new string [ 6 ] { "r" , "s" , "t" , "x" , "y" , "z" } ;
2217
2318 // Insert V
24- DigraphWithCycles . AddVertices ( V ) ;
19+ digraphWithCycles . AddVertices ( v ) ;
2520
2621 // Insert E
27- DigraphWithCycles . AddEdge ( "r" , "s" ) ;
28- DigraphWithCycles . AddEdge ( "r" , "t" ) ;
29- DigraphWithCycles . AddEdge ( "s" , "t" ) ;
30- DigraphWithCycles . AddEdge ( "s" , "x" ) ;
31- DigraphWithCycles . AddEdge ( "t" , "x" ) ;
32- DigraphWithCycles . AddEdge ( "t" , "y" ) ;
33- DigraphWithCycles . AddEdge ( "t" , "z" ) ;
34- DigraphWithCycles . AddEdge ( "x" , "y" ) ;
35- DigraphWithCycles . AddEdge ( "x" , "z" ) ;
36- DigraphWithCycles . AddEdge ( "y" , "z" ) ;
37- DigraphWithCycles . AddEdge ( "z" , "r" ) ;
38- DigraphWithCycles . AddEdge ( "z" , "s" ) ;
39-
40- var isCyclic = CyclesDetector . IsCyclic < string > ( DigraphWithCycles ) ;
22+ digraphWithCycles . AddEdge ( "r" , "s" ) ;
23+ digraphWithCycles . AddEdge ( "r" , "t" ) ;
24+ digraphWithCycles . AddEdge ( "s" , "t" ) ;
25+ digraphWithCycles . AddEdge ( "s" , "x" ) ;
26+ digraphWithCycles . AddEdge ( "t" , "x" ) ;
27+ digraphWithCycles . AddEdge ( "t" , "y" ) ;
28+ digraphWithCycles . AddEdge ( "t" , "z" ) ;
29+ digraphWithCycles . AddEdge ( "x" , "y" ) ;
30+ digraphWithCycles . AddEdge ( "x" , "z" ) ;
31+ digraphWithCycles . AddEdge ( "y" , "z" ) ;
32+ digraphWithCycles . AddEdge ( "z" , "r" ) ;
33+ digraphWithCycles . AddEdge ( "z" , "s" ) ;
34+
35+ var isCyclic = CyclesDetector . IsCyclic < string > ( digraphWithCycles ) ;
4136 Assert . True ( isCyclic == true , "Wrong status! The graph has cycles." ) ;
4237
43- CyclicGraph = new UndirectedSparseGraph < string > ( ) ;
38+ var cyclicGraph = new UndirectedSparseGraph < string > ( ) ;
4439
45- V = new string [ ] { "A" , "B" , "C" , "D" , "E" } ;
40+ v = new string [ ] { "A" , "B" , "C" , "D" , "E" } ;
4641
4742 // Insert new values of V
48- CyclicGraph . AddVertices ( V ) ;
43+ cyclicGraph . AddVertices ( v ) ;
4944
5045 // Insert new value for edges
51- CyclicGraph . AddEdge ( "A" , "C" ) ;
52- CyclicGraph . AddEdge ( "B" , "A" ) ;
53- CyclicGraph . AddEdge ( "B" , "C" ) ;
54- CyclicGraph . AddEdge ( "C" , "E" ) ;
55- CyclicGraph . AddEdge ( "C" , "D" ) ;
56- CyclicGraph . AddEdge ( "D" , "B" ) ;
57- CyclicGraph . AddEdge ( "E" , "D" ) ;
58-
59- isCyclic = CyclesDetector . IsCyclic < string > ( CyclicGraph ) ;
46+ cyclicGraph . AddEdge ( "A" , "C" ) ;
47+ cyclicGraph . AddEdge ( "B" , "A" ) ;
48+ cyclicGraph . AddEdge ( "B" , "C" ) ;
49+ cyclicGraph . AddEdge ( "C" , "E" ) ;
50+ cyclicGraph . AddEdge ( "C" , "D" ) ;
51+ cyclicGraph . AddEdge ( "D" , "B" ) ;
52+ cyclicGraph . AddEdge ( "E" , "D" ) ;
53+
54+ isCyclic = CyclesDetector . IsCyclic < string > ( cyclicGraph ) ;
6055 Assert . True ( isCyclic == true , "Wrong status! The graph has cycles." ) ;
6156
62- DAG = new DirectedSparseGraph < string > ( ) ;
57+ var dag = new DirectedSparseGraph < string > ( ) ;
6358
64- V = new string [ ] { "A" , "B" , "C" , "D" , "E" , "X" } ;
59+ v = new string [ ] { "A" , "B" , "C" , "D" , "E" , "X" } ;
6560
6661 // Insert new values of V
67- DAG . AddVertices ( V ) ;
62+ dag . AddVertices ( v ) ;
6863
6964 // Insert new value for edges
70- DAG . AddEdge ( "A" , "B" ) ;
71- DAG . AddEdge ( "A" , "X" ) ;
72- DAG . AddEdge ( "B" , "C" ) ;
73- DAG . AddEdge ( "C" , "D" ) ;
74- DAG . AddEdge ( "D" , "E" ) ;
75- DAG . AddEdge ( "E" , "X" ) ;
76-
77- isCyclic = CyclesDetector . IsCyclic < string > ( DAG ) ;
65+ dag . AddEdge ( "A" , "B" ) ;
66+ dag . AddEdge ( "A" , "X" ) ;
67+ dag . AddEdge ( "B" , "C" ) ;
68+ dag . AddEdge ( "C" , "D" ) ;
69+ dag . AddEdge ( "D" , "E" ) ;
70+ dag . AddEdge ( "E" , "X" ) ;
71+
72+ isCyclic = CyclesDetector . IsCyclic < string > ( dag ) ;
7873 Assert . True ( isCyclic == false , "Wrong status! The graph has no cycles." ) ;
7974 }
8075
0 commit comments