-
Notifications
You must be signed in to change notification settings - Fork 224
/
Copy pathtest.ts
94 lines (83 loc) · 2.29 KB
/
test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import ChordType from "./index";
import { interval } from "@tonaljs/core";
import DATA from "./data";
const INTERVALS = DATA.map((d) => d[0]).sort();
describe("@tonaljs/chord-type", () => {
test("names", () => {
// sorted
expect(ChordType.names().slice(0, 5)).toEqual([
"fifth",
"suspended fourth",
"suspended fourth seventh",
"augmented",
"major seventh flat sixth",
]);
});
test("symbols", () => {
// sorted
expect(ChordType.symbols().slice(0, 3)).toEqual([
"5",
"M7#5sus4",
"7#5sus4",
]);
});
test("all returns all chords", () => {
expect(ChordType.all()).toHaveLength(106);
});
test("get ", () => {
expect(ChordType.get("major")).toEqual({
empty: false,
setNum: 2192,
name: "major",
quality: "Major",
intervals: ["1P", "3M", "5P"],
aliases: ["M", "^", "", "maj"],
chroma: "100010010000",
normalized: "100001000100",
});
});
test("add a chord", () => {
ChordType.add(["1P", "5P"], ["q"]);
expect(ChordType.get("q")).toMatchObject({
chroma: "100000010000",
});
ChordType.add(["1P", "5P"], ["q"], "quinta");
expect(ChordType.get("quinta")).toEqual(ChordType.get("q"));
});
test("clear dictionary", () => {
ChordType.removeAll();
expect(ChordType.all()).toEqual([]);
expect(ChordType.keys()).toEqual([]);
});
});
describe("@tonal/chord-type data", () => {
test("no repeated intervals", () => {
for (let i = 1; i < INTERVALS.length; i++) {
expect(INTERVALS[i - 1]).not.toEqual(INTERVALS[i]);
}
});
test("all chords must have abreviatures", () => {
DATA.forEach((data) => {
const abrrvs = data[2].trim();
expect(abrrvs.length).toBeGreaterThan(0);
});
});
test("intervals should be in ascending order", () => {
DATA.forEach((data) => {
const [list] = data;
const intervals = list.split(" ").map((i) => interval(i).semitones || 0);
try {
for (let i = 1; i < intervals.length; i++) {
expect(intervals[i - 1]).toBeLessThan(intervals[i]);
}
} catch (e) {
// tslint:disable-next-line
console.error(
`Invalid chord: intervals should be in ascending order`,
data,
);
throw e;
}
});
});
});