Created
June 26, 2018 01:09
-
-
Save nobeans/bce796d6f0f839392b01e93ccc31e6db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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