github.com/influxdata/influxdb/v2@v2.7.6/influxql/query/internal/gota/cmo_test.go (about) 1 package gota 2 3 import "testing" 4 5 func TestCMO(t *testing.T) { 6 list := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1} 7 8 expList := []float64{100, 100, 100, 100, 100, 80, 60, 40, 20, 0, -20, -40, -60, -80, -100, -100, -100, -100, -100} 9 10 cmo := NewCMO(10) 11 var actList []float64 12 for _, v := range list { 13 if vOut := cmo.Add(v); cmo.Warmed() { 14 actList = append(actList, vOut) 15 } 16 } 17 18 if diff := diffFloats(expList, actList, 1e-7); diff != "" { 19 t.Errorf("unexpected floats:\n%s", diff) 20 } 21 } 22 23 func TestCMOS(t *testing.T) { 24 list := []float64{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1} 25 26 // expList is generated by the following code: 27 // expList, _ := talib.Cmo(list, 10, nil) 28 expList := []float64{100, 100, 100, 100, 100, 80, 61.999999999999986, 45.79999999999999, 31.22, 18.097999999999992, 6.288199999999988, -4.340620000000012, -13.906558000000008, -22.515902200000014, -30.264311980000013, -37.23788078200001, -43.51409270380002, -49.16268343342002, -54.24641509007802} 29 30 cmo := NewCMOS(10, WarmSMA) 31 var actList []float64 32 for _, v := range list { 33 if vOut := cmo.Add(v); cmo.Warmed() { 34 actList = append(actList, vOut) 35 } 36 } 37 38 if diff := diffFloats(expList, actList, 1e-7); diff != "" { 39 t.Errorf("unexpected floats:\n%s", diff) 40 } 41 }