Passed
Branch master (ea9505)
by Rafael S.
01:23
created

  A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 3
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 3
loc 3
rs 10
c 0
b 0
f 0
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