Skip to content

Commit

Permalink
more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
jlapacik committed Nov 19, 2018
1 parent c31874a commit 76138d4
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 225 deletions.
47 changes: 47 additions & 0 deletions execute/executetest/result.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package executetest

import (
"fmt"

"github.com/google/go-cmp/cmp"
"github.com/influxdata/flux"
)

Expand Down Expand Up @@ -45,3 +48,47 @@ func (ti *TableIterator) Do(f func(flux.Table) error) error {
}
return nil
}

// EqualResults compares two lists of Flux Results for equlity
func EqualResults(want, got []flux.Result) (bool, error) {
if len(want) != len(got) {
return false, fmt.Errorf("unexpected number of results - want %d results, got %d results", len(want), len(got))
}
for i, result := range want {
w := result
g := got[i]
if w.Name() != g.Name() {
return false, fmt.Errorf("unexpected result name - want %s, got %s", w.Name(), g.Name())
}
var wt, gt []*Table
if err := w.Tables().Do(func(tbl flux.Table) error {
t, err := ConvertTable(tbl)
if err != nil {
return err
}
wt = append(wt, t)
return nil
}); err != nil {
return false, err
}
if err := g.Tables().Do(func(tbl flux.Table) error {
t, err := ConvertTable(tbl)
if err != nil {
return err
}
gt = append(gt, t)
return nil
}); err != nil {
return false, err
}
NormalizeTables(wt)
NormalizeTables(gt)
if len(wt) != len(gt) {
return false, fmt.Errorf("unexpected size for result %s - want %d tables, got %d tables", w.Name(), len(wt), len(gt))
}
if !cmp.Equal(wt, gt, floatOptions) {
return false, fmt.Errorf("unexpected tables -want/+got\n%s", cmp.Diff(wt, gt))
}
}
return true, nil
}
3 changes: 1 addition & 2 deletions execute/executetest/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@ package executetest
import (
"fmt"

"github.com/influxdata/flux/semantic"

"github.com/influxdata/flux"
"github.com/influxdata/flux/execute"
"github.com/influxdata/flux/semantic"
"github.com/influxdata/flux/values"
)

Expand Down
36 changes: 35 additions & 1 deletion execute/executetest/transformation.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,49 @@
package executetest

import (
"math"
"sort"
"testing"

"github.com/gonum/floats"

"github.com/google/go-cmp/cmp"
"github.com/google/go-cmp/cmp/cmpopts"

"github.com/influxdata/flux"
"github.com/influxdata/flux/execute"
)

// Two floating point values are considered
// equal if they are within tol of each other.
const tol float64 = 1e-25

// The maximum number of floating point values that are allowed
// to lie between two float64s and still be considered equal.
const ulp uint = 2

// Comparison options for floating point values.
// NaNs are considered equal, and float64s must
// be sufficiently close to be considered equal.
var floatOptions = cmp.Options{
cmpopts.EquateNaNs(),
cmp.FilterValues(func(x, y float64) bool {
return !math.IsNaN(x) && !math.IsNaN(y)
}, cmp.Comparer(func(x, y float64) bool {
// If sufficiently close, then move on.
// This avoids situations close to zero.
if floats.EqualWithinAbs(x, y, tol) {
return true
}
// If not sufficiently close, both floats
// must be within ulp steps of each other.
if !floats.EqualWithinULP(x, y, ulp) {
return false
}
return true
})),
}

func ProcessTestHelper(
t *testing.T,
data []flux.Table,
Expand Down Expand Up @@ -50,7 +84,7 @@ func ProcessTestHelper(
sort.Sort(SortedTables(got))
sort.Sort(SortedTables(want))

if !cmp.Equal(want, got, cmpopts.EquateNaNs()) {
if !cmp.Equal(want, got, floatOptions) {
t.Errorf("unexpected tables -want/+got\n%s", cmp.Diff(want, got))
}
}
222 changes: 0 additions & 222 deletions querytest/compare.go

This file was deleted.

0 comments on commit 76138d4

Please sign in to comment.