This commit is contained in:
parent
96e07ece2d
commit
2454a44350
3 changed files with 109 additions and 0 deletions
72
succbone/succd/process_blocks_test.go
Normal file
72
succbone/succd/process_blocks_test.go
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"math"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestMomentaryOutput(t *testing.T) {
|
||||
mo := momentaryOutput{}
|
||||
mo.trigger()
|
||||
mo.process()
|
||||
if !mo.output {
|
||||
t.Fatalf("output didn't trigger")
|
||||
}
|
||||
mo.process()
|
||||
if !mo.output {
|
||||
t.Fatalf("output didn't keep triggered")
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
mo.process()
|
||||
if mo.output {
|
||||
t.Fatalf("output didn't untrigger")
|
||||
}
|
||||
}
|
||||
|
||||
func TestThresholdOutput(t *testing.T) {
|
||||
to := thresholdOutput{
|
||||
threshold: 1,
|
||||
}
|
||||
to.process(0)
|
||||
if to.output {
|
||||
t.Fatalf("output shouldn't have triggered")
|
||||
}
|
||||
to.process(2)
|
||||
if !to.output {
|
||||
t.Fatalf("output should have triggered")
|
||||
}
|
||||
to.process(0)
|
||||
if !to.output {
|
||||
t.Fatalf("output should have triggered (in debounce)")
|
||||
}
|
||||
}
|
||||
|
||||
func TestRingbufferInput(t *testing.T) {
|
||||
ri := ringbufferInput{
|
||||
limit: 3,
|
||||
}
|
||||
if ri.saturated() {
|
||||
t.Fatal("ringbuffer shouldn't be saturated yet")
|
||||
}
|
||||
ri.process(1)
|
||||
if ri.saturated() {
|
||||
t.Fatal("ringbuffer shouldn't be saturated yet")
|
||||
}
|
||||
ri.process(2)
|
||||
if ri.saturated() {
|
||||
t.Fatal("ringbuffer shouldn't be saturated yet")
|
||||
}
|
||||
ri.process(3)
|
||||
if !ri.saturated() {
|
||||
t.Fatalf("ringbuffer should be saturated")
|
||||
}
|
||||
|
||||
if diff := math.Abs(float64(ri.avg) - 2); diff > 0.01 {
|
||||
t.Fatalf("ringbuffer avg should be ~2, is %f", ri.avg)
|
||||
}
|
||||
ri.process(10)
|
||||
if diff := math.Abs(float64(ri.avg) - 5); diff > 0.01 {
|
||||
t.Fatalf("ringbuffer avg should be ~5, is %f", ri.avg)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue