Format code appropriately
This commit is contained in:
parent
cd5bcce2c2
commit
9e663d74da
|
@ -1,14 +1,14 @@
|
||||||
package trig
|
package trig
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"math"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
|
|
||||||
"github.com/influxdb/telegraf/plugins"
|
"github.com/influxdb/telegraf/plugins"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Trig struct {
|
type Trig struct {
|
||||||
x float64
|
x float64
|
||||||
Amplitude float64
|
Amplitude float64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,8 +26,8 @@ func (s *Trig) Description() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Trig) Gather(acc plugins.Accumulator) error {
|
func (s *Trig) Gather(acc plugins.Accumulator) error {
|
||||||
sinner := math.Sin((s.x * math.Pi) / 5.0) * s.Amplitude
|
sinner := math.Sin((s.x*math.Pi)/5.0) * s.Amplitude
|
||||||
cosinner := math.Cos((s.x * math.Pi) / 5.0) * s.Amplitude
|
cosinner := math.Cos((s.x*math.Pi)/5.0) * s.Amplitude
|
||||||
|
|
||||||
fields := make(map[string]interface{})
|
fields := make(map[string]interface{})
|
||||||
fields["sine"] = sinner
|
fields["sine"] = sinner
|
||||||
|
@ -36,15 +36,14 @@ func (s *Trig) Gather(acc plugins.Accumulator) error {
|
||||||
tags := make(map[string]string)
|
tags := make(map[string]string)
|
||||||
|
|
||||||
s.x += 1.0
|
s.x += 1.0
|
||||||
acc.AddFields("trig",fields,tags)
|
acc.AddFields("trig", fields, tags)
|
||||||
|
|
||||||
fmt.Printf("%#v\n",fields)
|
fmt.Printf("%#v\n", fields)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
|
||||||
plugins.Add("Trig", func() plugins.Plugin { return &Trig{x: 0.0} })
|
plugins.Add("Trig", func() plugins.Plugin { return &Trig{x: 0.0} })
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package trig
|
package trig
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
|
||||||
"math"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"math"
|
||||||
|
"testing"
|
||||||
|
|
||||||
"github.com/influxdb/telegraf/testutil"
|
"github.com/influxdb/telegraf/testutil"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
@ -15,13 +15,12 @@ func TestTrig(t *testing.T) {
|
||||||
Amplitude: 10.0,
|
Amplitude: 10.0,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for i := 0.0; i < 10.0; i++ {
|
||||||
for i:=0.0; i < 10.0; i++ {
|
|
||||||
|
|
||||||
var acc testutil.Accumulator
|
var acc testutil.Accumulator
|
||||||
|
|
||||||
sine := math.Sin((i * math.Pi) / 5.0) * s.Amplitude
|
sine := math.Sin((i*math.Pi)/5.0) * s.Amplitude
|
||||||
cosine := math.Cos((i * math.Pi) / 5.0) * s.Amplitude
|
cosine := math.Cos((i*math.Pi)/5.0) * s.Amplitude
|
||||||
|
|
||||||
s.Gather(&acc)
|
s.Gather(&acc)
|
||||||
|
|
||||||
|
@ -29,10 +28,9 @@ func TestTrig(t *testing.T) {
|
||||||
fields["sine"] = sine
|
fields["sine"] = sine
|
||||||
fields["cosine"] = cosine
|
fields["cosine"] = cosine
|
||||||
|
|
||||||
fmt.Printf("%#v\n",fields)
|
fmt.Printf("%#v\n", fields)
|
||||||
|
|
||||||
assert.True(t, acc.CheckFieldsValue("trig", fields))
|
assert.True(t, acc.CheckFieldsValue("trig", fields))
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue