Skip to content

Commit

Permalink
tests: add tests (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbender9 authored Dec 22, 2023
1 parent a7faf17 commit d7060cc
Show file tree
Hide file tree
Showing 24 changed files with 948 additions and 67 deletions.
125 changes: 122 additions & 3 deletions conversions/ais.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ module.exports = (app, plugin) => {
return null
}

var vessel = _.get(app.signalk.root, delta.context)
var vessel = app.getPath(delta.context)
var mmsi = _.get(vessel, 'mmsi') || findDeltaValue(delta, 'mmsi');

if ( !mmsi ) {
Expand All @@ -82,7 +82,7 @@ module.exports = (app, plugin) => {
}
return res
} else if ( delta.context.startsWith('atons.') ) {
var vessel = _.get(app.signalk.root, delta.context)
var vessel = app.getPath(delta.context)
var mmsi = _.get(vessel, 'mmsi') || findDeltaValue(delta, 'mmsi');

if ( !mmsi ) {
Expand All @@ -91,7 +91,126 @@ module.exports = (app, plugin) => {

return [ generateAtoN(vessel, mmsi, delta) ]
}
}
},
tests: [{
input: [{
"context":"vessels.urn:mrn:imo:mmsi:367301250",
"updates":[{"values":[
{
"path":"navigation.position",
"value": {"longitude":-76.3947165,"latitude":39.1296167}
},
{"path":"navigation.courseOverGroundTrue","value":1.501},
{"path":"navigation.speedOverGround","value":0.05},
{"path":"navigation.headingTrue","value":5.6199},
{"path":"navigation.rateOfTurn","value":0},
{"path":"navigation.state","value":"motoring"},
{"path":"navigation.destination.commonName","value":"BALTIMORE"},
{"path":"sensors.ais.fromBow","value":9},
{"path": "design.draft", "value": { "maximum": 4.2 }},
{"path": "design.length","value": {"overall": 30}},
{"path": "design.aisShipType", "value": {"id": 52, "name": "Tug"}},
{"path": "design.beam","value": 7},
{"path":"","value":{"mmsi":"367301250"}},
{"path":"","value":{"name":"SOME BOAT"}}
]}
]}],
expected: [{
"prio": 2,
"pgn": 129038,
"dst": 255,
"fields": {
"Message ID": "Scheduled Class A position report",
"User ID": 367301250,
"Longitude": -76.3947165,
"Latitude": 39.1296167,
"Position Accuracy": "Low",
"RAIM": "not in use",
"Time Stamp": "0",
"COG": 1.501,
"SOG": 0.05,
"AIS Transceiver information": "Channel A VDL reception",
"Heading": 5.6199,
"Rate of Turn": 0,
"Nav Status": "Under way using engine"
}
},{
"prio": 2,
"pgn": 129794,
"dst": 255,
"fields": {
"Message ID": "Static and voyage related data",
"User ID": 367301250,
"Callsign": "",
"Name": "SOME BOAT",
"Type of ship": "Tug",
"Length": 30,
"Beam": 7,
"Position reference from Bow": 9,
"Draft": 4.2,
"Destination": "BALTIMORE",
"AIS version indicator": "ITU-R M.1371-1",
"DTE": "Available",
"Reserved1": 1,
"AIS Transceiver information": "Channel A VDL reception"
}
}]
},{
input: [{
"context": "atons.urn:mrn:imo:mmsi:993672085",
"updates": [
{
"values":[
{"path": "","value": {"name": "78A"}},
{
"path": "navigation.position",
"value": {
"longitude": -76.4313882,
"latitude": 38.5783333
}
},
{
"path": "atonType",
"value": {
"id": 14,
"name": "Beacon, Starboard Hand"
}
},
{
"path": "",
"value": {
"mmsi": "993672085"
}
},
{
"path": "sensors.ais.class",
"value": "ATON"
}
]
}
]}],
expected: [{
"prio": 2,
"pgn": 129041,
"dst": 255,
"fields": {
"Message ID": 0,
"Repeat Indicator": "Initial",
"User ID": 993672085,
"Longitude": -76.4313882,
"Latitude": 38.5783333,
"Position Accuracy": "Low",
"RAIM": "not in use",
"Time Stamp": "0",
"AtoN Type": "Fixed beacon: starboard hand",
"Off Position Indicator": "Yes",
"Virtual AtoN Flag": "Yes",
"Assigned Mode Flag": "Assigned mode",
"Spare": 1,
"AtoN Name": "78A"
}
}]
}]
}
}

