ruby
ruby copied to clipboard
Simple Linked List exercise confusion
Hello everyone!
I've mentored some people in the Simple Linked List exercise and I think the instructions or intent are not clear.
The main doubt I have is: is the student supposed to implement a linked list optimized for FIFO or LIFO operations? Or is the ambiguity and openness to these two options intentional?
def test_list_create_from_array
array = [1, 2, 3]
list = SimpleLinkedList.new(array)
assert_equal [3, 2, 1], list.to_a
end
def test_list_multiple_to_array
skip
list = SimpleLinkedList.new
first = Element.new(1)
second = Element.new(2)
third = Element.new(3)
list.push(first).push(second).push(third)
assert_equal [3, 2, 1], list.to_a
end
When I see the tests above, I get extremely confused:
- A simple linked list is created with
[1, 2, 3]but transforming it to an array returns[3, 2, 1]. - A simple linked list is created. We push the elements in the order: 1, 2, and 3. Pushing is a operation that appends something to the end of a list. But transforming to an array returns
[3, 2, 1]instead of[1, 2, 3]. The exact opposite behaviour of the built-inArrayclass.
That doesn't seem to make sense. 🤔
The problem description mention stacks and sequences in an merely informative way:
This variant of linked lists is often used to represent sequences or push-down stacks (also called a LIFO stack; Last In, First Out).
But asks students to implement "a singly linked list", without specification:
As a first take, lets create a singly linked list to contain the range (1..10), and provide functions to reverse a linked list and convert to and from arrays.
Even the inspiration material linked in this exercise has no mention about stacks at all.
We have to clarify the problem description or possibly update the tests to better reflect the intent of the exercise. For example, if the intent is for students to implement and optimize for a stack, we should probably rename the class SimpleLinkedList to Stack.
I think I personally found the idea of a stack strong-ish implied given there is an explicit test for LIFO behavior. That plus the reversal behavior, but I can see where someone might find that behavior confusing. It would help to be certain first you were dealing with a stack.
we should probably rename the class SimpleLinkedList to Stack.
This would surely add some clarity :-) It should be noted if we find this unclear that this exercise is spread across MANY if not all tracks, so we may need to update them all - do we still have canonical text/verbiage anywhere or did that go away with version 3?
The canonical will be started from the problem specifications and then may be further specified in the language track via test generation or documentation. The ruby exercise information appears to come directly unmodified from the problem specifications.
Yeah, that would have been my guess. :)
I'm going to close this, as the conclusion was that the change needs to be proposed in the Problem Specifications repository.
The simple linked list is currently up-to-date with the problem-specifications repository, and if further changes are made there, we can sync this exercise again.