示例#1
0
 def test_rollover(self):
     cb = CircularBuffer(5, ['A', 'B', 'C', 'D', 'E'])
     assert cb.front() == 'A'
     assert cb.length() == 5
     assert cb.is_full() is True
     cb.enqueue('X')
     assert cb.front() == 'X'
     assert cb.length() == 5
     assert cb.is_full() is True
示例#2
0
 def test_is_full(self):
     c = CircularBuffer(3)
     assert c.is_full() is False
     c.enqueue('A')
     assert c.is_full() is False
     c.enqueue('B')
     assert c.is_full() is False
     c.enqueue('C')
     assert c.is_full() is True
     c.dequeue()
     assert c.is_full() is False
示例#3
0
 def test_is_full(self):
     cb = CircularBuffer(3)
     assert not cb.is_full()
     cb.enqueue('test')
     assert not cb.is_full()
     cb.enqueue('other test')
     assert not cb.is_full()
     cb.enqueue(12345)
     assert cb.is_full()
     cb.dequeue()
     assert not cb.is_full()
示例#4
0
 def test_init(self):
     c = CircularBuffer(3)
     assert c.max_size == 3
     assert c.size == 0
     assert c.start == 0
     assert c.end == 0
     assert c.is_empty() is True
     assert c.is_full() is False
示例#5
0
 def test_enqueue(self):
     cb = CircularBuffer(4)
     cb.enqueue(3)
     assert cb.size == 1
     assert len(cb) == 4
     assert cb.is_empty() == False
     cb.enqueue(1)
     assert cb.size == 2
     cb.enqueue(4)
     assert cb.size == 3
     cb.enqueue(1)
     assert cb.size == 4
     assert cb.is_full() == True
     cb.enqueue(5)
     assert cb.size == 4
示例#6
0
 def test_enqueue(self):
     c = CircularBuffer(3)
     c.enqueue('A')
     assert c.size == 1
     assert c.start == 0
     assert c.end == 1
     assert c.front() == 'A'
     c.enqueue('B')
     assert c.size == 2
     assert c.start == 0
     assert c.end == 2
     assert c.front() == 'A'
     c.enqueue('C')
     assert c.size == 3
     assert c.start == 0
     assert c.end == 0
     assert c.front() == 'A'
     assert c.is_full() is True
     with self.assertRaises(ValueError):
         c.enqueue('D')