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

test/from-bytes/nibbles.js   A

Complexity

Total Complexity 10
Complexity/F 1

Size

Lines of Code 52
Function Count 10

Duplication

Duplicated Lines 52
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 0
c 2
b 0
f 0
nc 1
dl 52
loc 52
rs 10
wmc 10
mnd 0
bc 10
fnc 10
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('Nibbles from bytes', function() {
5
    
6
    let byteData = require('../../index.js');
7
8
    it('should turn 1 nibble to a 4-bit uInt', function() {
9
        assert.deepEqual(byteData.fromBytes(
10
            [0], 4, {"base": 10, "signed": false}),
11
            [0]);
12
    });
13
    it('should turn 1 nibble to a 4-bit uInt', function() {
14
        assert.deepEqual(byteData.fromBytes(
15
            [15], 4, {"base": 10, "signed": false}),
16
            [15]);
17
    });
18
    it('should turn 1 nibble to a 4-bit int', function() {
19
        assert.deepEqual(byteData.fromBytes(
20
            [15], 4, {"base": 10, "signed": true}),
21
            [-1]);
22
    });
23
    it('should turn 2 nibbles to a 4-bit uInts', function() {
24
        assert.deepEqual(byteData.fromBytes(
25
            [0,1], 4, {"base": 10, "signed": false}),
26
            [0,1]);
27
    });
28
    it('should turn 1 nibble to a 4-bit uInt', function() {
29
        assert.deepEqual(byteData.fromBytes(
30
            ["1111"], 4, {"base": 2, "signed": false}),
31
            [15]);
32
    });
33
    it('should turn 1 nibble to a 4-bit int', function() {
34
        assert.deepEqual(byteData.fromBytes(
35
            ["1111"], 4, {"base": 2, "signed": true}),
36
            [-1]);
37
    });
38
    it('should turn 1 nibble to a 4-bit uInt', function() {
39
        assert.deepEqual(byteData.fromBytes(
40
            ["f"], 4, {"base": 16, "signed": false}),
41
            [15]);
42
    });
43
    it('should turn 1 nibble to a 4-bit int', function() {
44
        assert.deepEqual(byteData.fromBytes(
45
            ["f"], 4, {"base": 16, "signed": true}),
46
            [-1]);
47
    });
48
    it('should turn 1 nibble (with padding zeros) to a 4-bit int', function() {
49
        assert.deepEqual(byteData.fromBytes(
50
            ["0f"], 4, {"base": 16, "signed": true}),
51
            [-1]);
52
    });
53
});
54