Skip to content

Commit

Permalink
#30: refactor existing unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ZimmerD committed Aug 1, 2019
1 parent 34f7c49 commit 0a51f94
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions tests/BioFSharp.Tests/Core.fs
Original file line number Diff line number Diff line change
Expand Up @@ -92,36 +92,35 @@ module Core =

testCase "test_toString" <| fun () ->
let res = "H2O" |> parseFormulaString |> toString
Expect.isTrue (res = "H2.00 O1.00") "Expected True"
Expect.equal res "H2.00 O1.00" "Parsing of formula string failed."

testCase "test_add" <| fun () ->
let f1 = "H2" |> parseFormulaString
let f2 = "O" |> parseFormulaString
let res = add f1 f2 |> toString
Expect.isTrue (res = "H2.00 O1.00") "Expected True"
Expect.equal res "H2.00 O1.00" "Addition of formulas failed."

testCase "test_substract" <| fun () ->
let f1 = "H2O" |> parseFormulaString
let f2 = "H4O2" |> parseFormulaString
let res = substract f1 f2 |> toString
Expect.isTrue (res = "H2.00 O1.00") "Expected True"
Expect.equal res "H2.00 O1.00" "Substraction of formulas failed"

testCase "test_substract_neg" <| fun () ->
let f1 = "H2O" |> parseFormulaString
let f2 = emptyFormula
let res = substract f1 f2 |> toString
Expect.isTrue (res = "H-2.00 O-1.00") "Expected True"
Expect.equal res "H-2.00 O-1.00" "Substraction of formulas failed"

testCase "test_substract_Zero" <| fun () ->
let f1 = "H2O" |> parseFormulaString
let f2 = "H2O" |> parseFormulaString
let res = substract f1 f2 |> toString
Expect.isTrue (res = "H0.00 O0.00") "Expected True"
Expect.equal res "H0.00 O0.00" "Substraction of formulas failed"

]

open BioFSharp.Mass

open BioFSharp.Mass
[<Tests>]
let testMass =

Expand All @@ -131,35 +130,41 @@ module Core =
let mass = 1000.
let res = toMZ mass 3.
let exp = 334.3406098
Expect.floatClose Accuracy.high res exp (sprintf "Expected %f got %f" exp res)
Expect.floatClose Accuracy.high res exp "Mass to Mz conversion failed."

testCase "test_toMass" <| fun () ->
let mz = 334.3406098
let res = ofMZ mz 3.
let exp = 1000.
Expect.floatClose Accuracy.high res exp (sprintf "Expected %f got %f" exp res)
Expect.floatClose Accuracy.high res exp "Mz to Mass conversion failed."

testCase "test_accuracy" <| fun () ->
let mass = 1000.003
let referenceMass = 1000.001
let res = accuracy mass referenceMass
let exp = 1.999998
Expect.floatClose Accuracy.high res exp (sprintf "Expected %f got %f" exp res)
Expect.floatClose Accuracy.high res exp "Accuracy calculation failed."

testCase "test_deltaMassByPpm" <| fun () ->
let mass = 1000.
let ppm = 100.
let res = deltaMassByPpm ppm mass
let exp = 0.1
Expect.floatClose Accuracy.high res exp (sprintf "Expected %f got %f" exp res)
Expect.floatClose Accuracy.high res exp "Delta mass calculation failed."

testCase "test_rangePpm" <| fun () ->
testList "test_rangePpm" [
let mass = 1000.
let ppm = 100.
let min,max = rangePpm ppm mass
let expMin,expMax = 999.9, 1000.1
Expect.floatClose Accuracy.high min expMin (sprintf "Expected %f got %f" expMin min)
Expect.floatClose Accuracy.high max expMax (sprintf "Expected %f got %f" expMax max)

yield
testCase "lower_Border" <| fun () ->
Expect.floatClose Accuracy.high min expMin "Delta mass calculation failed, lower border is incorrect."
yield
testCase "upper_Border" <| fun () ->
Expect.floatClose Accuracy.high max expMax "Delta mass calculation failed, upper border is incorrect."

]

]

0 comments on commit 0a51f94

Please sign in to comment.