Skip to content

Commit

Permalink
Rename Expect to Assert and add Refute function
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Jul 17, 2014
1 parent 419193d commit 84363c6
Show file tree
Hide file tree
Showing 34 changed files with 165 additions and 161 deletions.
15 changes: 5 additions & 10 deletions adaptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ type Adaptor struct {
name string
port string
connected bool
params map[string]interface{}
adaptorType string
}

Expand All @@ -19,7 +18,7 @@ type AdaptorInterface interface {
Connected() bool
SetConnected(bool)
SetName(string)
Params() map[string]interface{}
SetPort(string)
ToJSON() *JSONConnection
}

Expand All @@ -32,17 +31,13 @@ func NewAdaptor(name string, adaptorType string, v ...interface{}) *Adaptor {
adaptorType: adaptorType,
name: name,
port: "",
params: make(map[string]interface{}),
}

for i := range v {
switch v[i].(type) {
case string:
a.port = v[i].(string)
case map[string]interface{}:
a.params = v[i].(map[string]interface{})
default:
fmt.Println("Unknown argument passed to NewAdaptor")
}
}

Expand All @@ -53,6 +48,10 @@ func (a *Adaptor) Port() string {
return a.port
}

func (a *Adaptor) SetPort(s string) {
a.port = s
}

func (a *Adaptor) Name() string {
return a.name
}
Expand All @@ -73,10 +72,6 @@ func (a *Adaptor) SetConnected(b bool) {
a.connected = b
}

func (a *Adaptor) Params() map[string]interface{} {
return a.params
}

