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

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

Complexity

Total Complexity 33
Complexity/F 1

Size

Lines of Code 209
Function Count 33

Duplication

Duplicated Lines 209
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 209
loc 209
rs 9.3999
wmc 33
mnd 0
bc 33
fnc 33
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('48-bit from bytes', function() {
5
    
6
    let byteData = require('../../index.js');
7
8
    it('should turn 6 bytes (hex) to 1 unsigned 48-bit int  (max range)',
9
            function() {
10
        assert.deepEqual(byteData.fromBytes(
11
            [0,0,0,0,0,0], 48, {"base": 10, "signed": false}),
12
            [0]);
13
    });
14
    it('should turn 6 bytes (hex) to 1 unsigned 48-bit int  (max range)',
15
            function() {
16
        assert.deepEqual(byteData.fromBytes(
17
            ["ff","ff","ff","ff","ff","ff"], 48, {"base": 16, "signed": false}),
18
            [281474976710655]);
19
    });
20
    it('should turn 5 bytes (hex) to 0 unsigned 48-bit int (not enough bytes)',
21
            function() {
22
        assert.deepEqual(byteData.fromBytes(
23
            ["ff","ff","ff","ff","ff"], 48, {"base": 16, "signed": false}),
24
            []);
25
    });
26
    it('should turn 6 bytes (hex) to 1 signed 48-bit int  (max range)',
27
            function() {
28
        assert.deepEqual(byteData.fromBytes(
29
            ["ff","ff","ff","ff","ff","7f"], 48, {"base": 16, "signed": true}),
30
            [140737488355327]);
31
    });
32
    it('should turn 6 bytes (hex) to 1 signed 48-bit int  (min range)',
33
            function() {
34
        assert.deepEqual(byteData.fromBytes(
35
            ["00","00","00","00","00","80"], 48, {"base": 16, "signed": true}),
36
            [-140737488355328]);
37
    });
38
39
    // 40 bit tests should work the same with 48-bit
40
    it('should turn 6 bytes (hex) to 1 unsigned 48-bit int  (65535)',
41
            function() {
42
        assert.deepEqual(byteData.fromBytes(
43
            ["ff","ff","0","0","0","0"], 48, {"base": 16, "signed": false}),
44
            [65535]);
45
    });
46
    it('should turn 6 bytes (hex) to 1 unsigned 48-bit int  (32767)',
47
            function() {
48
        assert.deepEqual(byteData.fromBytes(
49
            ["ff","7f","0","0","0", "00"], 48, {"base": 16, "signed": false}),
50
            [32767]);
51
    });
52
    it('should turn 6 bytes (hex) to 1 unsigned 48-bit int  (549755813887)',
53
            function() {
54
        assert.deepEqual(byteData.fromBytes(
55
            ["ff","ff","ff","ff","7f", "00"], 48, {"base": 16, "signed": false}),
56
            [549755813887]);
57
    });
58
    it('should turn 6 bytes (bin) to 1 unsigned 48-bit int  (500000000080)',
59
            function() {
60
        assert.deepEqual(byteData.fromBytes(
61
            ["01010000", "10001000", "01010010",  "01101010",  "01110100", "00000000" ],
62
            48,
63
            {"base": 2, "signed": false}),
64
            [500000000080]);
65
    });
66
    it('should turn 6 bytes (dec) to 1 unsigned 48-bit int (max 40-bit  range)',
67
            function() {
68
        assert.deepEqual(byteData.fromBytes(
69
            ["ff","ff","ff","ff","ff","00"], 48, {"base": 16, "signed": false}),
70
            [1099511627775]);
71
    });
72
    it('should turn 6 bytes (bin) to 1 unsigned 48-bit int (max 40-bit range)',
73
            function() {
74
        assert.deepEqual(byteData.fromBytes(
75
            [255,255,255,255,255, 0], 48, {"base": 10, "signed": false}),
76
            [1099511627775]);
77
    });
78
    it('should turn 6 bytes (bin) to 1 unsigned 48-bit int (max 48-bit range)',
79
            function() {
80
        assert.deepEqual(byteData.fromBytes(
81
            [255,255,255,255,255, 255], 48, {"base": 10, "signed": false}),
82
            [281474976710655]);
83
    });
84
85
    it('should turn 6 bytes (hex) to 1 unsigned 48-bit int (149515627075)',
86
            function() {
87
        assert.deepEqual(byteData.fromBytes(
88
            ["43","6a", "d3","cf","22","00"], 48, {"base": 16, "signed": false}),
89
            [149515627075]);
90
    });
91
    it('should turn 6 bytes (bin) to 1 unsigned 48-bit int (149515627075)',
92
            function() {
93
        assert.deepEqual(byteData.fromBytes(
94
            ["01000011","01101010", "11010011","11001111","00100010","00000000"],
95
            48, {"base": 2, "signed": false}),
96
            [149515627075]);
97
    });
98
    it('should turn 6 bytes (bin) to 1 unsigned 48-bit int (149515627075) (padding)',
99
            function() {
100
        assert.deepEqual(byteData.fromBytes(
101
            ["1000011","1101010", "11010011","11001111","100010","00000000"], 
102
            48, {"base": 2, "signed": false}),
103
            [149515627075]);
104
    });
105
106
    // 48 bit signed
107
    it('should turn 6 bytes (hex) to 1 signed 48-bit int  (-32768)',
108
            function() {
109
        assert.deepEqual(byteData.fromBytes(
110
            ["0","80","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}),
111
            [-32768]);
112
    });
113
    it('should turn 6 bytes (hex) to 1 signed 48-bit int  (-65535)',
114
            function() {
115
        assert.deepEqual(byteData.fromBytes(
116
            ["1","0","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}),
117
            [-65535]);
118
    });
119
        
120
    it('should turn 6 bytes (hex) to 1 signed 48-bit int  (-1)',
121
            function() {
122
        assert.deepEqual(byteData.fromBytes(
123
            ["ff","ff","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}),
124
            [-1]);
125
    });
126
    it('should turn 6 bytes (hex) to 1 signed 48-bit int  (-2)',
127
            function() {
128
        assert.deepEqual(byteData.fromBytes(
129
            ["fe","ff","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}),
130
            [-2]);
131
    });
132
    it('should turn 5 bytes (hex) to 1 signed 48-bit int  (-3)',
133
            function() {
134
        assert.deepEqual(byteData.fromBytes(
135
            ["fd","ff","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}),
136
            [-3]);
137
    });
138
    it('should turn 6 bytes (hex) to 1 signed 48-bit int  (-10)',
139
            function() {
140
        assert.deepEqual(byteData.fromBytes(
141
            ["f6","ff","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}),
142
            [-10]);
143
    });
144
    it('should turn 6 bytes (hex) to 1 signed 48-bit int  (-100)',
145
            function() {
146
        assert.deepEqual(byteData.fromBytes(
147
            ["9c","ff","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}),
148
            [-100]);
149
    });
150
    it('should turn 6 bytes (hex) to 1 signed 48-bit int  (-1000)',
151
            function() {
152
        assert.deepEqual(byteData.fromBytes(
153
            ["18","fc","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}),
154
            [-1000]);
155
    });
156
    it('should turn 6 bytes (hex) to 1 signed 48-bit int  (-10000)',
157
            function() {
158
        assert.deepEqual(byteData.fromBytes(
159
            ["f0","d8","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}),
160
            [-10000]);
161
    });
162
    it('should turn 6 bytes (hex) to 1 signed 48-bit int  (-100000)',
163
            function() {
164
        assert.deepEqual(byteData.fromBytes(
165
            ["60", "79","fe","ff","ff","ff"], 48, {"base": 16, "signed": true}),
166
            [-100000]);
167
    });
168
    it('should turn 6 bytes (hex) to 1 signed 48-bit int  (-1000000)',
169
            function() {
170
        assert.deepEqual(byteData.fromBytes(
171
            ["c0", "bd","f0","ff","ff","ff"], 48, {"base": 16, "signed": true}),
172
            [-1000000]);
173
    });
174
    it('should turn 6 bytes (hex) to 1 signed 48-bit int  (-32768)',
175
            function() {
176
        assert.deepEqual(byteData.fromBytes(
177
            ["0","80","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}),
178
            [-32768]);
179
    });
180
    it('should turn 6 bytes (hex) to 1 signed 48-bit int  (-32768)',
181
            function() {
182
        assert.deepEqual(byteData.fromBytes(
183
            ["8","80","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}),
184
            [-32760]);
185
    });
186
    it('should turn 6 bytes (hex) to 1 signed 48-bit int  (-12345)',
187
            function() {
188
        assert.deepEqual(byteData.fromBytes(
189
            ["c7","cf","ff","ff","ff","ff"], 48, {"base": 16, "signed": true}),
190
            [-12345]);
191
    });
192
    it('should turn 6 bytes (hex) to 1 signed 48-bit int  (-12345)',
193
            function() {
194
        assert.deepEqual(byteData.fromBytes(
195
            ["00","00","00","00","80","ff"], 48, {"base": 16, "signed": true}),
196
            [-549755813888]);
197
    });
198
    it('should turn 6 bytes (bin) to 1 signed 48-bit int (65535)',
199
            function() {
200
        assert.deepEqual(byteData.fromBytes(
201
            ["ff","ff","0","0","0","0"], 48, {"base": 16, "signed": false}),
202
            [65535]);
203
    });
204
    it('should turn 6 bytes (hex) to 1 unsigned 48-bit int  (32767)',
205
            function() {
206
        assert.deepEqual(byteData.fromBytes(
207
            ["ff","7f","0","0","0","0"], 48, {"base": 16, "signed": false}),
208
            [32767]);
209
    });
210
});
211