aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/google/go-cmp/cmp/cmpopts/equate.go
diff options
context:
space:
mode:
authorDmitry Vyukov <dvyukov@google.com>2020-07-04 10:38:29 +0200
committerDmitry Vyukov <dvyukov@google.com>2020-07-04 15:05:30 +0200
commitdcff124efb2ea4a834b74ac0974aa2f2fd000b40 (patch)
tree8d49a1e0849baa283d09c7227ec9d2311a34258a /vendor/github.com/google/go-cmp/cmp/cmpopts/equate.go
parent4f739670f77d37168a44be2139f4005b748a825d (diff)
go.mod: switch to modules for dependency management
Godep is long deprecated and modules is the future. Updating dependencies with godep is painful and non-transparent. This will hopefully help to create custom golangci-lint linters. The change was created with: go mod init rm -rf vendor go mod vendor Fixes #1247
Diffstat (limited to 'vendor/github.com/google/go-cmp/cmp/cmpopts/equate.go')
-rw-r--r--vendor/github.com/google/go-cmp/cmp/cmpopts/equate.go89
1 files changed, 0 insertions, 89 deletions
diff --git a/vendor/github.com/google/go-cmp/cmp/cmpopts/equate.go b/vendor/github.com/google/go-cmp/cmp/cmpopts/equate.go
deleted file mode 100644
index 41bbddc61..000000000
--- a/vendor/github.com/google/go-cmp/cmp/cmpopts/equate.go
+++ /dev/null
@@ -1,89 +0,0 @@
-// Copyright 2017, The Go Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style
-// license that can be found in the LICENSE.md file.
-
-// Package cmpopts provides common options for the cmp package.
-package cmpopts
-
-import (
- "math"
- "reflect"
-
- "github.com/google/go-cmp/cmp"
-)
-
-func equateAlways(_, _ interface{}) bool { return true }
-
-// EquateEmpty returns a Comparer option that determines all maps and slices
-// with a length of zero to be equal, regardless of whether they are nil.
-//
-// EquateEmpty can be used in conjunction with SortSlices and SortMaps.
-func EquateEmpty() cmp.Option {
- return cmp.FilterValues(isEmpty, cmp.Comparer(equateAlways))
-}
-
-func isEmpty(x, y interface{}) bool {
- vx, vy := reflect.ValueOf(x), reflect.ValueOf(y)
- return (x != nil && y != nil && vx.Type() == vy.Type()) &&
- (vx.Kind() == reflect.Slice || vx.Kind() == reflect.Map) &&
- (vx.Len() == 0 && vy.Len() == 0)
-}
-
-// EquateApprox returns a Comparer option that determines float32 or float64
-// values to be equal if they are within a relative fraction or absolute margin.
-// This option is not used when either x or y is NaN or infinite.
-//
-// The fraction determines that the difference of two values must be within the
-// smaller fraction of the two values, while the margin determines that the two
-// values must be within some absolute margin.
-// To express only a fraction or only a margin, use 0 for the other parameter.
-// The fraction and margin must be non-negative.
-//
-// The mathematical expression used is equivalent to:
-// |x-y| ≤ max(fraction*min(|x|, |y|), margin)
-//
-// EquateApprox can be used in conjunction with EquateNaNs.
-func EquateApprox(fraction, margin float64) cmp.Option {
- if margin < 0 || fraction < 0 || math.IsNaN(margin) || math.IsNaN(fraction) {
- panic("margin or fraction must be a non-negative number")
- }
- a := approximator{fraction, margin}
- return cmp.Options{
- cmp.FilterValues(areRealF64s, cmp.Comparer(a.compareF64)),
- cmp.FilterValues(areRealF32s, cmp.Comparer(a.compareF32)),
- }
-}
-
-type approximator struct{ frac, marg float64 }
-
-func areRealF64s(x, y float64) bool {
- return !math.IsNaN(x) && !math.IsNaN(y) && !math.IsInf(x, 0) && !math.IsInf(y, 0)
-}
-func areRealF32s(x, y float32) bool {
- return areRealF64s(float64(x), float64(y))
-}
-func (a approximator) compareF64(x, y float64) bool {
- relMarg := a.frac * math.Min(math.Abs(x), math.Abs(y))
- return math.Abs(x-y) <= math.Max(a.marg, relMarg)
-}
-func (a approximator) compareF32(x, y float32) bool {
- return a.compareF64(float64(x), float64(y))
-}
-
-// EquateNaNs returns a Comparer option that determines float32 and float64
-// NaN values to be equal.
-//
-// EquateNaNs can be used in conjunction with EquateApprox.
-func EquateNaNs() cmp.Option {
- return cmp.Options{
- cmp.FilterValues(areNaNsF64s, cmp.Comparer(equateAlways)),
- cmp.FilterValues(areNaNsF32s, cmp.Comparer(equateAlways)),
- }
-}
-
-func areNaNsF64s(x, y float64) bool {
- return math.IsNaN(x) && math.IsNaN(y)
-}
-func areNaNsF32s(x, y float32) bool {
- return areNaNsF64s(float64(x), float64(y))
-}