From 65869799a07fa3148760469b8474b04f1f99cba8 Mon Sep 17 00:00:00 2001 From: Emir Pasic Date: Mon, 18 Jun 2018 13:13:01 +0200 Subject: [PATCH] Revert "Revert "gofmt"" --- lists/arraylist/arraylist.go | 13 +++++++------ lists/arraylist/arraylist_test.go | 16 ++++++++-------- lists/doublylinkedlist/doublylinkedlist.go | 1 + lists/doublylinkedlist/doublylinkedlist_test.go | 16 ++++++++-------- lists/singlylinkedlist/singlylinkedlist.go | 3 ++- lists/singlylinkedlist/singlylinkedlist_test.go | 16 ++++++++-------- 6 files changed, 34 insertions(+), 31 deletions(-) diff --git a/lists/arraylist/arraylist.go b/lists/arraylist/arraylist.go index e2fbcec..9cb98d8 100644 --- a/lists/arraylist/arraylist.go +++ b/lists/arraylist/arraylist.go @@ -99,17 +99,18 @@ func (list *List) Values() []interface{} { } //IndexOf returns index of provided element -func (list *List) IndexOf(value interface{}) int{ +func (list *List) IndexOf(value interface{}) int { if list.size == 0 { return -1 } - for index, element := range list.elements { - if element == value { - return index - } + for index, element := range list.elements { + if element == value { + return index } - return -1 + } + return -1 } + // Empty returns true if list does not contain any elements. func (list *List) Empty() bool { return list.size == 0 diff --git a/lists/arraylist/arraylist_test.go b/lists/arraylist/arraylist_test.go index abbb2aa..3e31e3d 100644 --- a/lists/arraylist/arraylist_test.go +++ b/lists/arraylist/arraylist_test.go @@ -30,26 +30,26 @@ func TestListIndexOf(t *testing.T) { list := New() expectedIndex := -1 - if index := list.IndexOf("a"); index != expectedIndex{ - t.Errorf("Got %v expected %v",index,expectedIndex) + if index := list.IndexOf("a"); index != expectedIndex { + t.Errorf("Got %v expected %v", index, expectedIndex) } list.Add("a") list.Add("b", "c") expectedIndex = 0 - if index := list.IndexOf("a"); index != expectedIndex{ - t.Errorf("Got %v expected %v",index,expectedIndex) + if index := list.IndexOf("a"); index != expectedIndex { + t.Errorf("Got %v expected %v", index, expectedIndex) } expectedIndex = 1 - if index := list.IndexOf("b"); index != expectedIndex{ - t.Errorf("Got %v expected %v",index,expectedIndex) + if index := list.IndexOf("b"); index != expectedIndex { + t.Errorf("Got %v expected %v", index, expectedIndex) } expectedIndex = 2 - if index := list.IndexOf("c"); index != expectedIndex{ - t.Errorf("Got %v expected %v",index,expectedIndex) + if index := list.IndexOf("c"); index != expectedIndex { + t.Errorf("Got %v expected %v", index, expectedIndex) } } diff --git a/lists/doublylinkedlist/doublylinkedlist.go b/lists/doublylinkedlist/doublylinkedlist.go index 881e0f7..ab0e1bc 100644 --- a/lists/doublylinkedlist/doublylinkedlist.go +++ b/lists/doublylinkedlist/doublylinkedlist.go @@ -185,6 +185,7 @@ func (list *List) IndexOf(value interface{}) int { } return -1 } + // Empty returns true if list does not contain any elements. func (list *List) Empty() bool { return list.size == 0 diff --git a/lists/doublylinkedlist/doublylinkedlist_test.go b/lists/doublylinkedlist/doublylinkedlist_test.go index 444e272..4794da9 100644 --- a/lists/doublylinkedlist/doublylinkedlist_test.go +++ b/lists/doublylinkedlist/doublylinkedlist_test.go @@ -137,26 +137,26 @@ func TestListIndexOf(t *testing.T) { list := New() expectedIndex := -1 - if index := list.IndexOf("a"); index != expectedIndex{ - t.Errorf("Got %v expected %v",index,expectedIndex) + if index := list.IndexOf("a"); index != expectedIndex { + t.Errorf("Got %v expected %v", index, expectedIndex) } list.Add("a") list.Add("b", "c") expectedIndex = 0 - if index := list.IndexOf("a"); index != expectedIndex{ - t.Errorf("Got %v expected %v",index,expectedIndex) + if index := list.IndexOf("a"); index != expectedIndex { + t.Errorf("Got %v expected %v", index, expectedIndex) } expectedIndex = 1 - if index := list.IndexOf("b"); index != expectedIndex{ - t.Errorf("Got %v expected %v",index,expectedIndex) + if index := list.IndexOf("b"); index != expectedIndex { + t.Errorf("Got %v expected %v", index, expectedIndex) } expectedIndex = 2 - if index := list.IndexOf("c"); index != expectedIndex{ - t.Errorf("Got %v expected %v",index,expectedIndex) + if index := list.IndexOf("c"); index != expectedIndex { + t.Errorf("Got %v expected %v", index, expectedIndex) } } diff --git a/lists/singlylinkedlist/singlylinkedlist.go b/lists/singlylinkedlist/singlylinkedlist.go index 3182af3..45ee69c 100644 --- a/lists/singlylinkedlist/singlylinkedlist.go +++ b/lists/singlylinkedlist/singlylinkedlist.go @@ -155,7 +155,7 @@ func (list *List) Values() []interface{} { } //IndexOf returns index of provided element -func (list *List) IndexOf(value interface{}) int{ +func (list *List) IndexOf(value interface{}) int { if list.size == 0 { return -1 } @@ -166,6 +166,7 @@ func (list *List) IndexOf(value interface{}) int{ } return -1 } + // Empty returns true if list does not contain any elements. func (list *List) Empty() bool { return list.size == 0 diff --git a/lists/singlylinkedlist/singlylinkedlist_test.go b/lists/singlylinkedlist/singlylinkedlist_test.go index 0bebbb3..36e080d 100644 --- a/lists/singlylinkedlist/singlylinkedlist_test.go +++ b/lists/singlylinkedlist/singlylinkedlist_test.go @@ -137,26 +137,26 @@ func TestListIndexOf(t *testing.T) { list := New() expectedIndex := -1 - if index := list.IndexOf("a"); index != expectedIndex{ - t.Errorf("Got %v expected %v",index,expectedIndex) + if index := list.IndexOf("a"); index != expectedIndex { + t.Errorf("Got %v expected %v", index, expectedIndex) } list.Add("a") list.Add("b", "c") expectedIndex = 0 - if index := list.IndexOf("a"); index != expectedIndex{ - t.Errorf("Got %v expected %v",index,expectedIndex) + if index := list.IndexOf("a"); index != expectedIndex { + t.Errorf("Got %v expected %v", index, expectedIndex) } expectedIndex = 1 - if index := list.IndexOf("b"); index != expectedIndex{ - t.Errorf("Got %v expected %v",index,expectedIndex) + if index := list.IndexOf("b"); index != expectedIndex { + t.Errorf("Got %v expected %v", index, expectedIndex) } expectedIndex = 2 - if index := list.IndexOf("c"); index != expectedIndex{ - t.Errorf("Got %v expected %v",index,expectedIndex) + if index := list.IndexOf("c"); index != expectedIndex { + t.Errorf("Got %v expected %v", index, expectedIndex) } }