|
1
|
|
|
|
|
2
|
|
|
var assert = require('assert'); |
|
3
|
|
|
|
|
4
|
|
|
describe('8-bit from bytes', function() { |
|
5
|
|
|
|
|
6
|
|
|
let byteData = require('../../index.js'); |
|
7
|
|
|
|
|
8
|
|
|
it('should turn 1 byte to a 8-bit uInt', function() { |
|
9
|
|
|
assert.deepEqual(byteData.fromBytes( |
|
10
|
|
|
[0,0], 8), |
|
11
|
|
|
[0,0]); |
|
12
|
|
|
}); |
|
13
|
|
|
|
|
14
|
|
|
it('should turn 1 hex byte to a 8-bit uInt (max range)', function() { |
|
15
|
|
|
assert.deepEqual(byteData.fromBytes( |
|
16
|
|
|
["0","ff"], 8, {"base": 16}), |
|
17
|
|
|
[0, 255]); |
|
18
|
|
|
}); |
|
19
|
|
|
it('should turn 1 hex byte to a 8-bit int (max range)', function() { |
|
20
|
|
|
assert.deepEqual(byteData.fromBytes( |
|
21
|
|
|
["ff","7f"], 8, {"base": 16, "signed": true}), |
|
22
|
|
|
[-1, 127]); |
|
23
|
|
|
}); |
|
24
|
|
|
it('should turn 1 hex byte to a 8-bit int (max range)', function() { |
|
25
|
|
|
assert.deepEqual(byteData.fromBytes( |
|
26
|
|
|
["80","7f"], 8, {"base": 16, "signed": true}), |
|
27
|
|
|
[-128, 127]); |
|
28
|
|
|
}); |
|
29
|
|
|
it('should turn 1 bin byte to a 8-bit uInt (max range)', function() { |
|
30
|
|
|
assert.deepEqual(byteData.fromBytes( |
|
31
|
|
|
["00000000","11111111"], 8, {"base": 2, "signed": false}), |
|
32
|
|
|
[0, 255]); |
|
33
|
|
|
}); |
|
34
|
|
|
it('should turn 1 bin byte to a 8-bit int (max range)', function() { |
|
35
|
|
|
assert.deepEqual(byteData.fromBytes( |
|
36
|
|
|
["10000000","01111111"], 8, {"base": 2, "signed": true}), |
|
37
|
|
|
[-128, 127]); |
|
38
|
|
|
}); |
|
39
|
|
|
}); |
|
40
|
|
|
|