Skip to content

Commit 08a9096

Browse files
committed
Update README
1 parent 0b4376c commit 08a9096

File tree

2 files changed

+22
-51
lines changed

2 files changed

+22
-51
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,7 @@ This Sprint Challenge is split into three parts:
3030

3131
A ring buffer is a non-growable buffer with a fixed size. When the ring buffer is full and a new element is inserted, the oldest element in the ring buffer is overwritten with the newest element. This kind of data structure is very useful for use cases such as storing logs and history information, where you typically want to store information up until it reaches a certain age, after which you don't care about it anymore and don't mind seeing it overwritten by newer data.
3232

33-
Implement this behavior in the RingBuffer class. RingBuffer has two methods, `append` and `get`. The `append` method adds elements to the buffer. The `get` method, which is provided, returns all of the elements in the buffer in a list in their given order. It should not return any `None` values in the list even if they are present in the ring buffer.
34-
35-
_You may not use a Python List in your implementation of the `append` method (except for the stretch goal)_
36-
37-
*Stretch Goal*: Another method of implementing a ring buffer uses an array (Python List) instead of a linked list. What are the advantages and disadvantages of using this method? What disadvantage normally found in arrays is overcome with this arrangement?
33+
Implement this behavior in the RingBuffer class. RingBuffer has two methods, `append` and `get`. The `append` method adds the given element to the buffer. The `get` method returns all of the elements in the buffer in a list in their given order. It should not return any `None` values in the list even if they are present in the ring buffer.
3834

3935
For example:
4036

@@ -73,7 +69,7 @@ Six seconds is an eternity so you've been tasked with speeding up the code. Can
7369
(Hint: You might try importing a data structure you built during the week)
7470

7571

76-
#### Task 3. Reverse a Linked List Recursively
72+
#### Task 3. Reverse a Linked List
7773

7874
Inside of the `reverse` directory, you'll find a basic implementation of a Singly Linked List. _Without_ making it a Doubly Linked List (adding a tail attribute), complete the `reverse_list()` function within `reverse/reverse.py` reverse the contents of the list using recursion, *not a loop.*
7975

ring_buffer/test_ring_buffer.py

Lines changed: 20 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,75 +3,50 @@
33

44
class RingBufferTests(unittest.TestCase):
55
def setUp(self):
6-
self.buffer = RingBuffer(5)
7-
self.buffer_2 = RingBuffer(5)
6+
self.capacity = 5
7+
self.buffer = RingBuffer(self.capacity)
8+
9+
def test_new_buffer_has_appropriate_capacity(self):
10+
self.assertEqual(self.buffer.capacity, self.capacity)
811

9-
def test_ring_buffer(self):
10-
self.assertEqual(self.buffer.storage.length, 0)
12+
def test_adding_one_element_to_buffer(self):
13+
self.buffer.append('a')
14+
self.assertEqual(self.buffer.get(), ['a'])
1115

16+
def test_filling_buffer_to_capacity(self):
1217
self.buffer.append('a')
1318
self.buffer.append('b')
1419
self.buffer.append('c')
1520
self.buffer.append('d')
16-
self.assertEqual(self.buffer.storage.length, 4)
17-
self.assertEqual(self.buffer.get(), ['a', 'b', 'c', 'd'])
18-
1921
self.buffer.append('e')
20-
self.assertEqual(self.buffer.storage.length, 5)
2122
self.assertEqual(self.buffer.get(), ['a', 'b', 'c', 'd', 'e'])
2223

24+
def test_adding_one_element_to_full_buffer(self):
25+
self.buffer.append('a')
26+
self.buffer.append('b')
27+
self.buffer.append('c')
28+
self.buffer.append('d')
29+
self.buffer.append('e')
2330
self.buffer.append('f')
24-
self.assertEqual(self.buffer.storage.length, 5)
2531
self.assertEqual(self.buffer.get(), ['f', 'b', 'c', 'd', 'e'])
2632

27-
self.buffer.append('g')
28-
self.buffer.append('h')
29-
self.buffer.append('i')
30-
self.assertEqual(self.buffer.storage.length, 5)
31-
self.assertEqual(self.buffer.get(), ['f', 'g', 'h', 'i', 'e'])
32-
33-
self.buffer.append('j')
34-
self.buffer.append('k')
35-
self.assertEqual(self.buffer.get(), ['k', 'g', 'h', 'i', 'j'])
36-
37-
for i in range(50):
38-
self.buffer_2.append(i)
39-
self.assertEqual(self.buffer_2.get(), [45, 46, 47, 48, 49])
40-
41-
42-
class ArrayRingBufferTests(unittest.TestCase):
43-
def setUp(self):
44-
self.buffer = ArrayRingBuffer(5)
45-
self.buffer_2 = ArrayRingBuffer(5)
46-
47-
def test__array_ring_buffer(self):
48-
self.assertEqual(len(self.buffer.storage), 5)
49-
33+
def test_adding_many_elements_to_full_buffer(self):
5034
self.buffer.append('a')
5135
self.buffer.append('b')
5236
self.buffer.append('c')
5337
self.buffer.append('d')
54-
self.assertEqual(len(self.buffer.storage), 5)
55-
self.assertEqual(self.buffer.get(), ['a', 'b', 'c', 'd'])
56-
5738
self.buffer.append('e')
58-
self.assertEqual(len(self.buffer.storage), 5)
59-
self.assertEqual(self.buffer.get(), ['a', 'b', 'c', 'd', 'e'])
60-
6139
self.buffer.append('f')
62-
self.assertEqual(len(self.buffer.storage), 5)
63-
self.assertEqual(self.buffer.get(), ['f', 'b', 'c', 'd', 'e'])
64-
6540
self.buffer.append('g')
6641
self.buffer.append('h')
6742
self.buffer.append('i')
68-
self.assertEqual(len(self.buffer.storage), 5)
6943
self.assertEqual(self.buffer.get(), ['f', 'g', 'h', 'i', 'e'])
7044

45+
def test_adding_50_elements_to_buffer(self):
7146
for i in range(50):
72-
self.buffer_2.append(i)
73-
self.assertEqual(self.buffer_2.get(), [45, 46, 47, 48, 49])
47+
self.buffer.append(i)
7448

49+
self.assertEqual(self.buffer.get(), [45, 46, 47, 48, 49])
7550

7651
if __name__ == '__main__':
77-
unittest.main()
52+
unittest.main()

0 commit comments

Comments
 (0)