compare

package module
v0.0.0-...-a41bda0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2019 License: MIT Imports: 3 Imported by: 0

README

compare

Go Report Card GoDoc

Golang utility to compare data. Current functionality is:

  • comparing unsorted slices

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

func SliceUnsorted(a, b interface{}) (bool, error)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL