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

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

Complexity

Conditions 1
Paths 1

Size

Total Lines 82

Duplication

Lines 82
Ratio 100 %

Importance

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

15 Functions

Rating   Name   Duplication   Size   Complexity  
A write-16bit.js ➔ ... ➔ it(ꞌblockAlign should be 2ꞌ) 3 3 1
A write-16bit.js ➔ ... ➔ it(ꞌsubChunk2Id should be ꞌdataꞌꞌ) 3 3 1
A write-16bit.js ➔ ... ➔ it(ꞌnumChannels should be 1ꞌ) 3 3 1
A write-16bit.js ➔ ... ➔ it(ꞌchunkId should be ꞌRIFFꞌꞌ) 3 3 1
A write-16bit.js ➔ ... ➔ it(ꞌsampleRate should be 8000ꞌ) 3 3 1
A write-16bit.js ➔ ... ➔ it(ꞌsubChunk1Size should be 16ꞌ) 3 3 1
A write-16bit.js ➔ ... ➔ it(ꞌsamples_ on the new file should have the same length as in the original fileꞌ) 3 3 1
A write-16bit.js ➔ ... ➔ it(ꞌbyteRate should be 16000ꞌ) 3 3 1
A write-16bit.js ➔ ... ➔ it(ꞌsubChunk2Size should be > 0ꞌ) 3 3 1
A write-16bit.js ➔ ... ➔ it(ꞌsamples.length should be > 0ꞌ) 3 3 1
A write-16bit.js ➔ ... ➔ it(ꞌbitsPerSample should be 16ꞌ) 3 3 1
A write-16bit.js ➔ ... ➔ it(ꞌsubChunk1Id should be ꞌfmt ꞌꞌ) 3 3 1
A write-16bit.js ➔ ... ➔ it(ꞌformat should be ꞌWAVEꞌꞌ) 3 3 1
A write-16bit.js ➔ ... ➔ it(ꞌsamples_ on the new file should be same as the original fileꞌ) 3 3 1
A write-16bit.js ➔ ... ➔ it(ꞌaudioFormat should be 1 (PCM)ꞌ) 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 16bit 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 + "16-bit-8kHz-noBext-mono.wav");
15
    let wav = new wavefile.WaveFile();
16
17
    wav.fromBytes(wBytes);
18
19
    let wav2 = new wavefile.WaveFile();
20
21
    let bytes3 = wav.toBytes();
22
23
    wav2.fromBytes(bytes3);
24
25
    let bytes4 = wav2.toBytes();
26
27
    fs.writeFileSync(path + "/out/16-bit-8kHz-noBext-mono.wav", bytes4);
28
29
    it("chunkId should be 'RIFF'",
30
            function() {
31
        assert.equal(wav2.chunkId, "RIFF");
32
    });
33
    it("subChunk1Id should be 'fmt '",
34
            function() {
35
        assert.equal(wav2.subChunk1Id, "fmt ");
36
    });
37
    it("format should be 'WAVE'",
38
            function() {
39
        assert.equal(wav2.format, "WAVE");
40
    });
41
    it("subChunk1Size should be 16",
42
            function() {
43
        assert.equal(wav2.subChunk1Size, 16);
44
    });
45
    it("audioFormat should be 1 (PCM)",
46
            function() {
47
        assert.equal(wav2.audioFormat, 1);
48
    });
49
    it("numChannels should be 1",
50
            function() {
51
        assert.equal(wav2.numChannels, 1);
52
    });
53
    it("sampleRate should be 8000",
54
            function() {
55
        assert.equal(wav2.sampleRate, 8000);
56
    });
57
    it("byteRate should be 16000",
58
            function() {
59
        assert.equal(wav2.byteRate, 16000);
60
    });
61
    it("blockAlign should be 2",
62
            function() {
63
        assert.equal(wav2.blockAlign, 2);
64
    });
65
    it("bitsPerSample should be 16",
66
            function() {
67
        assert.equal(wav2.bitsPerSample, 16);
68
    });
69
    it("subChunk2Id should be 'data'",
70
            function() {
71
        assert.equal(wav2.subChunk2Id, 'data');
72
    });
73
    it("subChunk2Size should be > 0",
74
            function() {
75
        assert.ok(wav2.subChunk2Size > 0);
76
    });
77
    it("samples.length should be > 0",
78
            function() {
79
        assert.ok(wav2.samples_.length > 0);
80
    });
81
    it("samples_ on the new file should have the same length as in the original file",
82
            function() {
83
        assert.equal(wav2.samples_.length, wav.samples_.length);
84
    });
85
    it("samples_ on the new file should be same as the original file",
86
            function() {
87
        assert.deepEqual(wav2.samples_, wav.samples_);
88
    });
89
});
90