github.com/go-graphite/carbonapi@v0.17.0/zipper/types/response_test.go (about) 1 package types 2 3 import ( 4 "math" 5 "testing" 6 7 protov3 "github.com/go-graphite/protocol/carbonapi_v3_pb" 8 ) 9 10 func TestMergeFetchResponsesWithNanAppending(t *testing.T) { 11 m1 := protov3.FetchResponse{ 12 Values: []float64{math.NaN(), 0, 0, 0, math.NaN()}, 13 } 14 15 m2 := protov3.FetchResponse{ 16 Values: []float64{0}, 17 } 18 19 exp := protov3.FetchResponse{ 20 Values: []float64{0, 0, 0, 0, math.NaN()}, 21 } 22 23 err := MergeFetchResponses(&m1, &m2) 24 if err != nil { 25 t.Error(err) 26 return 27 } 28 29 if !cmpFloat64Arrays(m1.Values, exp.Values, 0.00001) { 30 t.Errorf("Error merging responses\nExp: %v\nGot: %v", exp, m1) 31 } 32 } 33 34 func cmpFloat64Arrays(a, b []float64, epsilon float64) bool { 35 if len(a) != len(b) { 36 return false 37 } 38 39 for i := range a { 40 if math.IsNaN(a[i]) && math.IsNaN(b[i]) { 41 continue 42 } else if math.IsInf(a[i], 1) && math.IsInf(b[i], 1) { 43 continue 44 } else if math.IsInf(a[i], -1) && math.IsInf(b[i], -1) { 45 continue 46 } 47 48 if math.Abs(a[i]-b[i]) >= epsilon { 49 return false 50 } 51 } 52 53 return true 54 }