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

test/to-bytes/32-bit.js   A

Complexity

Total Complexity 12
Complexity/F 1

Size

Lines of Code 56
Function Count 12

Duplication

Duplicated Lines 56
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 56
loc 56
rs 10
wmc 12
mnd 0
bc 12
fnc 12
bpm 1
cpm 1
noi 0

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
2
var assert = require('assert');
3
4
describe('32-bit to bytes', function() {
5
    
6
    let byteData = require('../../index.js');
7
8
    // 32-bit / 4 bytes
9
    it('should turn 2 signed 32-bit floats to 8 bytes (0s)', function() {
10
        assert.deepEqual(byteData.toBytes([0, 0], 32, {"base": 10, "float": true}), 
11
            [0,0,0,0,0,0,0,0]);
12
    });
13
    it('should turn 1 signed 32-bit float to 4 bytes (pi)', function() {
14
        assert.deepEqual(byteData.toBytes([2.147483647], 32, {"base": 10, "float": true}), 
15
            [95,112,9,64]);
16
    });
17
    it('should turn 1 signed 32-bit float to 4 bytes', function() {
18
        assert.deepEqual(byteData.toBytes([2.147483647], 32, {"base": 16, "float": true}), 
19
            ["5f","70","09","40"]);
20
    });
21
    it('should turn 1 signed 32-bit float to 4 bytes (1)', function() {
22
        assert.deepEqual(byteData.toBytes([214748364.7], 32, {"base": 10, "float": true}), 
23
            [205,204,76,77]);
24
    });
25
26
    it('should turn 2 signed 32-bit int to 8 bytes (max range)', function() {
27
        assert.deepEqual(byteData.toBytes([-2147483648, 2147483647], 32, {"base": 10}),
28
            [0,0,0,128,255,255,255,127]);
29
    });
30
    it('should turn 2 unsigned 32-bit ints to 8 bytes (0s)', function() {
31
        assert.deepEqual(byteData.toBytes([0, 0], 32, {"base": 10}), 
32
            [0,0,0,0,0,0,0,0]);
33
    });
34
    it('should turn 2 unsigned 32-bit int to 8 bytes (max range)', function() {
35
        assert.deepEqual(byteData.toBytes([0, 4294967295], 32, {"base": 10}),
36
            [0,0,0,0,255,255,255,255]);
37
    });
38
39
    it('should turn 1 signed 32-bit int to 4 bytes bin (min range)', function() {
40
        assert.deepEqual(byteData.toBytes([-2147483648], 32, {"base": 2, "float": false}),
41
            ["00000000", "00000000","00000000","10000000",]);
42
    });
43
    it('should turn 1 signed 32-bit int to 4 bytes bin (max range)', function() {
44
        assert.deepEqual(byteData.toBytes([2147483647], 32, {"base": 2}),
45
            ["11111111","11111111","11111111","01111111"]);
46
    });
47
48
    it('should turn 1 signed 32-bit int to 4 bytes bin (max range)', function() {
49
        assert.deepEqual(byteData.toBytes([-2147483648], 32, {"base": 16}),
50
            ["00","00","00","80"]);
51
    });
52
    it('should turn 1 unsigned 32-bit int to 4 bytes hex (max range)', function() {
53
        assert.deepEqual(byteData.toBytes([4294967295], 32, {"base": 16}),
54
            ["ff","ff","ff","ff"]);
55
    });
56
57
});
58