func (a *Adaptor) ToJSON() *JSONConnection {
return &JSONConnection{
Name: a.Name(),
Expand Down
20 changes: 10 additions & 10 deletions api/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestRobots(t *testing.T) {
body, _ := ioutil.ReadAll(response.Body)
var i []map[string]interface{}
json.Unmarshal(body, &i)
gobot.Expect(t, len(i), 3)
gobot.Assert(t, len(i), 3)
}

func TestRobot(t *testing.T) {
Expand All @@ -47,7 +47,7 @@ func TestRobot(t *testing.T) {
body, _ := ioutil.ReadAll(response.Body)
var i map[string]interface{}
json.Unmarshal(body, &i)
gobot.Expect(t, i["name"].(string), "Robot 1")
gobot.Assert(t, i["name"].(string), "Robot 1")
}

func TestRobotDevices(t *testing.T) {
Expand All @@ -59,7 +59,7 @@ func TestRobotDevices(t *testing.T) {
body, _ := ioutil.ReadAll(response.Body)
var i []map[string]interface{}
json.Unmarshal(body, &i)
gobot.Expect(t, len(i), 3)
gobot.Assert(t, len(i), 3)
}

func TestRobotCommands(t *testing.T) {
Expand All @@ -71,7 +71,7 @@ func TestRobotCommands(t *testing.T) {
body, _ := ioutil.ReadAll(response.Body)
var i []string
json.Unmarshal(body, &i)
gobot.Expect(t, i, []string{"robotTestFunction"})
gobot.Assert(t, i, []string{"robotTestFunction"})
}

func TestExecuteRobotCommand(t *testing.T) {
Expand All @@ -84,7 +84,7 @@ func TestExecuteRobotCommand(t *testing.T) {
body, _ := ioutil.ReadAll(response.Body)
var i interface{}
json.Unmarshal(body, &i)
gobot.Expect(t, i, "hey Robot 1, Beep Boop")
gobot.Assert(t, i, "hey Robot 1, Beep Boop")
}

func TestUnknownRobotCommand(t *testing.T) {
Expand All @@ -97,7 +97,7 @@ func TestUnknownRobotCommand(t *testing.T) {
body, _ := ioutil.ReadAll(response.Body)
var i interface{}
json.Unmarshal(body, &i)
gobot.Expect(t, i, "Unknown Command")
gobot.Assert(t, i, "Unknown Command")
}

func TestRobotDevice(t *testing.T) {
Expand All @@ -109,7 +109,7 @@ func TestRobotDevice(t *testing.T) {
body, _ := ioutil.ReadAll(response.Body)
var i map[string]interface{}
json.Unmarshal(body, &i)
gobot.Expect(t, i["name"].(string), "Device 1")
gobot.Assert(t, i["name"].(string), "Device 1")
}

func TestRobotDeviceCommands(t *testing.T) {
Expand All @@ -121,7 +121,7 @@ func TestRobotDeviceCommands(t *testing.T) {
body, _ := ioutil.ReadAll(response.Body)
var i []string
json.Unmarshal(body, &i)
gobot.Expect(t, i, []string{"TestDriverCommand", "DriverCommand"})
gobot.Assert(t, i, []string{"TestDriverCommand", "DriverCommand"})
}

func TestExecuteRobotDeviceCommand(t *testing.T) {
Expand All @@ -134,7 +134,7 @@ func TestExecuteRobotDeviceCommand(t *testing.T) {
body, _ := ioutil.ReadAll(response.Body)
var i interface{}
json.Unmarshal(body, &i)
gobot.Expect(t, i, "hello human")
gobot.Assert(t, i, "hello human")
}

func TestUnknownRobotDeviceCommand(t *testing.T) {
Expand All @@ -147,5 +147,5 @@ func TestUnknownRobotDeviceCommand(t *testing.T) {
body, _ := ioutil.ReadAll(response.Body)
var i interface{}
json.Unmarshal(body, &i)
gobot.Expect(t, i, "Unknown Command")
gobot.Assert(t, i, "Unknown Command")
}
8 changes: 4 additions & 4 deletions gobot/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,12 +188,12 @@ func initTest{{ .UpperName }}Driver() *{{ .UpperName }}Driver {
func Test{{ .UpperName }}DriverStart(t *testing.T) {
d := initTest{{.UpperName }}Driver()
gobot.Expect(t, d.Start(), true)
gobot.Assert(t, d.Start(), true)
}
func Test{{ .UpperName }}DriverHalt(t *testing.T) {
d := initTest{{.UpperName }}Driver()
gobot.Expect(t, d.Halt(), true)
gobot.Assert(t, d.Halt(), true)
}
`
}
Expand All @@ -212,12 +212,12 @@ func initTest{{ .UpperName }}Adaptor() *{{ .UpperName }}Adaptor {
func Test{{ .UpperName }}AdaptorConnect(t *testing.T) {
a := initTest{{.UpperName }}Adaptor()
gobot.Expect(t, a.Connect(), true)
gobot.Assert(t, a.Connect(), true)
}
func Test{{ .UpperName }}AdaptorFinalize(t *testing.T) {
a := initTest{{.UpperName }}Adaptor()
gobot.Expect(t, a.Finalize(), true)
gobot.Assert(t, a.Finalize(), true)
}
`
}
Expand Down
18 changes: 9 additions & 9 deletions gobot_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ func TestGobotStart(t *testing.T) {

func TestGobotRobot(t *testing.T) {
g := initTestGobot()
Expect(t, g.Robot("Robot 1").Name, "Robot 1")
Expect(t, g.Robot("Robot 4"), (*Robot)(nil))
Expect(t, g.Robot("Robot 1").Device("Device 4"), (Device)(nil))
Expect(t, g.Robot("Robot 1").Device("Device 1").Name(), "Device 1")
Expect(t, g.Robot("Robot 1").Devices().Len(), 3)
Expect(t, g.Robot("Robot 1").Connection("Connection 4"), (Connection)(nil))
Expect(t, g.Robot("Robot 1").Connections().Len(), 3)
Assert(t, g.Robot("Robot 1").Name, "Robot 1")
Assert(t, g.Robot("Robot 4"), (*Robot)(nil))
Assert(t, g.Robot("Robot 1").Device("Device 4"), (Device)(nil))
Assert(t, g.Robot("Robot 1").Device("Device 1").Name(), "Device 1")
Assert(t, g.Robot("Robot 1").Devices().Len(), 3)
Assert(t, g.Robot("Robot 1").Connection("Connection 4"), (Connection)(nil))
Assert(t, g.Robot("Robot 1").Connections().Len(), 3)
}

func TestGobotToJSON(t *testing.T) {
Expand All @@ -40,6 +40,6 @@ func TestGobotToJSON(t *testing.T) {
return nil
})
json := g.ToJSON()
Expect(t, len(json.Robots), g.Robots().Len())
Expect(t, len(json.Commands), len(g.Commands()))
Assert(t, len(json.Robots), g.Robots().Len())
Assert(t, len(json.Commands), len(g.Commands()))
}
4 changes: 2 additions & 2 deletions platforms/ardrone/ardrone_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ func initTestArdroneAdaptor() *ArdroneAdaptor {

func TestConnect(t *testing.T) {
a := initTestArdroneAdaptor()
gobot.Expect(t, a.Connect(), true)
gobot.Assert(t, a.Connect(), true)
}

func TestFinalize(t *testing.T) {
a := initTestArdroneAdaptor()
gobot.Expect(t, a.Finalize(), true)
gobot.Assert(t, a.Finalize(), true)
}
4 changes: 2 additions & 2 deletions platforms/ardrone/ardrone_driver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ func initTestArdroneDriver() *ArdroneDriver {

func TestArdroneDriverStart(t *testing.T) {
d := initTestArdroneDriver()
gobot.Expect(t, d.Start(), true)
gobot.Assert(t, d.Start(), true)
}

func TestArdroneDriverHalt(t *testing.T) {
d := initTestArdroneDriver()
gobot.Expect(t, d.Halt(), true)
gobot.Assert(t, d.Halt(), true)
}
func TestArdroneDriverTakeOff(t *testing.T) {
d := initTestArdroneDriver()
Expand Down
8 changes: 4 additions & 4 deletions platforms/beaglebone/beaglebone_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ func initTestBeagleboneAdaptor() *BeagleboneAdaptor {

func TestBeagleboneAdaptorFinalize(t *testing.T) {
a := initTestBeagleboneAdaptor()
gobot.Expect(t, a.Finalize(), true)
gobot.Assert(t, a.Finalize(), true)
}
func TestBeagleboneAdaptorConnect(t *testing.T) {
a := initTestBeagleboneAdaptor()
gobot.Expect(t, a.Connect(), true)
gobot.Assert(t, a.Connect(), true)
}
func TestBeagleboneAdaptorDisconnect(t *testing.T) {
a := initTestBeagleboneAdaptor()
gobot.Expect(t, a.Disconnect(), true)
gobot.Assert(t, a.Disconnect(), true)
}
func TestBeagleboneAdaptorReconnect(t *testing.T) {
a := initTestBeagleboneAdaptor()
gobot.Expect(t, a.Reconnect(), true)
gobot.Assert(t, a.Reconnect(), true)
}
8 changes: 4 additions & 4 deletions platforms/digispark/digispark_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ func initTestDigisparkAdaptor() *DigisparkAdaptor {

func TestDigisparkAdaptorFinalize(t *testing.T) {
a := initTestDigisparkAdaptor()
gobot.Expect(t, a.Finalize(), true)
gobot.Assert(t, a.Finalize(), true)
}

func TestDigisparkAdaptorConnect(t *testing.T) {
a := initTestDigisparkAdaptor()
gobot.Expect(t, a.Connect(), true)
gobot.Assert(t, a.Connect(), true)
}

func TestDigisparkAdaptorDisconnect(t *testing.T) {
a := initTestDigisparkAdaptor()
gobot.Expect(t, a.Disconnect(), true)
gobot.Assert(t, a.Disconnect(), true)
}

func TestDigisparkAdaptorReconnect(t *testing.T) {
a := initTestDigisparkAdaptor()
gobot.Expect(t, a.Reconnect(), true)
gobot.Assert(t, a.Reconnect(), true)
}
16 changes: 8 additions & 8 deletions platforms/firmata/firmata_adaptor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ func initTestFirmataAdaptor() *FirmataAdaptor {

func TestFirmataAdaptorFinalize(t *testing.T) {
a := initTestFirmataAdaptor()
gobot.Expect(t, a.Finalize(), true)
gobot.Assert(t, a.Finalize(), true)
}
func TestFirmataAdaptorConnect(t *testing.T) {
a := initTestFirmataAdaptor()
gobot.Expect(t, a.Connect(), true)
gobot.Assert(t, a.Connect(), true)
}

func TestFirmataAdaptorInitServo(t *testing.T) {
Expand All @@ -67,21 +67,21 @@ func TestFirmataAdaptorDigitalRead(t *testing.T) {
a := initTestFirmataAdaptor()
pinNumber := "1"
// -1 on no data
gobot.Expect(t, a.DigitalRead(pinNumber), -1)
gobot.Assert(t, a.DigitalRead(pinNumber), -1)

go func() {
<-time.After(5 * time.Millisecond)
gobot.Publish(a.board.events[fmt.Sprintf("digital_read_%v", pinNumber)],
[]byte{0x01})
}()
gobot.Expect(t, a.DigitalRead(pinNumber), 0x01)
gobot.Assert(t, a.DigitalRead(pinNumber), 0x01)
}

func TestFirmataAdaptorAnalogRead(t *testing.T) {
a := initTestFirmataAdaptor()
pinNumber := "1"
// -1 on no data
gobot.Expect(t, a.AnalogRead(pinNumber), -1)
gobot.Assert(t, a.AnalogRead(pinNumber), -1)

value := 133
go func() {
Expand All @@ -95,7 +95,7 @@ func TestFirmataAdaptorAnalogRead(t *testing.T) {
},
)
}()
gobot.Expect(t, a.AnalogRead(pinNumber), 133)
gobot.Assert(t, a.AnalogRead(pinNumber), 133)
}
func TestFirmataAdaptorAnalogWrite(t *testing.T) {
a := initTestFirmataAdaptor()
Expand All @@ -108,7 +108,7 @@ func TestFirmataAdaptorI2cStart(t *testing.T) {
func TestFirmataAdaptorI2cRead(t *testing.T) {
a := initTestFirmataAdaptor()
// [] on no data
gobot.Expect(t, a.I2cRead(1), []byte{})
gobot.Assert(t, a.I2cRead(1), []byte{})

i := []byte{100}
i2cReply := map[string][]byte{}
Expand All @@ -117,7 +117,7 @@ func TestFirmataAdaptorI2cRead(t *testing.T) {
<-time.After(5 * time.Millisecond)
gobot.Publish(a.board.events["i2c_reply"], i2cReply)
}()
gobot.Expect(t, a.I2cRead(1), i)
gobot.Assert(t, a.I2cRead(1), i)
}
func TestFirmataAdaptorI2cWrite(t *testing.T) {
a := initTestFirmataAdaptor()
Expand Down
Loading

0 comments on commit 84363c6

Please sign in to comment.