From f50e772972dc4022603a5cc0f8c2a98951bfc36e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Furkan=20T=C3=BCrkal?= Date: Thu, 6 Dec 2018 15:19:21 +0300 Subject: [PATCH] [test] added unit test for stack-1-introduction --- .../stack-1-introduction_test.go | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 stack-1-introduction/stack-1-introduction_test.go diff --git a/stack-1-introduction/stack-1-introduction_test.go b/stack-1-introduction/stack-1-introduction_test.go new file mode 100644 index 0000000..2401b1f --- /dev/null +++ b/stack-1-introduction/stack-1-introduction_test.go @@ -0,0 +1,40 @@ +// ==================================================== +// 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 TestStack(t *testing.T) { + var testDatas = []struct { + Stack *Stack + ArrayIn []int + ArrayOut []int + }{ + {New(3), []int{10, 20, 30}, []int{30, 20, 10}}, + {New(5), []int{10, 20, 30, 40, 50}, []int{50, 40, 30, 20, 10}}, + {New(1), []int{7}, []int{7}}, + {New(5), []int{15, 10, 22, 33, 77}, []int{77, 33, 22, 10, 15}}, + } + + for _, data := range testDatas { + for i := uint(0); i < data.Stack.capacity; i++ { + Push(data.Stack, data.ArrayIn[i]) + } + for i := uint(0); i < data.Stack.capacity; i++ { + expected := data.ArrayOut[i] + actual := Pop(data.Stack) + + if !reflect.DeepEqual(expected, actual) { + t.Errorf("Stack: Expected: %d, Actual: %d", expected, actual) + } + } + } +}