예제 #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_dequeue(self):
     q = CircularBuffer(['A', 'B', 'C'])
     assert q.dequeue() == 'A'
     assert q.length() == 2
     assert q.dequeue() == 'B'
     assert q.length() == 1
     assert q.dequeue() == 'C'
     assert q.length() == 0
     assert q.is_empty() is True
     with self.assertRaises(ValueError):
         q.dequeue()
예제 #3
0
 def test_length(self):
     q = CircularBuffer()
     assert q.length() == 0
     q.enqueue('A')
     assert q.length() == 1
     q.enqueue('B')
     assert q.length() == 2
     q.dequeue()
     assert q.length() == 1
     q.dequeue()
     assert q.length() == 0
예제 #4
0
 def test_length(self):
     cb = CircularBuffer(5)
     assert cb.length() == 0
     cb.enqueue('A')
     assert cb.length() == 1
     cb.enqueue('B')
     assert cb.length() == 2
     cb.dequeue()
     assert cb.length() == 1
     cb.dequeue()
     assert cb.length() == 0
예제 #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_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
예제 #7
0
 def test_init(self):
     q = CircularBuffer()
     assert q.front() is None
     assert q.length() == 0
     assert q.is_empty() is True
예제 #8
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
예제 #9
0
 def test_init(self):
     cb = CircularBuffer(5)
     assert cb.front() is None
     assert cb.length() == 0
     assert cb.is_empty() is True