Pārlūkot izejas kodu

Linted tests for Common

Andrea Condoluci 9 gadi atpakaļ
vecāks
revīzija
5f90036bcd

+ 21 - 25
src/Common/DataObjects/pitch.ts

@@ -1,23 +1,3 @@
-import {CollectionUtil} from "../../Util/collectionUtil";
-
-export enum NoteEnum {
-    C = 0,
-    D = 2,
-    E = 4,
-    F = 5,
-    G = 7,
-    A = 9,
-    B = 11
-}
-
-export enum AccidentalEnum {
-    DOUBLEFLAT = -2,
-    FLAT = -1,
-    NONE = 0,
-    SHARP = 1,
-    DOUBLESHARP = 2
-}
-
 export class Pitch {
 
     constructor(fundamentalNote: NoteEnum, octave: number, accidental: AccidentalEnum) {
@@ -29,7 +9,7 @@ export class Pitch {
     }
 
     public static pitchEnumValues: NoteEnum[] = [
-        NoteEnum.C, NoteEnum.D, NoteEnum.E, NoteEnum.F, NoteEnum.G, NoteEnum.A, NoteEnum.B
+        NoteEnum.C, NoteEnum.D, NoteEnum.E, NoteEnum.F, NoteEnum.G, NoteEnum.A, NoteEnum.B,
     ];
 
     private static halftoneFactor: number = 12 / (Math.LN2 / Math.LN10);
@@ -67,7 +47,7 @@ export class Pitch {
             value -= limit;
             overflow++; // the octave change
         }
-        return {value: value, overflow: overflow};
+        return {overflow: overflow, value: value};
     }
 
     //public static calcFrequency(pitch: Pitch): number;
@@ -75,7 +55,6 @@ export class Pitch {
     //public static calcFrequency(fractionalKey: number): number;
 
     public static calcFrequency(obj: Pitch|number): number {
-        let frequency: number;
         let octaveSteps: number = 0;
         let halftoneSteps: number;
         if (obj instanceof Pitch) {
@@ -244,13 +223,13 @@ export class Pitch {
     }
 
     private getNextFundamentalNote(fundamental: NoteEnum): NoteEnum {
-        let i = Pitch.pitchEnumValues.indexOf(fundamental);
+        let i: number = Pitch.pitchEnumValues.indexOf(fundamental);
         i = (i + 1) % Pitch.pitchEnumValues.length;
         return Pitch.pitchEnumValues[i];
     }
 
     private getPreviousFundamentalNote(fundamental: NoteEnum): NoteEnum {
-        let i = Pitch.pitchEnumValues.indexOf(fundamental);
+        let i: number = Pitch.pitchEnumValues.indexOf(fundamental);
         if (i > 0) {
             return Pitch.pitchEnumValues[i - 1];
         } else {
@@ -259,3 +238,20 @@ export class Pitch {
     }
 }
 
+export enum NoteEnum {
+    C = 0,
+    D = 2,
+    E = 4,
+    F = 5,
+    G = 7,
+    A = 9,
+    B = 11
+}
+
+export enum AccidentalEnum {
+    DOUBLEFLAT = -2,
+    FLAT = -1,
+    NONE = 0,
+    SHARP = 1,
+    DOUBLESHARP = 2
+}

+ 19 - 19
src/Util/fft.ts

@@ -6,48 +6,48 @@ module FFT {
     public simple(output: Float64Array, input: Float64Array, type: string): void;
   }
 
-  export function toRealImag(timeData: Float64Array): any {
+  export function toRealImag(timeData: Float64Array): { amplitude: Float64Array; phase: Float64Array; } {
     let n: number = timeData.length;
-    let fft: any = new FFT.complex(n << 1, false);
-    let output: Float64Array = new Float64Array(n << 1);
-    let input: Float64Array = new Float64Array(n << 1);
+    let fft: any = new FFT.complex(2 * n, false);
+    let output: Float64Array = new Float64Array(2 * n);
+    let input: Float64Array = new Float64Array(2 * n);
     // copy timeData into the input array
     // FIXME: is this fix needed?
     // problem: complex transform, real timeData
-    for (let i = 0; i < n; i++) {
-      input[i << 1] = timeData[i];
-      input[i << 1 + 1] = 0;
+    for (let i: number = 0; i < n; i++) {
+      input[2 * i] = timeData[i];
+      input[2 * i + 1] = 0;
     }
     fft.simple(output, input, "complex");
     // Split output in real/imaginary parts
     let real: Float64Array = new Float64Array(n);
     let imag: Float64Array = new Float64Array(n);
     for (let i: number = 0; i < n; i ++) {
-      real[i] = output[i << 1];
-      imag[i] = output[i << 1 + 1];
+      real[i] = output[2 * i];
+      imag[i] = output[2 * i + 1];
     }
     return { real: real, imag: imag };
   }
 
-  export function toAmplPhas(timeData: Float64Array): any {
+  export function toAmplPhas(timeData: Float64Array): { amplitude: Float64Array; phase: Float64Array; } {
     let n: number = timeData.length;
-    let fft: any = new FFT.complex(n << 1, false);
-    let output: Float64Array = new Float64Array(n << 1);
-    let input: Float64Array = new Float64Array(n << 1);
+    let fft: any = new FFT.complex(2 * n, false);
+    let output: Float64Array = new Float64Array(2 * n);
+    let input: Float64Array = new Float64Array(2 * n);
     // copy timeData into the input array
     // FIXME: is this fix needed?
     // problem: complex transform, real timeData
-    for (let i = 0; i < n; i++) {
-      input[i << 1] = timeData[i];
-      input[i << 1 + 1] = 0;
+    for (let i: number = 0; i < n; i++) {
+      input[2 * i] = timeData[i];
+      input[2 * i + 1] = 0;
     }
     fft.simple(output, input, "complex");
     // Represent complex output in amplitude/phase form
     let ampl: Float64Array = new Float64Array(n);
     let phas: Float64Array = new Float64Array(n);
-    for (let i = 0, x: number, y: number; i < n; i += 1) {
-      x = output[i << 1];
-      y = output[i << 1 + 1];
+    for (let i: number = 0, x: number, y: number; i < n; i += 1) {
+      x = output[2 * i];
+      y = output[2 * i + 1];
       ampl[i] = Math.sqrt(x * x + y * y);
       phas[i] = Math.atan2(y, x);
     }

+ 3 - 3
test/Common/DataObjects/fraction_Test.ts

@@ -25,9 +25,9 @@ describe("Fraction Unit Tests:", () => {
         return Math.floor(Math.random() * 500) + 1;
       };
       it("lt attribute", (done: MochaDone) => {
-        for (let i = 0; i < 10; i += 1) {
-          let f1: Fraction = new Fraction(rand(), rand());
-          let f2: Fraction = new Fraction(rand(), rand());
+        for (let i: number = 0; i < 10; i += 1) {
+          f1 = new Fraction(rand(), rand());
+          f2 = new Fraction(rand(), rand());
           chai.expect(f1.lt(f2)).to.equal(f1.RealValue < f2.RealValue);
         }
         done();

+ 7 - 2
test/Common/FileIO/Xml.ts

@@ -1,6 +1,11 @@
 import { IXmlElement } from "../../../src/Common/FileIO/Xml.ts";
 
-let xml_test_data: string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><!DOCTYPE score-partwise PUBLIC \"-//Recordare//DTD MusicXML 2.0 Partwise//EN\" \"http://www.musicxml.org/dtds/partwise.dtd\"><score-partwise>  <identification>    <encoding>      <software>Example Software Name</software>      <encoding-date>2016-04-04</encoding-date>      </encoding>    </identification>   <credit page=\"1\"> <credit-words justify=\"center\" valign=\"top\">Example Credit Words</credit-words> </credit>  </score-partwise>";
+// Test XML simple document
+let xml_test_data: string = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\
+<!DOCTYPE score-partwise PUBLIC \"-//Recordare//DTD MusicXML 2.0 Partwise//EN\" \"http://www.musicxml.org/dtds/partwise.dtd\">\
+<score-partwise>  <identification>    <encoding>      <software>Example Software Name</software>      \
+<encoding-date>2016-04-04</encoding-date>      </encoding>    </identification>   <credit page=\"1\"> \
+<credit-words justify=\"center\" valign=\"top\">Example Credit Words</credit-words> </credit>  </score-partwise>";
 
 
 describe("XML Unit Tests", () => {
@@ -18,7 +23,7 @@ describe("XML Unit Tests", () => {
       .Element("identification")
       .Element("encoding")
       .Element("software").Value).to.equal("Example Software Name");
-      done();
+    done();
   });
   it("IXmlAttribute Tests", (done: MochaDone) => {
     // Test Attributes method