Documentation
¶
Overview ¶
Package compare has a function for comparing unsorted slices
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SliceUnsorted ¶
SliceUnsorted will check whether two slices are equal when their sort order should not matter. Useful for testing, comparing results. Will return error if input is not slice
Example ¶
With SliceUnsorted there is no need to construct a sort function for the data type in question
package main
import (
"fmt"
"reflect"
"github.com/markysand/compare"
)
func main() {
sliceA := []struct {
name string
surname string
}{
{"Donald", "Duck"},
{"Mickey", "Mouse"},
}
sliceB := []struct {
name string
surname string
}{
{"Mickey", "Mouse"},
{"Donald", "Duck"},
}
result1, _ := compare.SliceUnsorted(sliceA, sliceB)
result2 := reflect.DeepEqual(sliceA, sliceB)
fmt.Println(result1)
fmt.Println(result2)
}
Output: true false
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.