Skip to content

Commit 9557768

Browse files
committed
add tests median of empty collection
#339
1 parent fa8d850 commit 9557768

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

tests/FSharp.Stats.Tests/Array.fs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ let testArrayNegInfinity = [|10000.;-0.1;14.;-10.;5.;Double.NegativeInfinity|]
1313

1414
let testArrayEvenCountsInt = [|10000;-50;14;-9|]
1515
let testArrayOddCountsInt = [|10000;-50;14;-10;5|]
16+
let testArrayEmptyInt : int array = [||]
17+
let testArrayEmptyFloat : float array = [||]
18+
let testArrayEmptyDec : decimal array = [||]
1619

1720
[<Tests>]
1821
let medianTests =
@@ -33,12 +36,21 @@ let medianTests =
3336
let median = Array.median testArrayNegInfinity
3437
Expect.floatClose Accuracy.high median 2.45 "Median should be 2.45"
3538

36-
testCase "testListEvenCountsInt" <| fun () ->
39+
testCase "testArrayEvenCountsInt" <| fun () ->
3740
let median = Array.median testArrayEvenCountsInt
3841
Expect.equal median 2 "Median should be 2"
39-
testCase "testListOddCountsInt" <| fun () ->
42+
testCase "testArrayOddCountsInt" <| fun () ->
4043
let median = Array.median testArrayOddCountsInt
4144
Expect.equal median 5 "Median should be 5"
45+
testCase "testArrayEmptyFloat" <| fun () ->
46+
let median = Array.median testArrayEmptyFloat
47+
Expect.isTrue (Ops.isNan median) "Median of empty float array should be nan"
48+
testCase "testArrayEmptyInt" <| fun () ->
49+
let median() = Array.median testArrayEmptyInt
50+
Expect.throws (fun () -> median () |> ignore) "Median for empty non-float sequences is not defined"
51+
testCase "testArrayEmptyDec" <| fun () ->
52+
let median() = Array.median testArrayEmptyDec
53+
Expect.throws (fun () -> median () |> ignore) "Median for empty non-float sequences is not defined"
4254
]
4355

4456
[<Tests>]

0 commit comments

Comments
 (0)