Skip to content

Commit

Permalink
Add tests for LongestPath
Browse files Browse the repository at this point in the history
Add simple tests for LongestPath
  • Loading branch information
LibraChris committed Dec 6, 2023
1 parent c35201d commit c14106f
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/Graphoscope.Tests/Graphoscope.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<Compile Include="GraphGenerators.fs" />
<Compile Include="WedgeCount.fs" />
<Compile Include="Components.fs" />
<Compile Include="LongestPath.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
Expand Down
49 changes: 49 additions & 0 deletions tests/Graphoscope.Tests/LongestPath.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module LongestPath

open System
open Xunit
open Graphoscope
open System.IO

open Xunit

[<Fact>]
let ``smallCyclicGraphReturnsExceptedResults``() =
let cyclicGraphExample =
seq{
"a","b",1.
"a","c",1.
"a","d",15.
"a","e",1.
"c","e",1.
"b","d",13.
"d","e",1.
"e","b",1.
"d","d",2.
}
|> Seq.map(fun (s, t, w) -> (s, s, t, t, w))
|> FGraph.ofSeq

let ex = new System.Exception("The given FGraph is not a Directed Acyclic Graph!")

// Assert
Assert.Throws<Exception>(fun () -> Measures.LongestPath.compute("a", cyclicGraphExample) |> ignore)
|> fun thrown -> Assert.Equal(ex.Message, thrown.Message)

[<Fact>]
let smallAcyclicGraphReturnsExceptedResults () =

let acyclicGraphExample =
seq{
"A","B",2.
"A","D",1.
"B","C",2.
"D","C",17.2
"A","C",18.

}
|>Seq.map(fun (s,t,w) -> (s,s,t,t,w))
|>FGraph.ofSeq

Assert.Equal((["A"; "D"; "C"], 18.2),Measures.LongestPath.computeByEdgeData("A",acyclicGraphExample))
Assert.Equal((["A"; "B"; "C"], 2.),Measures.LongestPath.compute("A",acyclicGraphExample))

0 comments on commit c14106f

Please sign in to comment.