From 175cfc4925079fb6812cf174ea29689e2518c026 Mon Sep 17 00:00:00 2001 From: Russell Stanley Date: Mon, 11 Apr 2022 13:15:07 +0930 Subject: [PATCH] revid/config: add transform matrix test case --- cmd/rv/probe_circleci.go | 2 +- revid/config/config_test.go | 2 ++ revid/config/variables.go | 16 +++++++++++----- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cmd/rv/probe_circleci.go b/cmd/rv/probe_circleci.go index 3c82038e..060424d1 100644 --- a/cmd/rv/probe_circleci.go +++ b/cmd/rv/probe_circleci.go @@ -40,7 +40,7 @@ type turbidityProbe struct { } // NewTurbidityProbe returns an empty turbidity probe for CircleCI testing only. -func NewTurbidityProbe(log logger.Logger, delay time.Duration) (*turbidityProbe, error) { +func NewTurbidityProbe(log logger.Logger, delay time.Duration, transformMatrix []float64) (*turbidityProbe, error) { tp := new(turbidityProbe) return tp, nil } diff --git a/revid/config/config_test.go b/revid/config/config_test.go index 4983d2bd..d2a25a2f 100644 --- a/revid/config/config_test.go +++ b/revid/config/config_test.go @@ -122,6 +122,7 @@ func TestUpdate(t *testing.T) { "VBRQuality": "excellent", "VerticalFlip": "true", "Width": "300", + "TransformMatrix": "0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8,0.9", } dl := &dumbLogger{} @@ -172,6 +173,7 @@ func TestUpdate(t *testing.T) { VBRQuality: QualityExcellent, VerticalFlip: true, Width: 300, + TransformMatrix: []float64{0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9}, } got := Config{Logger: dl} diff --git a/revid/config/variables.go b/revid/config/variables.go index 8098eb68..fc52dd5a 100644 --- a/revid/config/variables.go +++ b/revid/config/variables.go @@ -149,13 +149,19 @@ var Variables = []struct { Name: KeyTransformMatrix, Type: typeString, Update: func(c *Config, v string) { - v = strings.Replace(v, " ", "", 0) + c.Logger.Log(logger.Debug, "updating transform matrix", "string", v) + v = strings.Replace(v, " ", "", -1) + vals := make([]float64, 0) + if v == "" { + c.TransformMatrix = vals + return + } + elements := strings.Split(v, ",") - vals := make([]float64, len(elements)) - for _, i := range elements { - vFloat, err := strconv.ParseFloat(i, 64) + for _, e := range elements { + vFloat, err := strconv.ParseFloat(e, 64) if err != nil { - c.Logger.Log(logger.Warning, "invalid TransformMatrix param", "value", i) + c.Logger.Log(logger.Warning, "invalid TransformMatrix param", "value", e) } vals = append(vals, vFloat) }