Merge pull request #78 from whilei/gofmt-2018-Jun-17-00-39

gofmt
This commit is contained in:
Emir Pasic 2018-06-17 14:34:53 +02:00 committed by GitHub
commit 8c6c64e99f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 34 additions and 31 deletions

View File

@ -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

View File

@ -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)
}
}

View File

@ -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

View File

@ -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)
}
}

View File

@ -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

View File

@ -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)
}
}