default constructor
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
package input
|
||||
|
||||
type Input interface {
|
||||
Read() []byte
|
||||
Read() []Button
|
||||
}
|
||||
|
||||
func New() Input {
|
||||
return NewRandom('a', 'g')
|
||||
}
|
||||
|
||||
7
src/device/input/input_test.go
Normal file
7
src/device/input/input_test.go
Normal file
@@ -0,0 +1,7 @@
|
||||
package input
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestInput(t *testing.T) {
|
||||
var _ Input = &Random{}
|
||||
}
|
||||
@@ -18,7 +18,7 @@ type Random struct {
|
||||
|
||||
func NewRandom(start, stop byte) *Random {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
return &Random{start: start, stop: stop + 1}
|
||||
return &Random{start: start, stop: stop}
|
||||
}
|
||||
|
||||
func (r *Random) Read() []Button {
|
||||
@@ -30,7 +30,7 @@ func (r *Random) Read() []Button {
|
||||
r.down = r.down[:0]
|
||||
return was
|
||||
} else {
|
||||
c := Button{Char: r.start + byte(rand.Int()%int(r.stop-r.start)), Down: true}
|
||||
c := Button{Char: r.start + byte(rand.Int()%int(1+r.stop-r.start)), Down: true}
|
||||
r.down = append(r.down, c)
|
||||
return []Button{c}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user