Skip to content

Commit

Permalink
#559: Fix Series.windowSize throw IndexOutOfRangeException when size …
Browse files Browse the repository at this point in the history
…bigger than input length.
  • Loading branch information
Matthew Thornton committed Jul 11, 2023
1 parent 93c624e commit c60f995
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions tests/Deedle.Tests/Common.fs
Original file line number Diff line number Diff line change
Expand Up @@ -195,19 +195,51 @@ let ``Seq.windowedWithBounds can generate boundary at the beginning`` () =
[| DataSegment(Incomplete, [| 1 |]); DataSegment(Incomplete, [| 1; 2 |])
DataSegment(Complete, [| 1; 2; 3 |]); DataSegment(Complete, [| 2; 3; 4 |]) |]

[<Test>]
let ``Seq.windowedWithBounds can generate boundary at the beginning when input length equals size`` () =
Seq.windowedWithBounds 3 Boundary.AtBeginning [ 1; 2; 3 ] |> Array.ofSeq
|> shouldEqual
[| DataSegment(Incomplete, [| 1 |]); DataSegment(Incomplete, [| 1; 2 |])
DataSegment(Complete, [| 1; 2; 3 |]) |]

[<Test>]
let ``Seq.windowedWithBounds can generate boundary at the beginning when input length is less than size`` () =
Seq.windowedWithBounds 10 Boundary.AtBeginning [ 1; 2; ] |> Array.ofSeq
|> shouldEqual
[| DataSegment(Incomplete, [| 1 |]); DataSegment(Incomplete, [| 1; 2 |]) |]

[<Test>]
let ``Seq.windowedWithBounds can skip boundaries`` () =
Seq.windowedWithBounds 3 Boundary.Skip [ 1; 2; 3; 4 ] |> Array.ofSeq
|> shouldEqual
[| DataSegment(Complete, [| 1; 2; 3 |]); DataSegment(Complete, [| 2; 3; 4 |]) |]

[<Test>]
let ``Seq.windowedWithBounds is empty when input length is less than size`` () =
Seq.windowedWithBounds 10 Boundary.Skip [ 1; 2; 3; 4 ] |> Array.ofSeq
|> shouldEqual
[| |]

[<Test>]
let ``Seq.windowedWithBounds can generate boundary at the ending`` () =
Seq.windowedWithBounds 3 Boundary.AtEnding [ 1; 2; 3; 4 ] |> Array.ofSeq
|> shouldEqual
[| DataSegment(Complete, [| 1; 2; 3 |]); DataSegment(Complete, [| 2; 3; 4 |])
DataSegment(Incomplete, [| 3; 4 |]); DataSegment(Incomplete, [| 4 |]) |]

[<Test>]
let ``Seq.windowedWithBounds can generate boundary at the ending when input length equals size`` () =
Seq.windowedWithBounds 3 Boundary.AtEnding [ 1; 2; 3 ] |> Array.ofSeq
|> shouldEqual
[| DataSegment(Complete, [| 1; 2; 3 |])
DataSegment(Incomplete, [| 2; 3 |]); DataSegment(Incomplete, [| 3 |]) |]

[<Test>]
let ``Seq.windowedWithBounds can generate boundary at the ending when input length is less than size`` () =
Seq.windowedWithBounds 10 Boundary.AtEnding [ 1; 2 ] |> Array.ofSeq
|> shouldEqual
[| DataSegment(Incomplete, [| 1; 2 |]); DataSegment(Incomplete, [| 2 |]) |]

[<Test>]
let ``Seq.chunkedWithBounds works when length is multiple of chunk size`` () =
Seq.chunkedWithBounds 3 Boundary.AtBeginning [ 1 .. 9 ] |> Array.ofSeq
Expand Down Expand Up @@ -250,6 +282,58 @@ let ``Seq.chunkedWithBounds can skip incomplete chunk at the end`` () =
[| DataSegment(Complete, [|1; 2; 3|]); DataSegment(Complete, [|4; 5; 6|]);
DataSegment(Complete, [|7; 8; 9|]) |]

[<Test>]
let ``Seq.windowRangesWithBounds can generate boundary at the beginning`` () =
Seq.windowRangesWithBounds 3 Boundary.AtBeginning 4L |> Array.ofSeq
|> shouldEqual
[| DataSegmentKind.Incomplete, 0, 0; DataSegmentKind.Incomplete, 0, 1
DataSegmentKind.Complete, 0, 2; DataSegmentKind.Complete, 1, 3 |]

[<Test>]
let ``Seq.windowRangesWithBounds can generate boundary at the beginning when input length equals size`` () =
Seq.windowRangesWithBounds 3 Boundary.AtBeginning 3L |> Array.ofSeq
|> shouldEqual
[| DataSegmentKind.Incomplete, 0, 0; DataSegmentKind.Incomplete, 0, 1
DataSegmentKind.Complete, 0, 2 |]

[<Test>]
let ``Seq.windowRangesWithBounds can generate boundary at the beginning when input length is less than size`` () =
Seq.windowRangesWithBounds 10 Boundary.AtBeginning 2L |> Array.ofSeq
|> shouldEqual
[| DataSegmentKind.Incomplete, 0, 0; DataSegmentKind.Incomplete, 0, 1 |]

[<Test>]
let ``Seq.windowRangesWithBounds can skip boundaries`` () =
Seq.windowRangesWithBounds 3 Boundary.Skip 4L |> Array.ofSeq
|> shouldEqual
[| DataSegmentKind.Complete, 0, 2; DataSegmentKind.Complete, 1, 3 |]

[<Test>]
let ``Seq.windowRangesWithBounds is empty when input length is less than size`` () =
Seq.windowRangesWithBounds 10 Boundary.Skip 4L |> Array.ofSeq
|> shouldEqual
[| |]

[<Test>]
let ``Seq.windowRangesWithBounds can generate boundary at the ending`` () =
Seq.windowRangesWithBounds 3 Boundary.AtEnding 4L |> Array.ofSeq
|> shouldEqual
[| DataSegmentKind.Complete, 0, 2; DataSegmentKind.Complete, 1, 3
DataSegmentKind.Incomplete, 2, 3; DataSegmentKind.Incomplete, 3, 3 |]

[<Test>]
let ``Seq.windowRangesWithBounds can generate boundary at the ending when input length equals size`` () =
Seq.windowRangesWithBounds 3 Boundary.AtEnding 3L |> Array.ofSeq
|> shouldEqual
[| DataSegmentKind.Complete, 0, 2
DataSegmentKind.Incomplete, 1, 2; DataSegmentKind.Incomplete, 2, 2 |]

[<Test>]
let ``Seq.windowRangesWithBounds can generate boundary at the ending when input length is less than size`` () =
Seq.windowRangesWithBounds 10 Boundary.AtEnding 2L |> Array.ofSeq
|> shouldEqual
[| DataSegmentKind.Incomplete, 0, 1; DataSegmentKind.Incomplete, 1, 1 |]

[<Test>]
let ``Seq.alignOrdered (union) satisfies basic conditions`` () =
let comparer = System.Collections.Generic.Comparer<int>.Default
Expand Down

0 comments on commit c60f995

Please sign in to comment.