当前位置: 首页>>代码示例>>Golang>>正文


Golang gobottest.Assert函数代码示例

本文整理汇总了Golang中gobot/io/x/gobot/gobottest.Assert函数的典型用法代码示例。如果您正苦于以下问题:Golang Assert函数的具体用法?Golang Assert怎么用?Golang Assert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Assert函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestAdaptorConnect

func TestAdaptorConnect(t *testing.T) {
	a := NewAdaptor()
	gobottest.Assert(t, a.Connect(), ErrConnection)

	a = initTestAdaptor()
	gobottest.Assert(t, a.Connect(), nil)
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:7,代码来源:digispark_adaptor_test.go

示例2: TestMCP23017DriverGetPort

func TestMCP23017DriverGetPort(t *testing.T) {
	// port A
	mcp := initTestMCP23017Driver(0)
	expectedPort := getBank(0).PortA
	actualPort := mcp.getPort("A")
	gobottest.Assert(t, expectedPort, actualPort)

	// port B
	mcp = initTestMCP23017Driver(0)
	expectedPort = getBank(0).PortB
	actualPort = mcp.getPort("B")
	gobottest.Assert(t, expectedPort, actualPort)

	// default
	mcp = initTestMCP23017Driver(0)
	expectedPort = getBank(0).PortA
	actualPort = mcp.getPort("")
	gobottest.Assert(t, expectedPort, actualPort)

	// port A bank 1
	mcp = initTestMCP23017Driver(1)
	expectedPort = getBank(1).PortA
	actualPort = mcp.getPort("")
	gobottest.Assert(t, expectedPort, actualPort)
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:25,代码来源:mcp23017_driver_test.go

示例3: TestBMP180DriverMeasurements

func TestBMP180DriverMeasurements(t *testing.T) {
	bmp180, adaptor := initTestBMP180DriverWithStubbedAdaptor()
	adaptor.i2cReadImpl = func() ([]byte, error) {
		buf := new(bytes.Buffer)
		// Values from the datasheet example.
		if adaptor.written[len(adaptor.written)-1] == bmp180RegisterAC1MSB {
			binary.Write(buf, binary.BigEndian, int16(408))
			binary.Write(buf, binary.BigEndian, int16(-72))
			binary.Write(buf, binary.BigEndian, int16(-14383))
			binary.Write(buf, binary.BigEndian, uint16(32741))
			binary.Write(buf, binary.BigEndian, uint16(32757))
			binary.Write(buf, binary.BigEndian, uint16(23153))
			binary.Write(buf, binary.BigEndian, int16(6190))
			binary.Write(buf, binary.BigEndian, int16(4))
			binary.Write(buf, binary.BigEndian, int16(-32768))
			binary.Write(buf, binary.BigEndian, int16(-8711))
			binary.Write(buf, binary.BigEndian, int16(2868))
		} else if adaptor.written[len(adaptor.written)-2] == bmp180CmdTemp && adaptor.written[len(adaptor.written)-1] == bmp180RegisterTempMSB {
			binary.Write(buf, binary.BigEndian, int16(27898))
		} else if adaptor.written[len(adaptor.written)-2] == bmp180CmdPressure && adaptor.written[len(adaptor.written)-1] == bmp180RegisterPressureMSB {
			binary.Write(buf, binary.BigEndian, int16(23843))
			// XLSB, not used in this test.
			buf.WriteByte(0)
		}
		return buf.Bytes(), nil
	}
	bmp180.Start()
	temp, err := bmp180.Temperature()
	gobottest.Assert(t, err, nil)
	gobottest.Assert(t, temp, float32(15.0))
	pressure, err := bmp180.Pressure(BMP180UltraLowPower)
	gobottest.Assert(t, err, nil)
	gobottest.Assert(t, pressure, float32(69964))
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:34,代码来源:bmp180_driver_test.go

示例4: TestExecuteMcpCommand

func TestExecuteMcpCommand(t *testing.T) {
	var body interface{}
	a := initTestAPI()

	// known command
	request, _ := http.NewRequest("GET",
		"/api/commands/TestFunction",
		bytes.NewBufferString(`{"message":"Beep Boop"}`),
	)
	request.Header.Add("Content-Type", "application/json")
	response := httptest.NewRecorder()
	a.ServeHTTP(response, request)

	json.NewDecoder(response.Body).Decode(&body)
	gobottest.Assert(t, body.(map[string]interface{})["result"], "hey Beep Boop")

	// unknown command
	request, _ = http.NewRequest("GET",
		"/api/commands/TestFuntion1",
		bytes.NewBufferString(`{"message":"Beep Boop"}`),
	)
	request.Header.Add("Content-Type", "application/json")
	response = httptest.NewRecorder()
	a.ServeHTTP(response, request)

	json.NewDecoder(response.Body).Decode(&body)
	gobottest.Assert(t, body.(map[string]interface{})["error"], "Unknown Command")
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:28,代码来源:api_test.go

示例5: TestAdaptorConnect

func TestAdaptorConnect(t *testing.T) {
	a := initTestAdaptor()
	gobottest.Assert(t, a.Connect(), nil)

	a = NewAdaptor()
	gobottest.Assert(t, a.Connect(), errors.New("No joystick available"))
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:7,代码来源:joystick_adaptor_test.go

示例6: TestServoConfig

func TestServoConfig(t *testing.T) {
	b := New()
	b.connection = readWriteCloser{}

	tests := []struct {
		description string
		arguments   [3]int
		expected    []byte
		result      error
	}{
		{
			description: "Min values for min & max",
			arguments:   [3]int{9, 0, 0},
			expected:    []byte{0xF0, 0x70, 9, 0, 0, 0, 0, 0xF7},
		},
		{
			description: "Max values for min & max",
			arguments:   [3]int{9, 0x3FFF, 0x3FFF},
			expected:    []byte{0xF0, 0x70, 9, 0x7F, 0x7F, 0x7F, 0x7F, 0xF7},
		},
		{
			description: "Clipped max values for min & max",
			arguments:   [3]int{9, 0xFFFF, 0xFFFF},
			expected:    []byte{0xF0, 0x70, 9, 0x7F, 0x7F, 0x7F, 0x7F, 0xF7},
		},
	}

	for _, test := range tests {
		testWriteData.Reset()
		err := b.ServoConfig(test.arguments[0], test.arguments[1], test.arguments[2])
		gobottest.Assert(t, testWriteData.Bytes(), test.expected)
		gobottest.Assert(t, err, test.result)
	}
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:34,代码来源:client_test.go

示例7: TestConfigureLocator

func TestConfigureLocator(t *testing.T) {
	d := initTestSpheroDriver()
	d.ConfigureLocator(DefaultLocatorConfig())
	data := <-d.packetChannel

	buf := new(bytes.Buffer)
	binary.Write(buf, binary.BigEndian, DefaultLocatorConfig())

	gobottest.Assert(t, data.body, buf.Bytes())

	ret := d.Command("ConfigureLocator")(
		map[string]interface{}{
			"Flags":   1.0,
			"X":       100.0,
			"Y":       100.0,
			"YawTare": 0.0,
		},
	)
	gobottest.Assert(t, ret, nil)
	data = <-d.packetChannel

	lconfig := LocatorConfig{Flags: 1, X: 100, Y: 100, YawTare: 0}
	buf = new(bytes.Buffer)
	binary.Write(buf, binary.BigEndian, lconfig)

	gobottest.Assert(t, data.body, buf.Bytes())
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:27,代码来源:sphero_driver_test.go

示例8: TestArdroneAdaptor

func TestArdroneAdaptor(t *testing.T) {
	a := NewAdaptor()
	gobottest.Assert(t, a.config.Ip, "192.168.1.1")

	a = NewAdaptor("192.168.100.100")
	gobottest.Assert(t, a.config.Ip, "192.168.100.100")
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:7,代码来源:ardrone_adaptor_test.go

示例9: TestSHT3xDriverName

// Test Name & SetName
func TestSHT3xDriverName(t *testing.T) {
	sht3x := initTestSHT3xDriver()

	gobottest.Assert(t, sht3x.Name(), "SHT3x")
	sht3x.SetName("Sensor")
	gobottest.Assert(t, sht3x.Name(), "Sensor")
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:8,代码来源:sht3x_driver_test.go

示例10: TestL3GD20HDriverScale

func TestL3GD20HDriverScale(t *testing.T) {
	d := initTestL3GD20HDriver()
	gobottest.Assert(t, d.Scale(), L3GD20HScale250dps)

	d.SetScale(L3GD20HScale500dps)
	gobottest.Assert(t, d.Scale(), L3GD20HScale500dps)
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:7,代码来源:l3gd20h_driver_test.go

示例11: TestServoDriver

func TestServoDriver(t *testing.T) {
	var err interface{}

	d := initTestServoDriver()

	gobottest.Assert(t, d.Pin(), "1")
	gobottest.Refute(t, d.Connection(), nil)

	testAdaptorServoWrite = func() (err error) {
		return errors.New("pwm error")
	}

	err = d.Command("Min")(nil)
	gobottest.Assert(t, err.(error), errors.New("pwm error"))

	err = d.Command("Center")(nil)
	gobottest.Assert(t, err.(error), errors.New("pwm error"))

	err = d.Command("Max")(nil)
	gobottest.Assert(t, err.(error), errors.New("pwm error"))

	err = d.Command("Move")(map[string]interface{}{"angle": 100.0})
	gobottest.Assert(t, err.(error), errors.New("pwm error"))

}
开发者ID:hybridgroup,项目名称:gobot,代码行数:25,代码来源:servo_driver_test.go

示例12: TestAdaptorPinLevel

func TestAdaptorPinLevel(t *testing.T) {
	a := initTestAdaptor()

	gobottest.Assert(t, a.pinLevel(1), "HIGH")
	gobottest.Assert(t, a.pinLevel(0), "LOW")
	gobottest.Assert(t, a.pinLevel(5), "LOW")
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:7,代码来源:adaptor_test.go

示例13: TestGroveTemperatureSensorDriver

func TestGroveTemperatureSensorDriver(t *testing.T) {
	testAdaptor := newAioTestAdaptor()
	d := NewGroveTemperatureSensorDriver(testAdaptor, "123")
	gobottest.Assert(t, d.Connection(), testAdaptor)
	gobottest.Assert(t, d.Pin(), "123")
	gobottest.Assert(t, d.interval, 10*time.Millisecond)
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:7,代码来源:grove_temperature_sensor_driver_test.go

示例14: TestMavlinkAdaptorConnect

func TestMavlinkAdaptorConnect(t *testing.T) {
	a := initTestMavlinkAdaptor()
	gobottest.Assert(t, a.Connect(), nil)

	a.connect = func(port string) (io.ReadWriteCloser, error) { return nil, errors.New("connect error") }
	gobottest.Assert(t, a.Connect(), errors.New("connect error"))
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:7,代码来源:mavlink_adaptor_test.go

示例15: TestBlinkMDriverColor

func TestBlinkMDriverColor(t *testing.T) {
	blinkM, adaptor := initTestBlinkDriverWithStubbedAdaptor()

	// when len(data) is 3
	adaptor.i2cReadImpl = func() ([]byte, error) {
		return []byte{99, 1, 2}, nil
	}

	color, _ := blinkM.Color()
	gobottest.Assert(t, color, []byte{99, 1, 2})

	// when len(data) is not 3
	adaptor.i2cReadImpl = func() ([]byte, error) {
		return []byte{99}, nil
	}

	color, _ = blinkM.Color()
	gobottest.Assert(t, color, []byte{})

	adaptor.i2cWriteImpl = func() error {
		return errors.New("write error")
	}

	color, err := blinkM.Color()
	gobottest.Assert(t, err, errors.New("write error"))

}
开发者ID:hybridgroup,项目名称:gobot,代码行数:27,代码来源:blinkm_driver_test.go


注:本文中的gobot/io/x/gobot/gobottest.Assert函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。