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

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

Complexity

Total Complexity 11
Complexity/F 1

Size

Lines of Code 51
Function Count 11

Duplication

Duplicated Lines 51
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 51
loc 51
rs 10
wmc 11
mnd 0
bc 11
fnc 11
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('8-bit to bytes', function() {
5
    
6
    let byteData = require('../../index.js');
7
8
    // 8-bit / 1 byte unsigned
9
    it('should turn 2 8-bit unsigned int to 2 bytes (0s)', function() {
10
        assert.deepEqual(byteData.toBytes([0, 0], 8, {"base": 10}),
11
            [0, 0]);
12
    });
13
    it('should turn 2 8-bit unsigned int to 2 bytes (min, max)', function() {
14
        assert.deepEqual(byteData.toBytes([0, 255], 8, {"base": 10}),
15
            [0, 255]);
16
    });
17
    it('should turn 1 8-bit unsigned int to 1 byte', function() {
18
        assert.deepEqual(byteData.toBytes([1], 8, {"base": 10}),
19
            [1]);
20
    });
21
22
    // 8-bit / 1 byte signed
23
    it('should turn 2 8-bit signed int to 2 bytes (0s)', function() {
24
        assert.deepEqual(byteData.toBytes([0, 0], 8, {"base": 10}),
25
            [0, 0]);
26
    });
27
    it('should turn 2 8-bit signed int to 2 bytes (-128, 127)', function() {
28
        assert.deepEqual(byteData.toBytes([-128, 127], 8, {"base": 10}),
29
            [128, 127]);
30
    });
31
    it('should turn 1 8-bit signed int to 1 byte (-1)', function() {
32
        assert.deepEqual(byteData.toBytes([-1], 8, {"base": 10}),
33
            [255]);
34
    });
35
    it('should turn 1 8-bit signed int to 1 byte (-1, 5)', function() {
36
        assert.deepEqual(byteData.toBytes([-1, 5], 8, {"base": 10}),
37
            [255, 5]);
38
    });
39
    it('should turn 1 8-bit signed int to 1 byte hex (-1)', function() {
40
        assert.deepEqual(byteData.toBytes([-1], 8, {"base": 16}),
41
            ['ff']);
42
    });
43
    it('should turn 1 8-bit signed int to 1 byte hex (-1)', function() {
44
        assert.deepEqual(byteData.toBytes([127], 8, {"base": 16}),
45
            ['7f']);
46
    });
47
    it('should turn 1 8-bit signed int to 1 byte hex (-1)', function() {
48
        assert.deepEqual(byteData.toBytes([-128], 8, {"base": 16}),
49
            ['80']);
50
    });
51
52
});
53