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 }