def test_buffer_fill_size_return(self): ''' Test that buffer fill size is correctly returned under various use scenarios ''' # Test that buffer fill size is returned as # 0 when buffer is empty random_size = random.randrange(1, 100) buffer = RingBuffer(random_size) fill_size = buffer.get_buffer_fill() self.assertEqual(fill_size, 0) # Test that buffer fill size is returned as # the number of elements pushed when the # buffer is neither empty nor full random_size = random.randrange(1, 100) buffer = RingBuffer(random_size) for i in range(0, int(random_size / 2)): buffer.push(i) fill_size = buffer.get_buffer_fill() self.assertEqual(fill_size, int(random_size / 2)) # Test that buffer fill size is correctly # returned when buffer is full random_size = random.randrange(1, 100) buffer = RingBuffer(random_size) for i in range(0, random_size): buffer.push(i) fill_size = buffer.get_buffer_fill() self.assertEqual(fill_size, random_size)
def test_initialize_params(self): ''' Test that buffer init params are returned correctly ''' random_size = random.randrange(1, 100) buffer = RingBuffer(random_size) self.assertEqual(buffer.get_capacity(), random_size) self.assertFalse(buffer.is_full()) self.assertTrue(buffer.is_empty()) self.assertEqual(buffer.get_buffer_fill(), 0)
def test_clear(self): ''' Test that clear() method clears the buffer properly ''' random_size = random.randrange(1, 100) buffer = RingBuffer(random_size) for i in range(0, random.randrange(1, random_size)): buffer.push(i) buffer.clear() self.assertTrue(buffer.is_empty()) self.assertFalse(buffer.is_full()) self.assertEqual(buffer.get_capacity(), random_size) self.assertEqual(buffer.get_buffer_fill(), 0)