Passed
Push — master ( 772c18...ea9505 )
by Rafael S.
02:00
created

scribe(ꞌread 4-bit file from disk and write to new fileꞌ)   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 80

Duplication

Lines 80
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
nc 1
nop 0
dl 80
loc 80
rs 8.8387
c 1
b 0
f 0

17 Functions

Rating   Name   Duplication   Size   Complexity  
A write-4bit.js ➔ ... ➔ it(ꞌbyteRate should be 4055ꞌ) 3 3 1
A write-4bit.js ➔ ... ➔ it(ꞌbitsPerSample should be 4ꞌ) 3 3 1
A write-4bit.js ➔ ... ➔ it(ꞌsubChunk1Size should be 20ꞌ) 3 3 1
A write-4bit.js ➔ ... ➔ it(ꞌaudioFormat should be 17 (IMA ADPCM)ꞌ) 3 3 1
A write-4bit.js ➔ ... ➔ it(ꞌblockAlign should be 256ꞌ) 3 3 1
A write-4bit.js ➔ ... ➔ it(ꞌnumChannels should be 1ꞌ) 3 3 1
A write-4bit.js ➔ ... ➔ it(ꞌsampleRate should be 8000ꞌ) 3 3 1
A write-4bit.js ➔ ... ➔ it(ꞌchunkId should be ꞌRIFFꞌꞌ) 3 3 1
A write-4bit.js ➔ ... ➔ it(ꞌsamples_ on the new file should be same as the original fileꞌ) 3 3 1
A write-4bit.js ➔ ... ➔ it(ꞌsamples.length should be > 0ꞌ) 3 3 1
A write-4bit.js ➔ ... ➔ it(ꞌfactChunkSize should be 4ꞌ) 3 3 1
A write-4bit.js ➔ ... ➔ it(ꞌsubChunk2Id should be ꞌdataꞌꞌ) 3 3 1
A write-4bit.js ➔ ... ➔ it(ꞌsamples_ on the new file should have the same length as in the original fileꞌ) 3 3 1
A write-4bit.js ➔ ... ➔ it(ꞌformat should be ꞌWAVEꞌꞌ) 3 3 1
A write-4bit.js ➔ ... ➔ it(ꞌsubChunk2Size should be > 0ꞌ) 3 3 1
A write-4bit.js ➔ ... ➔ it(ꞌsubChunk1Id should be ꞌfmt ꞌꞌ) 3 3 1
A write-4bit.js ➔ ... ➔ it(ꞌfactChunkId should be ꞌfactꞌꞌ) 3 3 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
/*!
2
 * Copyright (c) 2017 Rafael da Silva Rocha.
3
 * 
4
 */
5
6 View Code Duplication
var assert = require('assert');
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated in your project.
Loading history...
7
8
describe('read 4-bit file from disk and write to new file', function() {
9
    
10
    let fs = require("fs");
11
    let wavefile = require("../index.js");
12
    let path = "test/files/";
13
    
14
    let wBytes = fs.readFileSync(path + "4bit-imaadpcm-8kHz-noBext-mono.wav");
15
    let wav = new wavefile.WaveFile(wBytes);
16
    let wav2 = new wavefile.WaveFile(wav.toBytes());
17
    fs.writeFileSync(path + "/out/4bit-imaadpcm-8kHz-noBext-mono.wav", wav2.toBytes());
18
19
    it("chunkId should be 'RIFF'",
20
            function() {
21
        assert.equal(wav2.chunkId, "RIFF");
22
    });
23
    it("subChunk1Id should be 'fmt '",
24
            function() {
25
        assert.equal(wav2.subChunk1Id, "fmt ");
26
    });
27
    it("format should be 'WAVE'",
28
            function() {
29
        assert.equal(wav2.format, "WAVE");
30
    });
31
    it("subChunk1Size should be 20",
32
            function() {
33
        assert.equal(wav2.subChunk1Size, 20);
34
    });
35
    it("audioFormat should be 17 (IMA ADPCM)",
36
            function() {
37
        assert.equal(wav2.audioFormat, 17);
38
    });
39
    it("numChannels should be 1",
40
            function() {
41
        assert.equal(wav2.numChannels, 1);
42
    });
43
    it("sampleRate should be 8000",
44
            function() {
45
        assert.equal(wav2.sampleRate, 8000);
46
    });
47
    it("byteRate should be 4055",
48
            function() {
49
        assert.equal(wav2.byteRate, 4055);
50
    });
51
    it("blockAlign should be 256",
52
            function() {
53
        assert.equal(wav2.blockAlign, 256);
54
    });
55
    it("bitsPerSample should be 4",
56
            function() {
57
        assert.equal(wav2.bitsPerSample, 4);
58
    });
59
    it("factChunkId should be 'fact'",
60
            function() {
61
        assert.equal(wav2.factChunkId, 'fact');
62
    });
63
    it("factChunkSize should be 4",
64
            function() {
65
        assert.equal(wav2.factChunkSize, 4);
66
    });
67
    it("subChunk2Id should be 'data'",
68
            function() {
69
        assert.equal(wav2.subChunk2Id, 'data');
70
    });
71
    it("subChunk2Size should be > 0",
72
            function() {
73
        assert.ok(wav2.subChunk2Size > 0);
74
    });
75
    it("samples.length should be > 0",
76
            function() {
77
        assert.ok(wav2.samples_.length > 0);
78
    });
79
    it("samples_ on the new file should have the same length as in the original file",
80
            function() {
81
        assert.equal(wav2.samples_.length, wav.samples_.length);
82
    });
83
    it("samples_ on the new file should be same as the original file",
84
            function() {
85
        assert.deepEqual(wav2.samples_, wav.samples_);
86
    });
87
});
88