From c4eb407e2c57ee53684487a71b22ff3f1cd62046 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20T=C3=BCrkal?= Date: Thu, 6 Dec 2018 15:45:35 +0300 Subject: [PATCH] [test] added unit test for linked-list-reverse --- .../linked-list-reverse_test.go | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 linked-list-reverse/linked-list-reverse_test.go diff --git a/linked-list-reverse/linked-list-reverse_test.go b/linked-list-reverse/linked-list-reverse_test.go new file mode 100644 index 0000000..bcd36da --- /dev/null +++ b/linked-list-reverse/linked-list-reverse_test.go @@ -0,0 +1,47 @@ +// ==================================================== +// Data-Structures-with-Go Copyright(C) 2017 Furkan Türkal +// This program comes with ABSOLUTELY NO WARRANTY; This is free software, +// and you are welcome to redistribute it under certain conditions; See +// file LICENSE, which is part of this source code package, for details. +// ==================================================== + +package main + +import ( + "reflect" + "testing" +) + +func TestLinkedListReverse(t *testing.T) { + var testDatas = []struct { + Node *Node + ArrayIn []int + ArrayOut []int + }{ + {New(), []int{20, 4, 15, 85}, []int{-1, 20, 4, 15, 85, -1}}, + {New(), []int{10, 20, 30, 40, 50}, []int{-1, 10, 20, 30, 40, 50, -1}}, + {New(), []int{7}, []int{-1, 7, -1}}, + } + + for _, data := range testDatas { + for i := 0; i < len(data.ArrayIn); i++ { + Push(&data.Node, data.ArrayIn[i]) + } + + Reverse(&data.Node) + + n := data.Node + i := 0 + for n != nil { + expected := data.ArrayOut[i] + actual := n.data + + if !reflect.DeepEqual(expected, actual) { + t.Errorf("LinkedListReverse: Expected: %d, Actual: %d", expected, actual) + } + + n = n.Next() + i++ + } + } +}