Esempio n. 1
0
 def test_is_empty(self):
     c = CircularBuffer(3)
     assert c.is_empty() is True
     c.enqueue('A')
     assert c.is_empty() is False
     c.dequeue()
     assert c.is_empty() is True
Esempio n. 2
0
 def test_is_empty(self):
     cb = CircularBuffer(2)
     assert cb.is_empty()
     cb.enqueue('test')
     assert not cb.is_empty()
     cb.dequeue()
     assert cb.is_empty()
Esempio n. 3
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
Esempio n. 4
0
 def test_enqueue_and_dequeue(self):
     abcd = ['a', 'b', 'c', 'd']
     cb = CircularBuffer(4)
     for i in range(4):
         cb.enqueue(abcd[i])
         assert cb.size == i + 1
     for i in range(3, 0):
         cb.dequeue()
         assert cb.size == i + 1
Esempio n. 5
0
 def test_dequeue(self):
     cb = CircularBuffer(4)
     cb.enqueue(3)
     cb.enqueue(1)
     cb.enqueue(4)
     cb.enqueue(1)
     assert cb.dequeue() == 3
     assert cb.dequeue() == 1
     assert cb.dequeue() == 4
     assert cb.dequeue() == 1
 def test_enqueue(self):
     buf = CircularBuffer(5)
     assert len(buf) == 0
     buf.enqueue('hi')
     assert len(buf) == 1
     buf.enqueue('boo')
     buf.enqueue('yo')
     buf.enqueue(1)
     buf.enqueue(2)
     buf.enqueue(10)
     assert len(buf) == 5
Esempio n. 7
0
 def test_size(self):
     cb = CircularBuffer()
     assert cb.size == 0
     cb.enqueue('A')
     assert cb.size == 1
     cb.enqueue('B')
     assert cb.size == 2
     cb.dequeue()
     assert cb.size == 1
     cb.dequeue()
     assert cb.size == 0
Esempio n. 8
0
 def test_front(self):
     cb = CircularBuffer()
     assert cb.peek() is None
     cb.enqueue('A')
     assert cb.peek() == 'A'
     cb.enqueue('B')
     assert cb.peek() == 'A'
     cb.dequeue()
     assert cb.peek() == 'B'
     cb.dequeue()
     assert cb.peek() is None
Esempio n. 9
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
Esempio n. 10
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
Esempio n. 11
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
Esempio n. 12
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
Esempio n. 13
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()
Esempio n. 14
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
Esempio n. 15
0
 def test_properties(self):
     cb = CircularBuffer(4)
     cb.enqueue('a')
     assert cb.size == 1
     assert cb.list == ['a', None, None, None]
     cb.enqueue('b')
     assert cb.size == 2
     assert cb.list == ['a', 'b', None, None]
     cb.enqueue('c')
     assert cb.size == 3
     assert cb.list == ['a', 'b', 'c', None]
     cb.enqueue('d')
     assert cb.size == 4
     assert cb.list == ['a', 'b', 'c', 'd']
Esempio n. 16
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
Esempio n. 17
0
 def test_dequeue(self):
     c = CircularBuffer(3)
     with self.assertRaises(ValueError):
         c.dequeue()
     c.enqueue('A')
     c.enqueue('B')
     c.enqueue('C')
     assert c.dequeue() == 'A'
     c.enqueue('D')
     assert c.dequeue() == 'B'
     assert c.dequeue() == 'C'
     c.enqueue('E')
     c.enqueue('F')
     assert c.dequeue() == 'D'
     assert c.dequeue() == 'E'
     assert c.dequeue() == 'F'
     with self.assertRaises(ValueError):
         c.dequeue()
Esempio n. 18
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
Esempio n. 19
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()
Esempio n. 20
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
Esempio n. 21
0
 def test_enqueue(self):
     cb = CircularBuffer()
     cb.enqueue('A')
     assert cb.peek() == 'A'
     assert cb.size == 1
     cb.enqueue('B')
     assert cb.peek() == 'A'
     assert cb.size == 2
     cb.enqueue('C')
     assert cb.peek() == 'A'
     assert cb.size == 3
     assert cb.is_empty() is False
Esempio n. 22
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
Esempio n. 23
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'
Esempio n. 24
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')
Esempio n. 25
0
class CircularBufferTest(unittest.TestCase):
    def setUp(self):
        self.cb = CircularBuffer(4)

    def test_enqueue(self):
        self.cb.enqueue('one')
        self.cb.enqueue('two')
        self.cb.enqueue('three')
        self.cb.enqueue('four')
        self.cb.enqueue('!!!!')
        #Create a __eq__function
        assert self.cb.get_at_index(0) == '!!!!'

    def test_size(self):
        self.cb.enqueue(101)
        self.cb.enqueue(202)
        self.cb.enqueue(303)
        print(self.cb.size())
        assert self.cb.size() == 3
        self.cb.enqueue(404)
        self.cb.enqueue(505)
        assert self.cb.size() == 4