Conditions | 1 |
Paths | 1 |
Total Lines | 138 |
Lines | 138 |
Ratio | 100 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | /*! |
||
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 |