2020-09-18 13:26:49 +03:00
|
|
|
/**
|
|
|
|
* Tae Won Ha - http://taewon.de - @hataewon
|
|
|
|
* See LICENSE
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Nimble
|
2020-09-18 17:01:55 +03:00
|
|
|
import XCTest
|
2020-09-18 13:26:49 +03:00
|
|
|
|
|
|
|
@testable import Commons
|
|
|
|
|
|
|
|
class FifoCacheTest: XCTestCase {
|
|
|
|
var fifo: FifoCache<Int, Int>!
|
|
|
|
|
|
|
|
override func setUp() {
|
|
|
|
super.setUp()
|
|
|
|
self.fifo = FifoCache(count: 10, queueQos: .default)
|
|
|
|
}
|
|
|
|
|
|
|
|
func testSimpleGet() {
|
2020-09-18 17:01:55 +03:00
|
|
|
for i in 0...5 { self.fifo.set(i, forKey: i) }
|
2020-09-18 13:26:49 +03:00
|
|
|
|
2020-09-18 17:01:55 +03:00
|
|
|
for i in 0...5 { expect(self.fifo.valueForKey(i)).to(equal(i)) }
|
|
|
|
for i in 6..<10 { expect(self.fifo.valueForKey(i)).to(beNil()) }
|
2020-09-18 13:26:49 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func testGet() {
|
2020-09-18 17:01:55 +03:00
|
|
|
for i in 0..<(10 * 3) { self.fifo.set(i, forKey: i) }
|
|
|
|
for i in 20..<30 { expect(self.fifo.valueForKey(i)).to(equal(i)) }
|
2020-09-18 13:26:49 +03:00
|
|
|
expect(self.fifo.valueForKey(19)).to(beNil())
|
|
|
|
expect(self.fifo.valueForKey(30)).to(beNil())
|
|
|
|
}
|
|
|
|
}
|