-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from fslaborg/digraphComponents
added support for finding and returning components from digraph
- Loading branch information
Showing
6 changed files
with
234 additions
and
25 deletions.
There are no files selected for viewing
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
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,68 @@ | ||
|
||
module Components | ||
|
||
open Xunit | ||
open Graphoscope | ||
open FSharpAux | ||
|
||
|
||
let testGraph = | ||
DiGraph.empty | ||
|> DiGraph.addNode 1 1 | ||
|> DiGraph.addNode 2 2 | ||
|> DiGraph.addNode 3 3 | ||
|> DiGraph.addNode 4 4 | ||
|> DiGraph.addNode 5 5 | ||
|> DiGraph.addNode 6 6 | ||
|> DiGraph.addNode 7 7 | ||
|> DiGraph.addEdge (1, 2, 1.0) | ||
|> DiGraph.addEdge (1, 3, 1.0) | ||
|> DiGraph.addEdge (2, 4, 1.0) | ||
|> DiGraph.addEdge (5, 6, 1.0) | ||
|> DiGraph.addEdge (5, 7, 1.0) | ||
|
||
|
||
let testGraphGiant = | ||
DiGraph.empty | ||
|> DiGraph.addNode 1 1 | ||
|> DiGraph.addNode 2 2 | ||
|> DiGraph.addNode 3 3 | ||
|> DiGraph.addNode 4 4 | ||
|> DiGraph.addNode 5 5 | ||
|> DiGraph.addNode 6 6 | ||
|> DiGraph.addNode 7 7 | ||
|> DiGraph.addEdge (1, 2, 1.0) | ||
|> DiGraph.addEdge (1, 3, 1.0) | ||
|> DiGraph.addEdge (2, 4, 1.0) | ||
|> DiGraph.addEdge (4, 5, 1.0) | ||
|> DiGraph.addEdge (5, 6, 1.0) | ||
|> DiGraph.addEdge (5, 7, 1.0) | ||
|
||
[<Fact>] | ||
let ``Can detect no giant compenent`` () = | ||
testGraph | ||
|> Algorithms.Components.hasGiantComponentOfDiGraph | ||
|> Assert.False | ||
|
||
[<Fact>] | ||
let ``Can detect giant compenent`` () = | ||
testGraphGiant | ||
|> Algorithms.Components.hasGiantComponentOfDiGraph | ||
|> Assert.True | ||
|
||
[<Fact>] | ||
let ``Can get components`` () = | ||
let components = | ||
testGraph | ||
|> Algorithms.Components.getComponentsDiGraph | ||
|> Set.count | ||
|
||
Assert.True (2 = components) | ||
|
||
[<Fact>] | ||
let ``Can get new graph of largest component`` () = | ||
let newGraph = | ||
testGraph | ||
|> Algorithms.Components.getLargestComponentDiGraph | ||
|
||
Assert.True (3 = (DiGraph.countEdges newGraph) ) |
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