Conditions | 1 |
Paths | 1 |
Total Lines | 82 |
Lines | 82 |
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 | /*! |
||
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 |