Skip to content

Instantly share code, notes, and snippets.

@nobeans
Created June 26, 2018 01:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobeans/bce796d6f0f839392b01e93ccc31e6db to your computer and use it in GitHub Desktop.
Save nobeans/bce796d6f0f839392b01e93ccc31e6db to your computer and use it in GitHub Desktop.
class ApacheCollectionsSpec extends Specification {
def "BoundedFifoBuffer"() {
given:
def buffer = new BoundedFifoBuffer(3)
when:
buffer.add(1)
buffer.add(2)
buffer.add(3)
then:
buffer.toList() == [1, 2, 3]
when:
buffer.add(4)
then: // 単純にサイズ以上は入らない
thrown BufferOverflowException
}
def "CircularFifoBuffer"() {
given:
def buffer = new CircularFifoBuffer(3)
when:
buffer.add(1)
buffer.add(2)
buffer.add(3)
then:
buffer.toList() == [1, 2, 3]
when:
buffer.add(4)
then:
buffer.toList() == [2, 3, 4]
when: // LRUではないので参照しても追い出される順序は変わらない
buffer.get() == 2
and:
buffer.add(5)
then:
buffer.toList() == [3, 4, 5]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment