Skip to content

Commit c4eb407

Browse files
committed
[test] added unit test for linked-list-reverse
1 parent f50e772 commit c4eb407

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// ====================================================
2+
// Data-Structures-with-Go Copyright(C) 2017 Furkan Türkal
3+
// This program comes with ABSOLUTELY NO WARRANTY; This is free software,
4+
// and you are welcome to redistribute it under certain conditions; See
5+
// file LICENSE, which is part of this source code package, for details.
6+
// ====================================================
7+
8+
package main
9+
10+
import (
11+
"reflect"
12+
"testing"
13+
)
14+
15+
func TestLinkedListReverse(t *testing.T) {
16+
var testDatas = []struct {
17+
Node *Node
18+
ArrayIn []int
19+
ArrayOut []int
20+
}{
21+
{New(), []int{20, 4, 15, 85}, []int{-1, 20, 4, 15, 85, -1}},
22+
{New(), []int{10, 20, 30, 40, 50}, []int{-1, 10, 20, 30, 40, 50, -1}},
23+
{New(), []int{7}, []int{-1, 7, -1}},
24+
}
25+
26+
for _, data := range testDatas {
27+
for i := 0; i < len(data.ArrayIn); i++ {
28+
Push(&data.Node, data.ArrayIn[i])
29+
}
30+
31+
Reverse(&data.Node)
32+
33+
n := data.Node
34+
i := 0
35+
for n != nil {
36+
expected := data.ArrayOut[i]
37+
actual := n.data
38+
39+
if !reflect.DeepEqual(expected, actual) {
40+
t.Errorf("LinkedListReverse: Expected: %d, Actual: %d", expected, actual)
41+
}
42+
43+
n = n.Next()
44+
i++
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)