Skip to content

Commit

Permalink
#30: Add phyl tree tests (#110)
Browse files Browse the repository at this point in the history
* Add test "countLeafs"

* Add test "map"

* Add test "iter"

* Add test "fold"

* Add test "tryGetNodeBy"

* Delete coverage.xml.637344003428108790L.exn

Co-authored-by: Kevin Schneider <schneider.kev@outlook.de>
  • Loading branch information
graemevissers and kMutagene authored Sep 9, 2020
1 parent 668753c commit 604a6cc
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<Compile Include="BioFSharp\NucleotideTests.fs" />
<Compile Include="BioFSharp\BioCollections.fs" />
<Compile Include="BioFSharp\BioItemTests.fs" />
<Compile Include="BioFSharp\PhylTreeTests.fs" />
<Compile Include="Main.fs" />
</ItemGroup>

Expand Down
88 changes: 88 additions & 0 deletions tests/BioFSharp.Tests.NetCore/BioFSharp/PhylTreeTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
module PhylTreeTests

open BioFSharp
open PhylTree
open BioList
open Nucleotides
open Expecto

let testPhylTree_oneGen = Node.Branch("1", [])

let testPhylTree_threeGens_string =
Node.Branch("ACTG",[
Node.Branch("ACTT", [
Node.Branch("ACTC", [])
])
Node.Branch("ACGG", [
Node.Branch("ACCG", [])
])
Node.Branch("GCTG", [
Node.Branch("TCTG", [])
])
])

let testPhylTree_threeGens_BioList =
Node.Branch(BioList.ofNucleotideString "ACTG",[
Node.Branch(BioList.ofNucleotideString "ACTT", [
Node.Branch(BioList.ofNucleotideString "ACTC", [])
])
Node.Branch(BioList.ofNucleotideString "ACGG", [
Node.Branch(BioList.ofNucleotideString "ACCG", [])
])
Node.Branch(BioList.ofNucleotideString "GCTG", [
Node.Branch(BioList.ofNucleotideString "TCTG", [])
])
])

let testFoldFun (acc: string) (node: Node<'n>) =
match node with
Branch(s, nl) ->
(s + "; " + acc)

let testMappingFun (n: Node<'n>) =
match n with
Branch(s, nl) -> s |> BioList.ofNucleotideString

[<Tests>]
let phylTreeTests =
testList "PhylTree" [
testCase "map" (fun() ->
Expect.equal
(PhylTree.map testMappingFun testPhylTree_threeGens_string)
testPhylTree_threeGens_BioList
"PhylTree.map did not return correct Node<'t>"
)
testCase "iter" (fun () ->
let mutable testList = []
let testIterFun (node: Node<'n>) =
match node with
Branch (s, nl) -> do (testList <- testList @ [s])
PhylTree.iter testIterFun testPhylTree_threeGens_string
Expect.equal
testList
["ACTG"; "ACTT"; "ACTC"; "ACGG"; "ACCG"; "GCTG"; "TCTG"]
"PhylTree.iter did not return correct Node<'t>"
)
testCase "fold" (fun () ->
let testAcc = ""
Expect.equal
(PhylTree.fold testAcc testFoldFun testPhylTree_threeGens_string)
"ACTG; GCTG; TCTG; ACGG; ACCG; ACTT; ACTC; "
"PhylTree.fold did not return correct accumulated value."
)
testCase "countLeafs" (fun () ->
Expect.equal
(testPhylTree_threeGens_string |> PhylTree.countLeafs)
3
"PhylTree.countLeafs did not return the correct number of leaves"
)
testCase "tryGetNodeBy" (fun () ->
let testConditionFun (node: Node<'n>) =
match node with
Branch(s, _) -> s = "ACTG"
Expect.equal
(PhylTree.tryGetNodeBy testConditionFun testPhylTree_threeGens_string)
(Some testPhylTree_threeGens_string)
"PhylTree.tryGetNodeBy did not return the correct Node<'n> for the given condition."
)
]
2 changes: 2 additions & 0 deletions tests/BioFSharp.Tests.NetCore/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ let main argv =

Tests.runTestsWithCLIArgs [] argv NucleotideTests.nucleotideTests |> ignore

Tests.runTestsWithCLIArgs [] argv PhylTreeTests.phylTreeTests |> ignore

0

0 comments on commit 604a6cc

Please sign in to comment.