You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hal/hal/mock_io.go

32 lines
633 B

package hal
import "fmt"
func NewMockIO(inputs ...float64) *MockIO {
return &MockIO{
Inputs: inputs,
}
}
type MockIO struct {
currentInputIndex int
Inputs []float64
Outputs []float64
}
func (io *MockIO) increaseInputIndex() {
io.currentInputIndex++
}
func (io *MockIO) Read() (float64, error) {
if len(io.Inputs) <= io.currentInputIndex {
return 0, fmt.Errorf("no mock data for index %d", io.currentInputIndex)
}
defer io.increaseInputIndex()
return io.Inputs[io.currentInputIndex], nil
}
func (io *MockIO) Write(output float64) error {
io.Outputs = append(io.Outputs, output)
return nil
}