Created
September 15, 2020 12:52
-
-
Save oludouglas/2aa3d76cb88da8b77be31f89ebd80e67 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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