-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add checksum recalculation to the utilities (#12)
- Loading branch information
Showing
4 changed files
with
140 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,11 @@ | |
"signalk" | ||
], | ||
"author": "Fabian Tollenaar <[email protected]>", | ||
"contributors": [ | ||
{ | ||
"name": "Marcel Verpaalen", | ||
"email": "[email protected]" | ||
}], | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/SignalK/nmea0183-utilities/issues" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
var chai = require("chai"); | ||
var expect = chai.expect; | ||
var utils = require('../index'); | ||
|
||
describe('CheckSum', function () { | ||
|
||
var sentence1 = '$GPBOD,045.,T,023.,M,DEST,START'; | ||
it('Checksum should be added and equal *01', function (done) { | ||
expect(utils.appendChecksum(sentence1)).to.equal('$GPBOD,045.,T,023.,M,DEST,START*01'); | ||
done(); | ||
}); | ||
|
||
var sentence2 = '!GPGGA,000000.00,5253.164,N,00539.655,E,0,00,99.9,,M,,M,,'; | ||
it('Checksum should be added and equal *6F', function (done) { | ||
expect(utils.appendChecksum(sentence2)).to.equal('!GPGGA,000000.00,5253.164,N,00539.655,E,0,00,99.9,,M,,M,,*6F'); | ||
done(); | ||
}); | ||
|
||
var sentence3 = '#GPGGA,000000.00,5253.164,N,00539.655,E,0,00,99.9,,M,,M,,'; | ||
it('Checksum should not be appended', function (done) { | ||
expect(utils.appendChecksum(sentence3)).to.equal('#GPGGA,000000.00,5253.164,N,00539.655,E,0,00,99.9,,M,,M,,'); | ||
done(); | ||
}); | ||
|
||
var sentence4 = '$GPGGA,000000.00,5253.164,N,00539.655,E,0,00,99.9,,M,,M,,*6A'; | ||
it('Checksum should not be recalculated to *6F', function (done) { | ||
expect(utils.appendChecksum(sentence4)).to.equal('$GPGGA,000000.00,5253.164,N,00539.655,E,0,00,99.9,,M,,M,,*6A'); | ||
done(); | ||
}); | ||
|
||
var sentence5 = '$GPBOD,045.,T,023.,M,DEST*,START*'; | ||
it('Checksum should not be appended', function (done) { | ||
expect(utils.appendChecksum(sentence5)).to.equal('$GPBOD,045.,T,023.,M,DEST*,START*'); | ||
done(); | ||
}); | ||
|
||
|
||
it('Checksum is valid', function (done) { | ||
expect(utils.valid('!GPGGA,000000.00,5253.164,N,00539.655,E,0,00,99.9,,M,,M,,*6F',true)).to.equal(true); | ||
done(); | ||
}); | ||
|
||
it('Checksum is invalid', function (done) { | ||
expect(utils.valid(sentence4,true)).to.equal(false); | ||
done(); | ||
}); | ||
|
||
it('Checksum is invalid but should not be checked', function (done) { | ||
expect(utils.valid(sentence4,false)).to.equal(true); | ||
done(); | ||
}); | ||
|
||
}); |