diff options
Diffstat (limited to 'vendor/github.com/google/go-cmp/cmp/internal/diff/diff.go')
-rw-r--r-- | vendor/github.com/google/go-cmp/cmp/internal/diff/diff.go | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/vendor/github.com/google/go-cmp/cmp/internal/diff/diff.go b/vendor/github.com/google/go-cmp/cmp/internal/diff/diff.go index 260befe..3d2e426 100644 --- a/vendor/github.com/google/go-cmp/cmp/internal/diff/diff.go +++ b/vendor/github.com/google/go-cmp/cmp/internal/diff/diff.go | |||
@@ -85,22 +85,31 @@ func (es EditScript) LenY() int { return len(es) - es.stats().NX } | |||
85 | type EqualFunc func(ix int, iy int) Result | 85 | type EqualFunc func(ix int, iy int) Result |
86 | 86 | ||
87 | // Result is the result of comparison. | 87 | // Result is the result of comparison. |
88 | // NSame is the number of sub-elements that are equal. | 88 | // NumSame is the number of sub-elements that are equal. |
89 | // NDiff is the number of sub-elements that are not equal. | 89 | // NumDiff is the number of sub-elements that are not equal. |
90 | type Result struct{ NSame, NDiff int } | 90 | type Result struct{ NumSame, NumDiff int } |
91 | |||
92 | // BoolResult returns a Result that is either Equal or not Equal. | ||
93 | func BoolResult(b bool) Result { | ||
94 | if b { | ||
95 | return Result{NumSame: 1} // Equal, Similar | ||
96 | } else { | ||
97 | return Result{NumDiff: 2} // Not Equal, not Similar | ||
98 | } | ||
99 | } | ||
91 | 100 | ||
92 | // Equal indicates whether the symbols are equal. Two symbols are equal | 101 | // Equal indicates whether the symbols are equal. Two symbols are equal |
93 | // if and only if NDiff == 0. If Equal, then they are also Similar. | 102 | // if and only if NumDiff == 0. If Equal, then they are also Similar. |
94 | func (r Result) Equal() bool { return r.NDiff == 0 } | 103 | func (r Result) Equal() bool { return r.NumDiff == 0 } |
95 | 104 | ||
96 | // Similar indicates whether two symbols are similar and may be represented | 105 | // Similar indicates whether two symbols are similar and may be represented |
97 | // by using the Modified type. As a special case, we consider binary comparisons | 106 | // by using the Modified type. As a special case, we consider binary comparisons |
98 | // (i.e., those that return Result{1, 0} or Result{0, 1}) to be similar. | 107 | // (i.e., those that return Result{1, 0} or Result{0, 1}) to be similar. |
99 | // | 108 | // |
100 | // The exact ratio of NSame to NDiff to determine similarity may change. | 109 | // The exact ratio of NumSame to NumDiff to determine similarity may change. |
101 | func (r Result) Similar() bool { | 110 | func (r Result) Similar() bool { |
102 | // Use NSame+1 to offset NSame so that binary comparisons are similar. | 111 | // Use NumSame+1 to offset NumSame so that binary comparisons are similar. |
103 | return r.NSame+1 >= r.NDiff | 112 | return r.NumSame+1 >= r.NumDiff |
104 | } | 113 | } |
105 | 114 | ||
106 | // Difference reports whether two lists of lengths nx and ny are equal | 115 | // Difference reports whether two lists of lengths nx and ny are equal |
@@ -191,9 +200,9 @@ func Difference(nx, ny int, f EqualFunc) (es EditScript) { | |||
191 | // that two lists commonly differ because elements were added to the front | 200 | // that two lists commonly differ because elements were added to the front |
192 | // or end of the other list. | 201 | // or end of the other list. |
193 | // | 202 | // |
194 | // Running the tests with the "debug" build tag prints a visualization of | 203 | // Running the tests with the "cmp_debug" build tag prints a visualization |
195 | // the algorithm running in real-time. This is educational for understanding | 204 | // of the algorithm running in real-time. This is educational for |
196 | // how the algorithm works. See debug_enable.go. | 205 | // understanding how the algorithm works. See debug_enable.go. |
197 | f = debug.Begin(nx, ny, f, &fwdPath.es, &revPath.es) | 206 | f = debug.Begin(nx, ny, f, &fwdPath.es, &revPath.es) |
198 | for { | 207 | for { |
199 | // Forward search from the beginning. | 208 | // Forward search from the beginning. |