diff --git a/src/FSharpx.Collections/CircularBuffer.fs b/src/FSharpx.Collections/CircularBuffer.fs index ea44f8db..406b1f8a 100644 --- a/src/FSharpx.Collections/CircularBuffer.fs +++ b/src/FSharpx.Collections/CircularBuffer.fs @@ -53,12 +53,14 @@ type CircularBuffer<'T>(bufferSize: int) = let mutable offset = offset - head <- (head + 1) % bufferSize + let startPos = (head + 1) % bufferSize - for x, y in nextBuffer head count do + for x, y in nextBuffer startPos count do Array.blit value offset buffer x y offset <- offset + y + head <- (head + count) % bufferSize + if length = bufferSize then tail <- (tail + count) % bufferSize else diff --git a/tests/FSharpx.Collections.Tests/CircularBufferTests.fs b/tests/FSharpx.Collections.Tests/CircularBufferTests.fs index ae455d44..16f66113 100644 --- a/tests/FSharpx.Collections.Tests/CircularBufferTests.fs +++ b/tests/FSharpx.Collections.Tests/CircularBufferTests.fs @@ -84,7 +84,7 @@ module CircularBufferTests = Expect.throwsT "" f } - ptest "Printing after multiple enqueue circles" { + test "Printing after multiple enqueue circles" { let circularBuffer = CircularBuffer 5 circularBuffer.Enqueue [| 1; 2; 3; 4; 5 |] @@ -96,7 +96,7 @@ module CircularBufferTests = - ptest "Printing from a queue 1..8 and dequeue 5, then enqueue 1..3 and dequeue 3, from array" { + test "Printing from a queue 1..8 and dequeue 5, then enqueue 1..3 and dequeue 3, from array" { let circularBuffer = CircularBuffer 5 circularBuffer.Enqueue([| 1; 2; 3; 4; 5 |]) @@ -106,7 +106,7 @@ module CircularBufferTests = Expect.equal "buffer" [| 1; 2; 3 |] <| circularBuffer.Dequeue 3 } - ptest "Consider a large array with various, incoming array segments" { + test "Consider a large array with various, incoming array segments" { let circularBuffer = CircularBuffer 5 let source =