Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.

Purge results in less then MIN_QUEUE_SIZE items #10

Open
Pitel opened this issue Aug 10, 2015 · 1 comment
Open

Purge results in less then MIN_QUEUE_SIZE items #10

Pitel opened this issue Aug 10, 2015 · 1 comment

Comments

@Pitel
Copy link

Pitel commented Aug 10, 2015

The test:

@Test public void testPurge() {
  ShakeDetector.SampleQueue q = new ShakeDetector.SampleQueue();
  q.add(1, true);
  q.add(2, true);
  q.add(3, true);
  q.add(4, true);
  q.add(5, true);
  q.add(6, true);
  q.add(7, true);
  q.add(8, true);
  q.add(9, true);
  assertThat(q.asList()).hasSize(9);
  q.purge(3);
  assertThat(q.asList()).hasSize(7);
  q.purge(8);
  assertThat(q.asList()).hasSize(4); // MIN_QUEUE_SIZE
}

The last assert fails, the size is 3.

@xuegl
Copy link

xuegl commented Dec 9, 2016

The purge condition is

while (sampleCount >= MIN_QUEUE_SIZE  && oldest != null && cutoff - oldest.timestamp > 0) {
        ........
}

When the size of queue reached MIN_QUEUE_SIZE, this loop would still be executed once more, so the exact min size will be MIN_QUEUE_SIZE - 1.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants