test $INPUT_RANDOM_WEIGHT_FILE

master
Bel LaPointe 2023-03-02 09:49:43 -07:00
parent a732bdb6c3
commit 5edefdff5f
3 changed files with 43 additions and 17 deletions

View File

@ -1,9 +1,15 @@
package input
import "os"
type Input interface {
Read() []Button
}
func New() Input {
return NewRandom(randomCharFromRange('a', 'g'))
foo := randomCharFromRange('a', 'g')
if p, ok := os.LookupEnv("INPUT_RANDOM_WEIGHT_FILE"); ok {
foo = randomCharFromWeightFile(p)
}
return NewRandom(foo)
}

View File

@ -0,0 +1,36 @@
package input_test
import (
"mayhem-party/src/device/input"
"os"
"path"
"testing"
)
func TestNew(t *testing.T) {
r := input.New()
for i := 0; i < 15; i++ {
batch := r.Read()
for _, got := range batch {
t.Logf("[%d] %c:%v", i, got.Char, got.Down)
}
}
}
func TestNewRandomWeightFile(t *testing.T) {
d := t.TempDir()
p := path.Join(d, "f")
if err := os.WriteFile(p, []byte(`{"a":1}`), os.ModePerm); err != nil {
t.Fatal(err)
}
os.Setenv("INPUT_RANDOM_WEIGHT_FILE", p)
r := input.New()
for i := 0; i < 15; i++ {
batch := r.Read()
for _, got := range batch {
if got.Char != 'a' {
t.Error(got)
}
}
}
}

View File

@ -1,16 +0,0 @@
package input_test
import (
"mayhem-party/src/device/input"
"testing"
)
func TestNew(t *testing.T) {
r := input.New()
for i := 0; i < 15; i++ {
batch := r.Read()
for _, got := range batch {
t.Logf("[%d] %c:%v", i, got.Char, got.Down)
}
}
}