Last active
September 15, 2020 12:57
-
-
Save oludouglas/9acf4a51348fe57723bcafcd8118b39a 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 "testing" | |
type DoublyLinkedListNode struct { | |
value interface{} | |
prev *DoublyLinkedListNode | |
next *DoublyLinkedListNode | |
} | |
func (d *DoublyLinkedListNode) NextNode(node *DoublyLinkedListNode) { | |
d.next = node | |
} | |
func (d *DoublyLinkedListNode) PrevNode(node *DoublyLinkedListNode) { | |
d.prev = node | |
} | |
func TestDoublyLinkedList(t *testing.T) { | |
a := DoublyLinkedListNode{value: 3} | |
b := DoublyLinkedListNode{value: 3} | |
c := DoublyLinkedListNode{value: 3} | |
d := DoublyLinkedListNode{value: 3} | |
a.NextNode(&b) | |
b.NextNode(&c) | |
b.PrevNode(&a) | |
c.NextNode(&d) | |
c.PrevNode(&b) | |
if a.next != &b { | |
t.Errorf("Expected a %v but got %v", &b, a.next) | |
} | |
if a.value != 3 { | |
t.Errorf("Expected a %v but got %v", &b, a.next) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment