예제 #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_overflow(self):
     cb = CircularBuffer(4)
     cb.enqueue(3)
     cb.enqueue(1)
     cb.enqueue(4)
     cb.enqueue(1)
     assert cb.front() == 3
     cb.enqueue(5)
     assert cb.front() == 1
     assert cb.dequeue() == 1
예제 #3
0
 def test_front(self):
     q = CircularBuffer()
     assert q.front() is None
     q.enqueue('A')
     assert q.front() == 'A'
     q.enqueue('B')
     assert q.front() == 'A'
     q.dequeue()
     assert q.front() == 'B'
     q.dequeue()
     assert q.front() is None
예제 #4
0
 def test_front(self):
     cb = CircularBuffer(5)
     assert cb.front() is None
     cb.enqueue('A')
     assert cb.front() == 'A'
     cb.enqueue('B')
     assert cb.front() == 'A'
     cb.dequeue()
     assert cb.front() == 'B'
     cb.dequeue()
     assert cb.front() is None
예제 #5
0
 def test_enqueue(self):
     q = CircularBuffer()
     q.enqueue('A')
     assert q.front() == 'A'
     assert q.length() == 1
     q.enqueue('B')
     assert q.front() == 'A'
     assert q.length() == 2
     q.enqueue('C')
     assert q.front() == 'A'
     assert q.length() == 3
     assert q.is_empty() is False
예제 #6
0
 def test_front(self):
     cb = CircularBuffer(4)
     cb.enqueue(3)
     assert cb.front() == 3
     cb.enqueue(1)
     assert cb.front() == 3
     cb.enqueue(4)
     assert cb.front() == 3
     cb.enqueue(1)
     assert cb.front() == 3
     cb.enqueue(5)
     assert cb.front() == 1
예제 #7
0
 def test_enqueue(self):
     cb = CircularBuffer(5)
     cb.enqueue('A')
     assert cb.front() == 'A'
     assert cb.length() == 1
     cb.enqueue('B')
     assert cb.front() == 'A'
     assert cb.length() == 2
     cb.enqueue('C')
     assert cb.front() == 'A'
     assert cb.length() == 3
     assert cb.is_empty() is False
예제 #8
0
 def test_front(self):
     abcd = ['a', 1, ['dsf', 5, '324'], {'d': 1002}]
     cb = CircularBuffer(4)
     for i in range(4):
         cb.enqueue(abcd[i])
         assert cb.size == i + 1
     assert cb.front() == 'a'
     cb.dequeue()
     assert cb.front() == 1
     cb.dequeue()
     assert cb.front() == ['dsf', 5, '324']
     cb.dequeue()
     assert cb.front() == {'d': 1002}
     cb.dequeue()
예제 #9
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')
예제 #10
0
 def test_front(self):
     c = CircularBuffer(3)
     assert c.front() is None
     c.enqueue('A')
     assert c.front() == 'A'
     c.enqueue('B')
     assert c.front() == 'A'
     c.dequeue()
     assert c.front() == 'B'
     c.dequeue()
     assert c.front() is None
     c.enqueue('C')
     assert c.front() == 'C'
예제 #11
0
 def test_init(self):
     q = CircularBuffer()
     assert q.front() is None
     assert q.length() == 0
     assert q.is_empty() is True
예제 #12
0
 def test_init_with_list(self):
     q = CircularBuffer(['A', 'B', 'C'])
     assert q.front() == 'A'
     assert q.length() == 3
     assert q.is_empty() is False
예제 #13
0
 def test_init(self):
     cb = CircularBuffer(5)
     assert cb.front() is None
     assert cb.length() == 0
     assert cb.is_empty() is True