exercism / rust

Exercism exercises in Rust.
https://exercism.org/tracks/rust
MIT License
1.48k stars 520 forks source link

Simple-linked-list: test_from_slice test wrong? #960

Closed RalfNorthman closed 4 years ago

RalfNorthman commented 4 years ago

Maybe I'm missing something, but since the list pops from the front shouldn't Some("1") be first instead of last (and so on)?

Test as it is written now:

#[test]                                                                                
  fn test_from_slice() {                                                                 
      let mut array = vec!["1", "2", "3", "4"];                                          
      let mut list: SimpleLinkedList<_> = array.drain(..).collect();                     
      assert_eq!(list.pop(), Some("4"));                                                 
      assert_eq!(list.pop(), Some("3"));                                                 
      assert_eq!(list.pop(), Some("2"));                                                 
      assert_eq!(list.pop(), Some("1"));                                                 
  } 
coriolinus commented 4 years ago

The list doesn't pop from the front; it pops from the list head. See discussion in https://github.com/exercism/rust/issues/834 and here.

RalfNorthman commented 4 years ago

Oh, my mistake, I come from a tradition (e.g. R, elm) where head is at the front and tail is at the back.

Doesn't that sound more intuitive than vice versa?

coriolinus commented 4 years ago

Yes. Unfortunately, saying that the head is at the front has its own set of semantic issues.

Ideally we'd say "top" instead of "head", because we want stack semantics, but that's even more confusing for students who haven't heard of stacks.

On Mon, Jul 27, 2020, 19:49 Ralf Northman notifications@github.com wrote:

Oh, my mistake, I come from a tradition (e.g. R, elm) where head is at the front and tail is at the back.

Doesn't that sound more intuitive than vice versa?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/exercism/rust/issues/960#issuecomment-664543755, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB3V4TQEEUWOU6EKQ5IHR2DR5W4ZJANCNFSM4PIO7K7Q .