Conditions | 1 |
Paths | 1 |
Total Lines | 155 |
Lines | 155 |
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 24-bit wave files from scratch', function() { |
||
13 | |||
14 | let wavefile = require('../../index.js'); |
||
15 | let wav = new wavefile.WaveFile(); |
||
16 | wav.fromScratch(1, 48000, '24', [0, 1, -8388608, 8388607]); |
||
17 | |||
18 | let fs = require('fs'); |
||
19 | fs.writeFileSync("./test/files/out/24-bit-48kHz-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 48000', function() { |
||
46 | assert.equal(wav.sampleRate, 48000); |
||
47 | }); |
||
48 | |||
49 | it('byteRate should be 144000', function() { |
||
50 | assert.equal(wav.byteRate, 144000); |
||
51 | }); |
||
52 | |||
53 | it('blockAlign should be 3', function() { |
||
54 | assert.equal(wav.blockAlign, 3); |
||
55 | }); |
||
56 | |||
57 | it('bitsPerSample should be 24', function() { |
||
58 | assert.equal(wav.bitsPerSample, 24); |
||
59 | }); |
||
60 | |||
61 | it('subChunk2Id should be "data"', function() { |
||
62 | assert.equal(wav.subChunk2Id, "data"); |
||
63 | }); |
||
64 | |||
65 | it('subChunk2Size should be 12', function() { |
||
66 | assert.equal(wav.subChunk2Size, 12); |
||
67 | }); |
||
68 | |||
69 | it('samples_ should be the same as the args', function() { |
||
70 | assert.deepEqual(wav.samples_, [0, 1, -8388608, 8388607]); |
||
71 | }); |
||
72 | |||
73 | it('bitDepth_ should be "24"', function() { |
||
74 | assert.equal(wav.bitDepth_, "24"); |
||
75 | }); |
||
76 | |||
77 | /* |
||
78 | it('should return a 24-bit wave file', function() { |
||
79 | let wav = rw64.writeWavBytes(1, 48000, '24', |
||
80 | [0, 1, -8388608, 8388607]); |
||
81 | let wavRead = rw64.readWavBytes(wav); |
||
82 | |||
83 | assert.equal(wavRead.audioFormat, 1); |
||
84 | assert.equal(wavRead.numChannels, 1); |
||
85 | assert.equal(wavRead.blockAlign, 3); |
||
86 | assert.equal(wavRead.sampleRate, 48000); |
||
87 | assert.equal(wavRead.bitsPerSample, 24); |
||
88 | assert.equal(wavRead.subChunk2Size, 12); // 4 x 3 |
||
89 | assert.deepEqual(wavRead.samples, [0, 1, -8388608, 8388607]); |
||
90 | }); |
||
91 | |||
92 | it('should return a 24-bit wave file with a odd number of samples', |
||
93 | function() { |
||
94 | let wav = rw64.writeWavBytes(1, 48000, '24', |
||
95 | [0, 1, -8388608, 8388607, 4]); |
||
96 | let wavRead = rw64.readWavBytes(wav); |
||
97 | |||
98 | assert.equal(wavRead.audioFormat, 1); |
||
99 | assert.equal(wavRead.numChannels, 1); |
||
100 | assert.equal(wavRead.sampleRate, 48000); |
||
101 | assert.equal(wavRead.bitsPerSample, 24); |
||
102 | assert.equal(wavRead.blockAlign, 3); |
||
103 | assert.equal(wavRead.subChunk2Size, 15); // 5 x 3 |
||
104 | assert.deepEqual(wavRead.samples, [0, 1, -8388608, 8388607, 4]); |
||
105 | }); |
||
106 | |||
107 | it('should return a 24-bit wave file with 8 channels', function() { |
||
108 | let wav = rw64.writeWavBytes(8, 48000, '24', |
||
109 | [0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1]); |
||
110 | let read = rw64.readWavBytes(wav); |
||
111 | |||
112 | assert.equal(read.subChunk1Size, 16); |
||
113 | assert.equal(read.audioFormat, 1); |
||
114 | assert.equal(read.numChannels, 8); |
||
115 | assert.equal(read.sampleRate, 48000); |
||
116 | assert.equal(read.blockAlign, 24); |
||
117 | assert.equal(read.bitsPerSample, 24); |
||
118 | }); |
||
119 | |||
120 | it('should return a 24-bit wave file encoded as a base 64 string', |
||
121 | function() { |
||
122 | assert.ok(rw64.writeWavBase64(1, 48000, '24', |
||
123 | [0, 0.5, -0.5])); |
||
124 | }); |
||
125 | |||
126 | it('should return a 24-bit wave file encoded as a Data URI', |
||
127 | function() { |
||
128 | assert.ok(rw64.writeWavDataURI(1, 48000, '24', |
||
129 | [0, 0.5, -0.5])); |
||
130 | }); |
||
131 | |||
132 | it('should write a 24-bit stereo wav file', function() { |
||
133 | let channels = [ |
||
134 | [0,1,2], |
||
135 | [0,1,2] |
||
136 | ]; |
||
137 | let samples = rw64.interleave(channels); |
||
138 | let wav = rw64.writeWavBytes(2, 44100, '24', samples); |
||
139 | let read = rw64.readWavBytes(wav); |
||
140 | |||
141 | assert.equal(read.subChunk1Size, 16); |
||
142 | assert.equal(read.audioFormat, 1); |
||
143 | assert.equal(read.numChannels, 2); |
||
144 | assert.equal(read.sampleRate, 44100); |
||
145 | assert.equal(read.blockAlign, 6); |
||
146 | assert.equal(read.bitsPerSample, 24); |
||
147 | }); |
||
148 | |||
149 | it('should write a 24-bit stereo wav file', function() { |
||
150 | let channels = [ |
||
151 | [0,1,2], |
||
152 | [0,1,2] |
||
153 | ]; |
||
154 | let samples = rw64.interleave(channels); |
||
155 | let wav = rw64.writeWavBytes(2, 44100, '24', samples); |
||
156 | let read = rw64.readWavBytes(wav); |
||
157 | |||
158 | assert.equal(read.subChunk1Size, 16); |
||
159 | assert.equal(read.audioFormat, 1); |
||
160 | assert.equal(read.numChannels, 2); |
||
161 | assert.equal(read.sampleRate, 44100); |
||
162 | assert.equal(read.blockAlign, 6); |
||
163 | assert.equal(read.bitsPerSample, 24); |
||
164 | }); |
||
165 | */ |
||
166 | }); |
||
167 |