Skip to content

Instantly share code, notes, and snippets.

@oludouglas
Created September 15, 2020 12:52
Show Gist options
  • Save oludouglas/2aa3d76cb88da8b77be31f89ebd80e67 to your computer and use it in GitHub Desktop.
Save oludouglas/2aa3d76cb88da8b77be31f89ebd80e67 to your computer and use it in GitHub Desktop.
package interviews
import (
"reflect"
"testing"
)
type SinglyLinkedList struct {
val interface{}
nextnode *SinglyLinkedList
}
func (s SinglyLinkedList) Size() int {
return 0
}
func (s *SinglyLinkedList) NextNode(nextNode *SinglyLinkedList) {
s.nextnode = nextNode
}
func TestSinglyLinkedList(t *testing.T) {
a := SinglyLinkedList{val: 12}
want := 0
got := a.Size()
if got != want {
t.Errorf("Expected a size of %d but got %d", want, got)
}
b := SinglyLinkedList{val: 15}
a.NextNode(&b)
c := SinglyLinkedList{val: 16}
b.NextNode(&c)
if b.nextnode != &c {
t.Errorf("expected %v but got %v", c, b.nextnode)
}
if b.val != 15 {
t.Errorf("expected %v but got %v", c, b.nextnode)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment