Created
September 6, 2019 20:22
-
-
Save michaljemala/6059f1937dde8e308e4fd364baa2ee98 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 main | |
import ( | |
"fmt" | |
"hova.dzia.poliev.ka/slice" | |
) | |
func main() { | |
x := slice.Unordered{1, 2, 3} | |
y := slice.Unordered{3, 2, 1} | |
fmt.Println(slice.Equal(x, y)) | |
fmt.Println(slice.Match(x, y)) | |
} | |
-- go.mod -- | |
module hova.dzia.poliev.ka | |
-- slice/slice.go -- | |
package slice | |
import ( | |
"github.com/google/go-cmp/cmp" | |
"github.com/stretchr/testify/assert" | |
) | |
type Unordered []interface{} | |
func Equal(x, y interface{}) bool { | |
return cmp.Equal(x, y) | |
} | |
func Match(x, y interface{}) bool { | |
return cmp.Equal(x, y, cmp.Comparer(func(x, y Unordered) bool { | |
return assert.ElementsMatch(nil, x, y) | |
})) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment