Skip to content

Commit

Permalink
add go tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nicksanford committed Jul 3, 2023
1 parent ed2437e commit d2c3b0c
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions cartofacade/capi_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,21 @@ func TestCGoAPI(t *testing.T) {
err = vc.start()
test.That(t, err, test.ShouldBeNil)

// test getPointCloudMap before sensor data is added
pcd, err := vc.getPointCloudMap()
test.That(t, pcd, test.ShouldBeNil)
test.That(t, err, test.ShouldBeError)
test.That(t, err, test.ShouldResemble, errors.New("VIAM_CARTO_POINTCLOUD_MAP_EMPTY"))

lastInternalStateSize := 0

// test getInternalState before sensor data is added
internalState, err := vc.getInternalState()
test.That(t, err, test.ShouldBeNil)
test.That(t, internalState, test.ShouldNotBeNil)
test.That(t, len(internalState), test.ShouldBeGreaterThan, lastInternalStateSize)
lastInternalStateSize = len(internalState)

// test invalid addSensorReading: not in sensor list
timestamp := time.Date(2021, 8, 15, 14, 30, 45, 100, time.UTC)
err = vc.addSensorReading("not my sensor", []byte("he0llo"), timestamp)
Expand Down Expand Up @@ -188,11 +203,17 @@ func TestCGoAPI(t *testing.T) {
positionIsZero(t, position)

// test getPointCloudMap returns error if not enough sensor data has been provided
pcd, err := vc.getPointCloudMap()
pcd, err = vc.getPointCloudMap()
test.That(t, pcd, test.ShouldBeNil)
test.That(t, err, test.ShouldBeError)
test.That(t, err, test.ShouldResemble, errors.New("VIAM_CARTO_POINTCLOUD_MAP_EMPTY"))

internalState, err = vc.getInternalState()
test.That(t, err, test.ShouldBeNil)
test.That(t, internalState, test.ShouldNotBeNil)
// Special case
test.That(t, len(internalState), test.ShouldEqual, lastInternalStateSize)

// 2. test valid addSensorReading: valid reading binary
t.Log("sensor reading 2")
timestamp = timestamp.Add(time.Second * 2)
Expand All @@ -212,6 +233,12 @@ func TestCGoAPI(t *testing.T) {
test.That(t, err, test.ShouldBeNil)
test.That(t, pc.Size(), test.ShouldNotEqual, 0)

internalState, err = vc.getInternalState()
test.That(t, err, test.ShouldBeNil)
test.That(t, internalState, test.ShouldNotBeNil)
test.That(t, len(internalState), test.ShouldBeGreaterThan, lastInternalStateSize)
lastInternalStateSize = len(internalState)

// third sensor reading populates the pointcloud map and the position
t.Log("sensor reading 3")
timestamp = timestamp.Add(time.Second * 2)
Expand All @@ -229,9 +256,10 @@ func TestCGoAPI(t *testing.T) {
test.That(t, position.Kmag, test.ShouldNotEqual, 0)
test.That(t, position.Real, test.ShouldNotEqual, 0)

// test getInternalState
_, err = vc.getInternalState()
test.That(t, err, test.ShouldResemble, errors.New("nil internal state"))
internalState, err = vc.getInternalState()
test.That(t, err, test.ShouldBeNil)
test.That(t, internalState, test.ShouldNotBeNil)
test.That(t, len(internalState), test.ShouldBeGreaterThan, lastInternalStateSize)

// test stop
err = vc.stop()
Expand Down

0 comments on commit d2c3b0c

Please sign in to comment.