Parcourir la source

fix NoteType: add 32nd value, 2 NoteType tests for test suite (#740)

fix #740
sschmid il y a 5 ans
Parent
commit
9bf101efab

+ 5 - 2
src/MusicalScore/VoiceData/NoteType.ts

@@ -8,6 +8,7 @@ export enum NoteType {
     _256th,
     _128th,
     _64th,
+    _32nd,
     _16th,
     EIGTH,
     QUARTER,
@@ -20,13 +21,15 @@ export enum NoteType {
 
 export class NoteTypeHandler {
     // tslint:disable-next-line: variable-name
-    public static NoteTypeXmlValues: string[] = ["", "1024th", "512th", "256th", "128th", "64th", "32th", "16th",
+    public static NoteTypeXmlValues: string[] = ["", "1024th", "512th", "256th", "128th", "64th", "32nd", "16th",
         "eigth", "quarter", "half", "whole", "breve", "long", "maxima"];
     // alternative to array: use switch/case
 
 
     public static NoteTypeToString(noteType: NoteType): string {
-        return this.NoteTypeXmlValues[noteType]; // assumes that the enum values are ordered from 0 to x, like NoteTypeXmlValues array members
+        return this.NoteTypeXmlValues[noteType];
+        // assumes that the enum values are ordered from 0 to x, like NoteTypeXmlValues array members
+        // see NoteType_Test.ts
     }
 
     public static StringToNoteType(noteType: string): NoteType {

+ 19 - 0
test/MusicalScore/VoiceData/NoteType_Test.ts

@@ -0,0 +1,19 @@
+import { NoteType, NoteTypeHandler } from "../../../src/MusicalScore/VoiceData";
+
+/* tslint:disable:no-unused-expression */
+describe("NoteType", () => {
+    it("parses 32nd note correctly (sample value)", (done: MochaDone) => {
+        chai.expect(NoteTypeHandler.StringToNoteType("32nd")).to.equal(NoteType._32nd);
+        done();
+    });
+
+    it("parses all NoteType values from string correctly (in XML: <note><type>)", (done: MochaDone) => {
+        const inputValues: string[] = NoteTypeHandler.NoteTypeXmlValues;
+        for (let i: number = 0; i < inputValues.length; i++) {
+            chai.expect(NoteTypeHandler.StringToNoteType(inputValues[i])).to.equal(i);
+            // assumption: i corresponds to NoteType int value: 0 = UNDEFINED, 1 = _1024th, etc.
+            // we could also iterate over the NoteType enum values, but that's a bit ugly in typescript.
+        }
+        done();
+    });
+});