View slices_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
name: "Compare slices with different number of elements", | |
args: args{ | |
a: []int{1, 2, 3, 4}, | |
b: []int{2, 4, 1}, | |
}, | |
want: false, | |
}, |
View slices_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
name: "Compare slices with same number of elements but different elements", | |
args: args{ | |
a: []int{1, 2, 3, 4}, | |
b: []int{5, 2, 4, 1}, | |
}, | |
want: false, | |
}, |
View slices_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestAreSlicesEqual(t *testing.T) { | |
type args struct { | |
a []int | |
b []int | |
} | |
tests := []struct { | |
name string | |
args args | |
want bool | |
}{ |
View slices_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestAreSlicesEqual(t *testing.T) { | |
type args struct { | |
a []int | |
b []int | |
} | |
tests := []struct { | |
name string | |
args args | |
want bool | |
}{ |
View slices.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func AreSlicesEqual(a, b []int) bool { | |
if len(a) != len(b) { | |
return false | |
} | |
for _, i := range a { | |
if !DoesSliceIncludesInt(i, b) { | |
return false | |
} | |
} |
View slices_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func TestDoesSliceIncludesIntNotInSlice(t *testing.T) { | |
inputValue := 4 | |
inputSlice := []int{1, 2, 3} | |
expectedOutput := false | |
got := DoesSliceIncludesInt(inputValue, inputSlice) | |
if got != expectedOutput { | |
t.Errorf("SliceIncludesInt(%d, %d) = %t; want %t", inputValue, inputSlice, got, expectedOutput) |
View slices_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package helpers | |
import "testing" | |
func TestDoesSliceIncludesInt(t *testing.T) { | |
inputValue := 3 | |
inputSlice := []int{1, 2, 3} | |
expectedOutput := true |
View slices_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package helpers | |
import "testing" | |
func TestDoesSliceIncludesInt(t *testing.T) { | |
inputValue := 3 | |
inputSlice := []int{1, 2, 3} | |
expectedOutput := true |
View slices_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package helpers | |
import "testing" | |
func TestDoesSliceIncludesInt(t *testing.T) { | |
// Content of the test | |
} |
View slices.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package helpers | |
func DoesSliceIncludesInt(value int, slice []int) bool { | |
for _, i := range slice { | |
if value == i { | |
return true | |
} | |
} | |
return false | |
} |
NewerOlder