1
|
|
|
|
2
|
|
|
var assert = require('assert'); |
3
|
|
|
|
4
|
|
|
describe('nibbles to bytes', function() { |
5
|
|
|
|
6
|
|
|
let byteData = require('../../index.js'); |
7
|
|
|
|
8
|
|
|
// 4-bit / half byte byte signed |
9
|
|
|
it('should turn 2 4-bit signed int to 2 nibbles (0s)', function() { |
10
|
|
|
assert.deepEqual(byteData.toBytes([0, 0], 4, {"base": 10}), |
11
|
|
|
[0, 0]); |
12
|
|
|
}); |
13
|
|
|
it('should turn 2 4-bit signed int to 2 bytes (-8, 7)', function() { |
14
|
|
|
assert.deepEqual(byteData.toBytes([-8, 7], 4, {"base": 10}), |
15
|
|
|
[8, 7]); |
16
|
|
|
}); |
17
|
|
|
it('should turn 1 4-bit signed int to 1 nibble (-1)', function() { |
18
|
|
|
assert.deepEqual(byteData.toBytes([-1], 4, {"base": 10}), |
19
|
|
|
[15]); |
20
|
|
|
}); |
21
|
|
|
it('should turn 1 4-bit signed int to 1 nibble (-1, 5)', function() { |
22
|
|
|
assert.deepEqual(byteData.toBytes([-1, 5], 4, {"base": 10}), |
23
|
|
|
[15, 5]); |
24
|
|
|
}); |
25
|
|
|
it('should turn 1 4-bit signed int to 1 nibble hex (-1)', function() { |
26
|
|
|
assert.deepEqual(byteData.toBytes([-1], 4, {"base": 16}), |
27
|
|
|
['f']); |
28
|
|
|
}); |
29
|
|
|
it('should turn 1 4-bit signed int to 1 nibble hex (-8)', function() { |
30
|
|
|
assert.deepEqual(byteData.toBytes([-8], 4, {"base": 16}), |
31
|
|
|
['8']); |
32
|
|
|
}); |
33
|
|
|
it('should turn 1 4-bit signed int to 1 nibble hex (7)', function() { |
34
|
|
|
assert.deepEqual(byteData.toBytes([7], 4, {"base": 16}), |
35
|
|
|
['7']); |
36
|
|
|
}); |
37
|
|
|
it('should turn 1 4-bit signed int to 1 nibble bin (6)', function() { |
38
|
|
|
assert.deepEqual(byteData.toBytes([6], 4, {"base": 2}), |
39
|
|
|
['0110']); |
40
|
|
|
}); |
41
|
|
|
}); |
42
|
|
|
|