test $INPUT_RANDOM_WEIGHT_FILE
parent
a732bdb6c3
commit
5edefdff5f
|
|
@ -1,9 +1,15 @@
|
||||||
package input
|
package input
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
type Input interface {
|
type Input interface {
|
||||||
Read() []Button
|
Read() []Button
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() Input {
|
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)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue