Passed
Branch master (9a7ed1)
by Rafael S.
01:20
created

test/from-bytes/24-bit.js   A

Complexity

Total Complexity 8
Complexity/F 1

Size

Lines of Code 48
Function Count 8

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 0
loc 48
rs 10
wmc 8
mnd 0
bc 8
fnc 8
bpm 1
cpm 1
noi 0
1
2
var assert = require('assert');
3
4
describe('24-bit from bytes', function() {
5
    
6
    let byteData = require('../../index.js');
7
8
    it('should turn 6 bytes to 2 24-bit ints', function() {
9
        assert.deepEqual(byteData.fromBytes(
10
            [0,0,0,0,0,0], 24, {"base": 10, "signed": false}),
11
            [0,0]);
12
    });
13
    it('should turn 6 bytes bin to 2 24-bit ints (max range)', function() {
14
        assert.deepEqual(byteData.fromBytes(
15
            ["00000000","00000000","10000000","11111111","11111111","01111111"],
16
            24, {"base": 2, "signed": true}),
17
            [-8388608, 8388607]);
18
    });
19
    it('should turn 6 bytes bin to 2 24-bit uInts (max range)', function() {
20
        assert.deepEqual(byteData.fromBytes(
21
            ["00000000","00000000","00000000","11111111","11111111","11111111"],
22
            24, {"base": 2, "signed": false}),
23
            [0,16777215]);
24
    });
25
    it('should turn 7 bytes bin to 2 24-bit uInts (ignore the extra byte) (max range)', function() {
26
        assert.deepEqual(byteData.fromBytes(
27
            ["00000000","00000000","00000000","11111111","11111111","11111111","11111111"],
28
            24, {"base": 2, "signed": false}),
29
            [0,16777215]);
30
    });
31
    it('should turn 2 bytes bin to 0 24-bit uInts (not enough bytes)', function() {
32
        assert.deepEqual(byteData.fromBytes(
33
            ["11111111","11111111"], 
34
            24, {"base": 2, "signed": false}),
35
            []);
36
    });
37
    it('should turn 6 bytes hex to 2 24-bit ints (max range)', function() {
38
        assert.deepEqual(byteData.fromBytes(
39
            ["0","0","80", "ff","ff","7f"], 
40
            24, {"base": 16, "signed": true}),
41
            [-8388608, 8388607]);
42
    });
43
    it('should turn 6 bytes hex to 2 24-bit uInts (max range)', function() {
44
        assert.deepEqual(byteData.fromBytes(
45
            ["0","0","0","ff","ff","ff"],
46
            24, {"base": 16, "signed": false}),
47
            [0,16777215]);
48
    });
49
});
50