Expand Down
22 changes: 21 additions & 1 deletion conversions/attitude.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ module.exports = (app, plugin) => {
Yaw: attitude.yaw,
Roll: attitude.roll
}]
}
},
tests: [
{
input: [ {
"yaw": 1.8843,
"pitch": 0.042,
"roll": 0.042
} ],
expected: [ {
"dst": 255,
"fields": {
"Pitch": 0.042,
"Roll": 0.042,
"SID": 87,
"Yaw": 1.8843,
},
"pgn": 127257,
"prio": 2
}]
}
]
}
}
41 changes: 39 additions & 2 deletions conversions/battery.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@ module.exports = (app, plugin) => {
}
},

testOptions: {
BATTERYv2: {
batteries: [
{
signalkId: 0,
instanceId: 1
}
]
}
},

conversions: (options) => {
if ( !_.get(options, 'BATTERYv2.batteries') ) {
return null
Expand Down Expand Up @@ -73,12 +84,38 @@ module.exports = (app, plugin) => {
"Instance": battery.instanceId,
'State of Charge': stateOfCharge,
'State of Health': stateOfHealth,
'Time Remaining': timeRemaining,
'Time Remaining': timeRemaining,
'Ripple Voltage': ripple
})
}
return res
}
},
tests: [{
input: [12.5, 23.1, 290.15, 0.93, 12340, 0.6, 12.0],
expected: [{
"prio": 2,
"pgn": 127508,
"dst": 255,
"fields": {
"Instance": 1,
"Voltage": 12.5,
"Current": 23.1,
"Temperature": 290.15
}
},{
"prio": 2,
"pgn": 127506,
"dst": 255,
"fields": {
"Instance": 1,
"DC Type": "Battery",
"State of Charge": 93,
"State of Health": 60,
"Time Remaining": "03:26:00",
"Ripple Voltage": 12
}
}]
}]
}
})
}
Expand Down
15 changes: 14 additions & 1 deletion conversions/cogSOG.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ module.exports = (app, plugin) => {
} catch ( err ) {
console.error(err)
}
}
},
tests: [{
input: [ 2.1, 9 ],
expected: [{
"prio": 2,
"pgn": 129026,
"dst": 255,
"fields": {
"COG Reference": "True",
"COG": 2.1,
"SOG": 9
}
}]
}]
}
}
37 changes: 32 additions & 5 deletions conversions/depth.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ module.exports = (app, plugin) => {
optionKey: 'DEPTHv2',
keys: ["environment.depth.belowTransducer"],
callback: (belowTransducer) => {
var surfaceToTransducer = _.get(app.signalk.self,
'environment.depth.surfaceToTransducer.value')
var transducerToKeel = _.get(app.signalk.self,
'environment.depth.transducerToKeel.value')
var surfaceToTransducer = app.getSelfPath('environment.depth.surfaceToTransducer.value')
var transducerToKeel = app.getSelfPath('environment.depth.transducerToKeel.value')
var offset = _.isUndefined(surfaceToTransducer) ? (_.isUndefined(transducerToKeel) ? 0 : transducerToKeel) : surfaceToTransducer
try {
return [
Expand All @@ -23,7 +21,36 @@ module.exports = (app, plugin) => {
} catch ( err ) {
console.error(err)
}
}
},
tests: [{
input: [ 4.5 ],
skSelfData: {
'environment.depth.surfaceToTransducer.value': 1
},
expected: [{
"prio": 2,
"pgn": 128267,
"dst": 255,
"fields": {
"Depth": 4.5,
"Offset": 1
}
}]
},{
input: [ 2.1 ],
skSelfData: {
'environment.depth.transducerToKeel.value': 3
},
expected: [{
"prio": 2,
"pgn": 128267,
"dst": 255,
"fields": {
"Depth": 2.1,
"Offset": 3
}
}]
}]
}
}

Loading

0 comments on commit d7060cc

Please sign in to comment.