| OLD | NEW |
| 1 package digesttools | 1 package digesttools |
| 2 | 2 |
| 3 import ( | 3 import ( |
| 4 "math" | 4 "math" |
| 5 "testing" | 5 "testing" |
| 6 | 6 |
| 7 "github.com/stretchr/testify/assert" | 7 "github.com/stretchr/testify/assert" |
| 8 "go.skia.org/infra/golden/go/diff" | 8 "go.skia.org/infra/golden/go/diff" |
| 9 "go.skia.org/infra/golden/go/expstorage" | 9 "go.skia.org/infra/golden/go/expstorage" |
| 10 "go.skia.org/infra/golden/go/tally" | 10 "go.skia.org/infra/golden/go/tally" |
| 11 "go.skia.org/infra/golden/go/types" | 11 "go.skia.org/infra/golden/go/types" |
| 12 ) | 12 ) |
| 13 | 13 |
| 14 type MockDiffStore struct{} | 14 type MockDiffStore struct{} |
| 15 | 15 |
| 16 func (m MockDiffStore) AbsPath(digest []string) map[string]string
{ return nil } | 16 func (m MockDiffStore) AbsPath(digest []string) map[string]string
{ return nil } |
| 17 func (m MockDiffStore) UnavailableDigests() map[string]*diff.DigestFailure
{ return nil } | 17 func (m MockDiffStore) UnavailableDigests() map[string]*diff.DigestFailure
{ return nil } |
| 18 func (m MockDiffStore) PurgeDigests(digests []string, purgeGS bool)
{} | 18 func (m MockDiffStore) PurgeDigests(digests []string, purgeGS bool) error
{ return nil } |
| 19 func (m MockDiffStore) SetDigestSets(namedDigestSets map[string]map[string]bool)
{} | 19 func (m MockDiffStore) SetDigestSets(namedDigestSets map[string]map[string]bool)
{} |
| 20 | 20 |
| 21 // Get always finds that digest "eee" is closest to dMain. | 21 // Get always finds that digest "eee" is closest to dMain. |
| 22 func (m MockDiffStore) Get(dMain string, dRest []string) (map[string]*diff.DiffM
etrics, error) { | 22 func (m MockDiffStore) Get(dMain string, dRest []string) (map[string]*diff.DiffM
etrics, error) { |
| 23 result := map[string]*diff.DiffMetrics{} | 23 result := map[string]*diff.DiffMetrics{} |
| 24 for i, d := range dRest { | 24 for i, d := range dRest { |
| 25 diffPercent := float32(i + 2) | 25 diffPercent := float32(i + 2) |
| 26 if d == "eee" { | 26 if d == "eee" { |
| 27 diffPercent = 0.1 | 27 diffPercent = 0.1 |
| 28 } | 28 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 assert.InDelta(t, 0.166, float64(c.Diff), 0.01) | 73 assert.InDelta(t, 0.166, float64(c.Diff), 0.01) |
| 74 assert.Equal(t, "bbb", c.Digest) | 74 assert.Equal(t, "bbb", c.Digest) |
| 75 assert.Equal(t, []int{5, 3, 4, 0}, c.MaxRGBA) | 75 assert.Equal(t, []int{5, 3, 4, 0}, c.MaxRGBA) |
| 76 } | 76 } |
| 77 | 77 |
| 78 func TestCombinedDiffMetric(t *testing.T) { | 78 func TestCombinedDiffMetric(t *testing.T) { |
| 79 assert.InDelta(t, 1.0, combinedDiffMetric(0.0, []int{}), 0.000001) | 79 assert.InDelta(t, 1.0, combinedDiffMetric(0.0, []int{}), 0.000001) |
| 80 assert.InDelta(t, 1.0, combinedDiffMetric(1.0, []int{255, 255, 255, 255}
), 0.000001) | 80 assert.InDelta(t, 1.0, combinedDiffMetric(1.0, []int{255, 255, 255, 255}
), 0.000001) |
| 81 assert.InDelta(t, math.Sqrt(0.5), combinedDiffMetric(0.5, []int{255, 255
, 255, 255}), 0.000001) | 81 assert.InDelta(t, math.Sqrt(0.5), combinedDiffMetric(0.5, []int{255, 255
, 255, 255}), 0.000001) |
| 82 } | 82 } |
| OLD | NEW |