Passed
Branch master (4064de)
by Rafael S.
02:04 queued 40s
created

test/from-scratch/32bitPCM-from-scratch.js   A

Complexity

Total Complexity 15
Complexity/F 1

Size

Lines of Code 140
Function Count 15

Duplication

Duplicated Lines 140
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 0
c 1
b 0
f 0
nc 1
dl 140
loc 140
rs 10
wmc 15
mnd 0
bc 15
fnc 15
bpm 1
cpm 1
noi 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B 32bitPCM-from-scratch.js ➔ describe(ꞌcreate 32-bit PCM wave files from scratchꞌ) 138 138 1

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
 * riffwave64
3
 * Read & write wave files with 8, 16, 24, 32 PCM, 32 IEEE & 64-bit data.
4
 * Copyright (c) 2017 Rafael da Silva Rocha.
5
 * https://github.com/rochars/riffwave64
6
 * https://tr2099.github.io
7
 *
8
 */
9
 
10 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...
11
12
describe('create 32-bit PCM wave files from scratch', function() {
13
    
14
    let wavefile = require('../../index.js');
15
    let wav = new wavefile.WaveFile();
16
    wav.fromScratch(1, 44100, '32', [0, -2147483648, 2147483647, 4]);
17
18
    let fs = require('fs');
19
    fs.writeFileSync("./test/files/out/32-bitPCM-441kHz-mono-fromScratch.wav", wav.toBytes());
20
21
    it('chunkId should be "RIFF"', function() {
22
        assert.equal(wav.chunkId, "RIFF");
23
    });
24
25
    it('format should be "WAVE"', function() {
26
        assert.equal(wav.format, "WAVE");
27
    });
28
29
    it('subChunk1Id should be "fmt "', function() {
30
        assert.equal(wav.subChunk1Id, "fmt ");
31
    });
32
33
    it('subChunk1Size should be 16', function() {
34
        assert.equal(wav.subChunk1Size, 16);
35
    });
36
37
    it('audioFormat should be 1', function() {
38
        assert.equal(wav.audioFormat, 1);
39
    });
40
41
    it('numChannels should be 1', function() {
42
        assert.equal(wav.numChannels, 1);
43
    });
44
45
    it('sampleRate should be 44100', function() {
46
        assert.equal(wav.sampleRate, 44100);
47
    });
48
49
    it('byteRate should be 176400', function() {
50
        assert.equal(wav.byteRate, 176400);
51
    });
52
53
    it('blockAlign should be 4', function() {
54
        assert.equal(wav.blockAlign, 4);
55
    });
56
57
    it('bitsPerSample should be 32', function() {
58
        assert.equal(wav.bitsPerSample, 32);
59
    });
60
61
    it('subChunk2Id should be "data"', function() {
62
        assert.equal(wav.subChunk2Id, "data");
63
    });
64
65
    it('subChunk2Size should be 16', function() {
66
        assert.equal(wav.subChunk2Size, 16);
67
    });
68
69
    it('samples_ should be the same as the args', function() {
70
        assert.deepEqual(wav.samples_, [0, -2147483648, 2147483647, 4]);
71
    });
72
73
    it('bitDepth_ should be "24"', function() {
74
        assert.equal(wav.bitDepth_, "32");
75
    });
76
77
    /*
78
    it('should return a 32-bit PCM wave file', function() {
79
        let wav = rw64.writeWavBytes(1, 44100, '32',
80
            [0, -2147483648, 2147483647, 4]);
81
        let wavRead = rw64.readWavBytes(wav);
82
        
83
        assert.equal(wavRead.audioFormat, 1);
84
        assert.equal(wavRead.numChannels, 1);
85
        assert.equal(wavRead.sampleRate, 44100);
86
        assert.equal(wavRead.bitsPerSample, 32);
87
        assert.equal(wavRead.blockAlign, 4);
88
        assert.deepEqual(wavRead.samples, [0, -2147483648, 2147483647, 4]);
89
    });
90
91
    it('should return a 32-bit PCM wave file with a odd number of samples',
92
            function() {
93
        let wav = rw64.writeWavBytes(1, 44100, '32',
94
            [0, -2147483648, 45, 0, 1]);
95
        let wavRead = rw64.readWavBytes(wav);
96
        
97
        assert.equal(wavRead.audioFormat, 1);
98
        assert.equal(wavRead.numChannels, 1);
99
        assert.equal(wavRead.sampleRate, 44100);
100
        assert.equal(wavRead.bitsPerSample, 32);
101
        assert.equal(wavRead.blockAlign, 4);
102
        assert.deepEqual(wavRead.samples, [0, -2147483648, 45, 0, 1]);
103
    });
104
105
    it('should return a 32-bit PCM wave file with 7 channels', function() {
106
        let wav = rw64.writeWavBytes(7, 48000, '32',
107
            [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1]);
108
        let read = rw64.readWavBytes(wav);
109
        
110
        assert.equal(read.subChunk1Size, 16);
111
        assert.equal(read.audioFormat, 1);
112
        assert.equal(read.numChannels, 7);
113
        assert.equal(read.sampleRate, 48000);
114
        assert.equal(read.blockAlign, 28);
115
        assert.equal(read.bitsPerSample, 32);
116
    });
117
118
    it('should write a 32-bit PCM stereo wav file', function() {
119
        let channels = [
120
            [0,1,2],
121
            [0,1,2]
122
        ];
123
        let samples = rw64.interleave(channels);
124
        let wav = rw64.writeWavBytes(2, 44100, '32', samples);
125
        let read = rw64.readWavBytes(wav);
126
        
127
        assert.equal(read.subChunk1Size, 16);
128
        assert.equal(read.audioFormat, 1);
129
        assert.equal(read.numChannels, 2);
130
        assert.equal(read.sampleRate, 44100);
131
        assert.equal(read.blockAlign, 8);
132
        assert.equal(read.bitsPerSample, 32);
133
    });
134
135
    it('should return a 32-bit PCM file with max possible sample value',
136
            function() {
137
        let wav = rw64.writeWavBytes(1, 16000, '32',
138
            [-2147483648, 2147483647, -1, 1, 0]);
139
        let wavRead = rw64.readWavBytes(wav);
140
        assert.equal(wavRead.audioFormat, 1);
141
        assert.equal(wavRead.numChannels, 1);
142
        assert.equal(wavRead.sampleRate, 16000);
143
        assert.equal(wavRead.blockAlign, 4);
144
        assert.equal(wavRead.bitsPerSample, 32);
145
        assert.deepEqual(wavRead.samples,
146
            [-2147483648, 2147483647, -1, 1, 0]);
147
    });
148
    */
149
});
150