Skip to content

Commit

Permalink
add map merge tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bvenn committed Apr 26, 2023
1 parent 44c8071 commit 9bd6c08
Showing 1 changed file with 43 additions and 1 deletion.
44 changes: 43 additions & 1 deletion tests/FSharp.Stats.Tests/DistributionsEmpirical.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ open TestExtensions
[<Tests>]
let empiricalTests =


let mySmallAlphabet = "abcdefghijklmnopqrstuvwxyz" |> Set.ofSeq
let myAlphabet = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" |> Set.ofSeq
let myAlphabetNum = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" |> Set.ofSeq
Expand Down Expand Up @@ -146,5 +145,48 @@ let empiricalTests =
"Empirical.createNominal leads to a wrong PMF map keys"
TestExtensions.sequenceEqual(Accuracy.high) expectedValues actualValues
"Empirical.createNominal leads to a wrong PMF map values"
let a =
[
(0.2,12)
(0.0,5)
(-0.1,3)
]
|> Map.ofList

let b =
[
(0.2,-10)
(0.3,2)
(0.0,0)
]
|> Map.ofList

testCase "add" <| fun () ->
let expectedKeys,expectedValues =
Map.ofSeq [|(-0.1,3);(0.0,5);(0.2,2);(0.3,2)|]
|> Map.toArray
|> Array.unzip
let actualKeys,actualValues =
Empirical.add a b
|> Map.toArray
|> Array.unzip
Expect.equal expectedKeys actualKeys
"Empirical.add leads to a wrong distribution addition"
Expect.equal expectedValues actualValues
"Empirical.add leads to a wrong distribution addition"

testCase "merge" <| fun () ->
let expectedKeys,expectedValues =
Map.ofSeq [|(-0.1,3);(0.0,0);(0.2,-10);(0.3,2)|]
|> Map.toArray
|> Array.unzip
let actualKeys,actualValues =
Empirical.merge a b
|> Map.toArray
|> Array.unzip
Expect.equal expectedKeys actualKeys
"Empirical.merge leads to a wrong distribution merge"
Expect.equal expectedValues actualValues
"Empirical.merge leads to a wrong distribution merge"
]

0 comments on commit 9bd6c08

Please sign in to comment.