github.com/influxdata/influxdb/v2@v2.7.6/influxql/query/internal/gota/trix_test.go (about)

     1  package gota
     2  
     3  import "testing"
     4  
     5  func TestTRIX(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 is generated by the following code:
     9  	// expList, _ := talib.Trix(list, 4, nil)
    10  	expList := []float64{18.181818181818187, 15.384615384615374, 13.33333333333333, 11.764705882352944, 10.526315789473696, 8.304761904761904, 5.641927541329594, 3.0392222148232007, 0.7160675740302658, -1.2848911076603242, -2.9999661985600667, -4.493448741755901, -5.836238000516913, -7.099092024379772, -8.352897627933453, -9.673028502435233, -11.147601363985949, -12.891818138458877, -15.074463280730022}
    11  
    12  	trix := NewTRIX(4, WarmSMA)
    13  	var actList []float64
    14  	for _, v := range list {
    15  		if vOut := trix.Add(v); trix.Warmed() {
    16  			actList = append(actList, vOut)
    17  		}
    18  	}
    19  
    20  	if diff := diffFloats(expList, actList, 1e-7); diff != "" {
    21  		t.Errorf("unexpected floats:\n%s", diff)
    22  	}
    23  }