From 668753ccea51cb04f8a8c1b76e8ae2bb209ec678 Mon Sep 17 00:00:00 2001 From: graemevissers <51211544+graemevissers@users.noreply.github.com> Date: Wed, 26 Aug 2020 02:26:48 -0700 Subject: [PATCH] #30: Add nucleotide tests (#109) * Add testCase "symbol" * Add test "formula" * Add test "isTerminator" * Add test "isTerminator" * Add test "isGap" * Add test "name" * Add NucleotideTests.fs to Main. Fix errors * Add test "charToParsedNucleotideChar" * Add test "complement" * Add test "replaceTbyU" * Add test "replaceUbyT" --- .../BioFSharp.Tests.NetCore.fsproj | 1 + .../BioFSharp/NucleotideTests.fs | 132 ++++++++++++++++++ tests/BioFSharp.Tests.NetCore/Main.fs | 2 + 3 files changed, 135 insertions(+) create mode 100644 tests/BioFSharp.Tests.NetCore/BioFSharp/NucleotideTests.fs diff --git a/tests/BioFSharp.Tests.NetCore/BioFSharp.Tests.NetCore.fsproj b/tests/BioFSharp.Tests.NetCore/BioFSharp.Tests.NetCore.fsproj index 4269d670..ad1fc4f3 100644 --- a/tests/BioFSharp.Tests.NetCore/BioFSharp.Tests.NetCore.fsproj +++ b/tests/BioFSharp.Tests.NetCore/BioFSharp.Tests.NetCore.fsproj @@ -10,6 +10,7 @@ + diff --git a/tests/BioFSharp.Tests.NetCore/BioFSharp/NucleotideTests.fs b/tests/BioFSharp.Tests.NetCore/BioFSharp/NucleotideTests.fs new file mode 100644 index 00000000..94a71822 --- /dev/null +++ b/tests/BioFSharp.Tests.NetCore/BioFSharp/NucleotideTests.fs @@ -0,0 +1,132 @@ +module NucleotideTests + +open BioFSharp +open Nucleotides +open Formula +open Expecto + +let allNucs = [ + Nucleotide.A; Nucleotide.T; Nucleotide.G; Nucleotide.C; Nucleotide.U + Nucleotide.I; Nucleotide.Gap; Nucleotide.Ter; Nucleotide.R + Nucleotide.Y; Nucleotide.K; Nucleotide.M; Nucleotide.S + Nucleotide.W; Nucleotide.B; Nucleotide.D; Nucleotide.H + Nucleotide.V; Nucleotide.N +] +let allSymbols = ['A';'T';'G';'C';'U';'I';'-';'*';'R';'Y';'K';'M';'S';'W';'B';'D';'H';'V';'N'] +let allFormuals = [ + Formula.Table.A; Formula.Table.T; Formula.Table.G; Formula.Table.C; Formula.Table.U + Formula.Table.I; Formula.emptyFormula; Formula.emptyFormula; Formula.emptyFormula + Formula.emptyFormula; Formula.emptyFormula; Formula.emptyFormula; Formula.emptyFormula + Formula.emptyFormula; Formula.emptyFormula; Formula.emptyFormula; Formula.emptyFormula + Formula.emptyFormula; Formula.emptyFormula +] +let allNames = [ + "Adenine"; "Thymidine"; "Guanine"; "Cytosine"; "Uracil" + "Inosine"; "Gap" ; "Ter" ; "puRine" ; "pYrimidine" + "Keto" ; "aMino" ; "Strong base pair" ; "Weak base pair" + "not A" ; "not C" ; "not G" ; "not T/U" ; "Unspecified" +] +let allParsedNucChars = [ + StandardCodes Nucleotide.A; Standard_DNAonly Nucleotide.T; StandardCodes Nucleotide.G + StandardCodes Nucleotide.C; Standard_RNAonly Nucleotide.U; Standard_RNAonly Nucleotide.I + GapTer Nucleotide.Gap; GapTer Nucleotide.Ter; AmbiguityCodes Nucleotide.R + AmbiguityCodes Nucleotide.Y; AmbiguityCodes Nucleotide.K; AmbiguityCodes Nucleotide.M + AmbiguityCodes Nucleotide.S; AmbiguityCodes Nucleotide.W; AmbiguityCodes Nucleotide.B + AmbiguityCodes Nucleotide.D; AmbiguityCodes Nucleotide.H; AmbiguityCodes Nucleotide.V + AmbiguityCodes Nucleotide.N; NoNucChar '!' +] + +[] +let nucleotideTests = + testList "Nucleotides" [ + testCase "symbol" (fun() -> + let testSymbols = allNucs |> List.map(fun nuc -> Nucleotides.symbol nuc) + Expect.equal + testSymbols + allSymbols + "Nucleotides.symbol did not return the correct symbol for all Nucleotides." + ) + testCase "formula" (fun() -> + let testFormulas = allNucs |> List.map(fun nuc -> Nucleotides.formula nuc) + Expect.equal + testFormulas + allFormuals + "Nucleotides.formula did not return the correct formula for all Nucleotides." + ) + testCase "isTerminator" (fun() -> + let testBools = [ + false; false; false; false; false; false; false; true; false + false; false; false; false; false; false; false; false; false + false + ] + Expect.equal + (allNucs |> List.map(fun nuc -> Nucleotides.isTerminator nuc)) + testBools + "Nucleotides.isTerminator did not return the correct boolean for all Nucleotides." + ) + testCase "isGap" (fun() -> + let testBools = [ + false; false; false; false; false; false; true; false; false + false; false; false; false; false; false; false; false; false + false + ] + Expect.equal + (allNucs |> List.map(fun nuc -> Nucleotides.isGap nuc)) + testBools + "Nucleotides.isGap did not return the correct boolean for all Nucleotides." + ) + testCase "name" (fun() -> + let testNames = (allNucs |> List.map(fun nuc -> Nucleotides.name nuc)) + Expect.equal + testNames + allNames + "Nucleotides.name did not return the correct name for all nucleotides." + ) + testCase "charToParsedNucleotideChar" (fun() -> + let testSymbols = List.append allSymbols ['!'] + let testParsedNucChars = (testSymbols |> List.map(fun nuc -> Nucleotides.charToParsedNucleotideChar nuc)) + Expect.equal + testParsedNucChars + allParsedNucChars + "Nucleotides.charToParsedNucleotideChar did not return correct ParsedNucleotideChar for all Nucleotides." + ) + testCase "complement" (fun () -> + let allComplementNucs = [ + Nucleotide.T; Nucleotide.A; Nucleotide.C; Nucleotide.G; Nucleotide.A + Nucleotide.I; Nucleotide.Gap; Nucleotide.Ter; Nucleotide.Y; Nucleotide.R + Nucleotide.M; Nucleotide.K; Nucleotide.S; Nucleotide.W; Nucleotide.V + Nucleotide.H; Nucleotide.D; Nucleotide.B; Nucleotide.N + ] + let testComplementNucs = (allNucs |> List.map(fun nuc -> Nucleotides.complement nuc)) + Expect.equal + testComplementNucs + allComplementNucs + "Nucleotides.complement did not return the correct complement Nucleotide for all Nucleotides." + ) + testCase "replaceTbyU" (fun () -> + let allNucsReplaceTbyU = [ + Nucleotide.A; Nucleotide.U; Nucleotide.G; Nucleotide.C; Nucleotide.U + Nucleotide.I; Nucleotide.Gap; Nucleotide.Ter; Nucleotide.R + Nucleotide.Y; Nucleotide.K; Nucleotide.M; Nucleotide.S; Nucleotide.W + Nucleotide.B; Nucleotide.D; Nucleotide.H; Nucleotide.V; Nucleotide.N + ] + let testNucsReplaceTbyU = (allNucs |> List.map(fun nuc -> Nucleotides.replaceTbyU nuc)) + Expect.equal + testNucsReplaceTbyU + allNucsReplaceTbyU + "Nucleotides.replaceTbyU did not return the correct Nucleotide for all Nucleotides." + ) + testCase "replaceUbyT" (fun () -> + let allNucsReplaceUbyT = [ + Nucleotide.A; Nucleotide.T; Nucleotide.G; Nucleotide.C; Nucleotide.T + Nucleotide.I; Nucleotide.Gap; Nucleotide.Ter; Nucleotide.R + Nucleotide.Y; Nucleotide.K; Nucleotide.M; Nucleotide.S; Nucleotide.W + Nucleotide.B; Nucleotide.D; Nucleotide.H; Nucleotide.V; Nucleotide.N + ] + let testNucsReplaceUbyT = (allNucs |> List.map(fun nuc -> Nucleotides.replaceUbyT nuc)) + Expect.equal + testNucsReplaceUbyT + allNucsReplaceUbyT + "Nucleotides.replaceUbyT did not return the correct Nucleotide for all Nucleotides." + ) + ] diff --git a/tests/BioFSharp.Tests.NetCore/Main.fs b/tests/BioFSharp.Tests.NetCore/Main.fs index ec8403d9..9713bebd 100644 --- a/tests/BioFSharp.Tests.NetCore/Main.fs +++ b/tests/BioFSharp.Tests.NetCore/Main.fs @@ -20,4 +20,6 @@ let main argv = Tests.runTestsWithCLIArgs [] argv AminoAcidTests.aminoAcidTests |> ignore + Tests.runTestsWithCLIArgs [] argv NucleotideTests.nucleotideTests |> ignore + 0 \ No newline at end of file